chore: download progress

This commit is contained in:
jialin
2025-02-27 18:03:28 +08:00
parent 8464e0ea3f
commit 295b4b3b72
14 changed files with 441 additions and 289 deletions
+4 -2
View File
@@ -1,6 +1,8 @@
import { request } from '@umijs/max';
export const OPENAI_COMPATIBLE = 'v1';
export const OPENAI_COMPATIBLE = 'v1-openai';
export const GPUSTACK_API = 'v1';
export const CHAT_API = `/${OPENAI_COMPATIBLE}/chat/completions`;
@@ -9,7 +11,7 @@ export const EDIT_IMAGE_API = `/${OPENAI_COMPATIBLE}/images/edits`;
export const EMBEDDING_API = `/${OPENAI_COMPATIBLE}/embeddings`;
export const OPENAI_MODELS = `/v1-openai/models`;
export const OPENAI_MODELS = `/${OPENAI_COMPATIBLE}/models`;
export const RERANKER_API = '/rerank';
@@ -5,7 +5,7 @@ import { useIntl } from '@umijs/max';
import { Button, Modal } from 'antd';
import _ from 'lodash';
import React, { useMemo, useState } from 'react';
import { OPENAI_COMPATIBLE } from '../apis';
import { GPUSTACK_API } from '../apis';
type ViewModalProps = {
systemMessage?: string;
@@ -47,7 +47,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const intl = useIntl();
const [lang, setLang] = useState(langMap.shell);
const BaseURL = `${window.location.origin}/${OPENAI_COMPATIBLE}`;
const BaseURL = `${window.location.origin}/${GPUSTACK_API}`;
const formatPyParams = (params: any) => {
return _.keys(params).reduce((acc: string, key: string) => {
@@ -70,7 +70,7 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
const printLog = logcommand ? `print(response.${logcommand})` : '';
if (lang === langMap.shell) {
const code = `curl ${window.location.origin}/${OPENAI_COMPATIBLE}/${api} \\\n-H "Content-Type: application/json" \\\n-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\\n-d '${JSON.stringify(
const code = `curl ${window.location.origin}/${GPUSTACK_API}/${api} \\\n-H "Content-Type: application/json" \\\n-H "Authorization: Bearer $\{YOUR_GPUSTACK_API_KEY}" \\\n-d '${JSON.stringify(
{
...parameters,
...payload
+16 -7
View File
@@ -1,8 +1,13 @@
import { OPENAI_COMPATIBLE } from '../apis';
import { GPUSTACK_API, OPENAI_COMPATIBLE } from '../apis';
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
export const speechToTextCode = ({ api, parameters }: Record<string, any>) => {
export const speechToTextCode = ({
api: url,
parameters
}: Record<string, any>) => {
const host = window.location.origin;
// replace url OPENAI_COMPATIBLE with GPUSTACK
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
const curlCode = `
@@ -19,7 +24,7 @@ ${formatCurlArgs(parameters, true)}`
from openai import OpenAI\n
audio_file = open("audio.mp3", "rb")
client = OpenAI(
base_url="${host}/${OPENAI_COMPATIBLE}",
base_url="${host}/${GPUSTACK_API}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -44,7 +49,7 @@ const OpenAI = require("openai");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
"baseURL": "${host}/${GPUSTACK_API}"
});
async function main() {
@@ -62,8 +67,12 @@ main();`.trim();
};
};
export const TextToSpeechCode = ({ api, parameters }: Record<string, any>) => {
export const TextToSpeechCode = ({
api: url,
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
const curlCode = `
@@ -78,7 +87,7 @@ from pathlib import Path
from openai import OpenAI\n
output_file_path = Path(__file__).parent / "output.mp3"
client = OpenAI(
base_url="${host}/${OPENAI_COMPATIBLE}",
base_url="${host}/${GPUSTACK_API}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -103,7 +112,7 @@ const ouptFile = path.resolve("./output.mp3");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
"baseURL": "${host}/${GPUSTACK_API}"
});
async function main() {
+5 -4
View File
@@ -1,11 +1,12 @@
import { OPENAI_COMPATIBLE } from '../apis';
import { GPUSTACK_API, OPENAI_COMPATIBLE } from '../apis';
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
export const generateEmbeddingCode = ({
api,
api: url,
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
const curlCode = `
@@ -18,7 +19,7 @@ ${formatCurlArgs(parameters, false)}`.trim();
const pythonCode = `
from openai import OpenAI\n
client = OpenAI(
base_url="${host}/${OPENAI_COMPATIBLE}",
base_url="${host}/${GPUSTACK_API}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -35,7 +36,7 @@ const OpenAI = require("openai");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
"baseURL": "${host}/${GPUSTACK_API}"
});
async function main() {
+8 -6
View File
@@ -1,14 +1,15 @@
import _ from 'lodash';
import { OPENAI_COMPATIBLE } from '../apis';
import { GPUSTACK_API, OPENAI_COMPATIBLE } from '../apis';
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
export const generateImageCode = ({
api,
api: url,
parameters,
isFormdata = false,
edit = false
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
let curlCode = `
@@ -45,7 +46,7 @@ print(response.json()['data'][0]['b64_json'])`.trim();
const nodeJsCode = `
const axios = require('axios');
const url = "${host}/${OPENAI_COMPATIBLE}/images/generations";
const url = "${host}/${GPUSTACK_API}/images/generations";
const headers = {
"Content-type": "application/json",
"Authorization": "Bearer $\{YOUR_GPUSTACK_API_KEY}"
@@ -64,12 +65,13 @@ axios.post(url, data, { headers }).then((response) => {
};
export const generateOpenaiImageCode = ({
api,
api: url,
parameters,
isFormdata = false,
edit = false
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
let curlCode = `
@@ -93,7 +95,7 @@ ${formatCurlArgs(_.omit(parameters, ['mask', 'image']), isFormdata)}`
const pythonCode = `
from openai import OpenAI\n
client = OpenAI(
base_url="${host}/${OPENAI_COMPATIBLE}",
base_url="${host}/${GPUSTACK_API}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -110,7 +112,7 @@ const OpenAI = require("openai");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
"baseURL": "${host}/${GPUSTACK_API}"
});
async function main() {