chore: v1 to v2

This commit is contained in:
jialin
2025-11-20 17:31:15 +08:00
parent ea39a45f31
commit 551f04011a
12 changed files with 40 additions and 55 deletions
+1
View File
@@ -1,6 +1,7 @@
const proxyTableList = [
'cli',
'v1',
'v2',
'auth',
'v1-openai',
'version',
+2 -1
View File
@@ -7,4 +7,5 @@ export const DEFAULT_ENTER_PAGE = {
login: '/login'
};
export const GPUSTACK_API_BASE_URL = 'v1';
export const GPUSTACK_API_BASE_URL = 'v2';
export const OPENAI_COMPATIBLE = 'v1';
+1 -2
View File
@@ -4,7 +4,6 @@ import { throttle } from 'lodash';
import qs from 'query-string';
import { useEffect, useRef } from 'react';
const GPUSTACK_API = GPUSTACK_API_BASE_URL;
export interface HandlerOptions {
isComplete?: boolean | null;
percent?: number;
@@ -170,7 +169,7 @@ const useSetChunkFetch = () => {
axiosToken.current = new AbortController();
try {
const response = await fetch(
`${GPUSTACK_API}${url}?${qs.stringify({
`${GPUSTACK_API_BASE_URL}${url}?${qs.stringify({
...params,
watch: watch === undefined ? true : watch
})}`,
@@ -2,7 +2,7 @@ import AutoTooltip from '@/components/auto-tooltip';
import CopyButton from '@/components/copy-button';
import IconFont from '@/components/icon-font';
import ScrollerModal from '@/components/scroller-modal';
import { GPUSTACK_API_BASE_URL } from '@/config/settings';
import { OPENAI_COMPATIBLE } from '@/config/settings';
import {
AUDIO_SPEECH_TO_TEXT_API,
AUDIO_TEXT_TO_SPEECH_API,
@@ -23,8 +23,6 @@ import { modelCategoriesMap } from '../config';
import { ListItem } from '../config/types';
import useGenericProxy from '../hooks/use-generic-proxy';
const GPUSTACK_API = GPUSTACK_API_BASE_URL;
const API_MAP: Record<string, { api: string }> = {
[modelCategoriesMap.embedding]: {
api: EMBEDDING_API
@@ -112,7 +110,7 @@ const ApiAccessInfo = ({ open, data, onClose }: ApiAccessInfoProps) => {
const endPoint = useMemo(() => {
if (!data.generic_proxy) {
return `${window.location.origin}/${GPUSTACK_API}`;
return `${window.location.origin}/${OPENAI_COMPATIBLE}`;
}
return `${window.location.origin}${MODEL_PROXY}/<YOUR_API_PATH>`;
}, [data]);
+6 -3
View File
@@ -454,9 +454,12 @@ const DataForm: React.FC<DataFormProps> = forwardRef((props, ref) => {
enabled: false,
algorithm: '',
draft_model: null,
num_draft_tokens: 4,
ngram_min_match_length: 1,
ngram_max_match_length: 10
num_draft_tokens:
initialValues?.speculative_config?.num_draft_tokens || 4,
ngram_min_match_length:
initialValues?.speculative_config?.ngram_min_match_length || 1,
ngram_max_match_length:
initialValues?.speculative_config?.ngram_max_match_length || 10
},
...initialValues
}}
+2 -4
View File
@@ -1,10 +1,8 @@
import { GPUSTACK_API_BASE_URL } from '@/config/settings';
import { GPUSTACK_API_BASE_URL, OPENAI_COMPATIBLE } from '@/config/settings';
import { createFormData, errorHandler } from '@/utils/fetch-chunk-data';
import { request } from '@umijs/max';
export const OPENAI_COMPATIBLE = 'v1-openai';
export const GPUSTACK_API = GPUSTACK_API_BASE_URL;
export { GPUSTACK_API_BASE_URL, OPENAI_COMPATIBLE };
export const CHAT_API = `/${OPENAI_COMPATIBLE}/chat/completions`;
@@ -1,6 +1,6 @@
import AlertInfo from '@/components/alert-info';
import SealInputNumber from '@/components/seal-form/input-number';
import { GPUSTACK_API_BASE_URL } from '@/config/settings';
import { OPENAI_COMPATIBLE } from '@/config/settings';
import useOverlayScroller from '@/hooks/use-overlay-scroller';
import useRequestToken from '@/hooks/use-request-token';
import {
@@ -202,7 +202,7 @@ const GroundReranker: React.FC<MessageProps> = forwardRef((props, ref) => {
const viewCodeContent = useMemo(() => {
return generateRerankCode({
api: `/${GPUSTACK_API_BASE_URL}/rerank`,
api: `/${OPENAI_COMPATIBLE}/rerank`,
parameters: {
..._.pick(parameters, ['model', ..._.split(formFields, ',')]),
query: queryValue,
+7 -14
View File
@@ -1,5 +1,5 @@
import _ from 'lodash';
import { GPUSTACK_API, MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
export const generateSpeechToTextCurlCode = ({
@@ -9,9 +9,7 @@ export const generateSpeechToTextCurlCode = ({
}: Record<string, any>) => {
const host = window.location.origin;
// replace url OPENAI_COMPATIBLE with GPUSTACK
const api = modelProxy
? `${MODEL_PROXY}/\${YOUR_API_PATH}`
: url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
const api = modelProxy ? `${MODEL_PROXY}/\${YOUR_API_PATH}` : url;
// ========================= Curl =========================
const curlCode = `
@@ -32,8 +30,6 @@ export const speechToTextCode = ({
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 = generateSpeechToTextCurlCode({ api: url, parameters });
@@ -43,7 +39,7 @@ export const speechToTextCode = ({
from openai import OpenAI\n
audio_file = open("audio.mp3", "rb")
client = OpenAI(
base_url="${host}/${GPUSTACK_API}",
base_url="${host}/${OPENAI_COMPATIBLE}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -68,7 +64,7 @@ const OpenAI = require("openai");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${GPUSTACK_API}"
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
});
async function main() {
@@ -92,9 +88,7 @@ export const generateTextToSpeechCurlCode = ({
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = modelProxy
? `${MODEL_PROXY}/\${YOUR_API_PATH}`
: url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
const api = modelProxy ? `${MODEL_PROXY}/\${YOUR_API_PATH}` : url;
// ========================= Curl =========================
const curlCode = `
@@ -111,7 +105,6 @@ export const TextToSpeechCode = ({
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
const curlCode = generateTextToSpeechCurlCode({ api: url, parameters });
@@ -122,7 +115,7 @@ from pathlib import Path
from openai import OpenAI\n
output_file_path = Path(__file__).parent / "output.mp3"
client = OpenAI(
base_url="${host}/${GPUSTACK_API}",
base_url="${host}/${OPENAI_COMPATIBLE}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -147,7 +140,7 @@ const ouptFile = path.resolve("./output.mp3");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${GPUSTACK_API}"
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
});
async function main() {
+4 -7
View File
@@ -1,4 +1,4 @@
import { GPUSTACK_API, MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
export const generateEmbeddingCurlCode = ({
@@ -7,9 +7,7 @@ export const generateEmbeddingCurlCode = ({
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = modelProxy
? `${MODEL_PROXY}/\${YOUR_API_PATH}`
: url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
const api = modelProxy ? `${MODEL_PROXY}/\${YOUR_API_PATH}` : url;
// ========================= Curl =========================
const curlCode = `
@@ -26,7 +24,6 @@ export const generateEmbeddingCode = ({
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
const curlCode = generateEmbeddingCurlCode({ api: url, parameters });
@@ -35,7 +32,7 @@ export const generateEmbeddingCode = ({
const pythonCode = `
from openai import OpenAI\n
client = OpenAI(
base_url="${host}/${GPUSTACK_API}",
base_url="${host}/${OPENAI_COMPATIBLE}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -52,7 +49,7 @@ const OpenAI = require("openai");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${GPUSTACK_API}"
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
});
async function main() {
+7 -9
View File
@@ -1,5 +1,5 @@
import _ from 'lodash';
import { GPUSTACK_API, MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
export const generateImageCurlCode = ({
@@ -10,9 +10,7 @@ export const generateImageCurlCode = ({
edit = false
}: Record<string, any>) => {
const host = window.location.origin;
const api = modelProxy
? `${MODEL_PROXY}/\${YOUR_API_PATH}`
: url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
const api = modelProxy ? `${MODEL_PROXY}/\${YOUR_API_PATH}` : url;
// ========================= Curl =========================
let curlCode = `
@@ -43,7 +41,7 @@ export const generateImageCode = ({
edit = false
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
const api = url;
// ========================= Curl =========================
let curlCode = generateImageCurlCode({
@@ -69,7 +67,7 @@ print(response.json()['data'][0]['b64_json'])`.trim();
const nodeJsCode = `
const axios = require('axios');
const url = "${host}/${GPUSTACK_API}/images/generations";
const url = "${host}/${OPENAI_COMPATIBLE}/images/generations";
const headers = {
"Content-type": "application/json",
"Authorization": "Bearer $\{YOUR_GPUSTACK_API_KEY}"
@@ -94,7 +92,7 @@ export const generateOpenaiImageCode = ({
edit = false
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
const api = url;
// ========================= Curl =========================
let curlCode = `
@@ -118,7 +116,7 @@ ${formatCurlArgs(_.omit(parameters, ['mask', 'image']), isFormdata)}`
const pythonCode = `
from openai import OpenAI\n
client = OpenAI(
base_url="${host}/${GPUSTACK_API}",
base_url="${host}/${OPENAI_COMPATIBLE}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -135,7 +133,7 @@ const OpenAI = require("openai");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${GPUSTACK_API}"
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
});
async function main() {
+4 -7
View File
@@ -1,4 +1,4 @@
import { GPUSTACK_API, MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { MODEL_PROXY, OPENAI_COMPATIBLE } from '../apis';
import { fomatNodeJsParams, formatCurlArgs, formatPyParams } from './utils';
export const generateLLmCurlCode = ({
@@ -7,9 +7,7 @@ export const generateLLmCurlCode = ({
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = modelProxy
? `${MODEL_PROXY}/\${YOUR_API_PATH}`
: url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
const api = modelProxy ? `${MODEL_PROXY}/\${YOUR_API_PATH}` : url;
// ========================= Curl =========================
const curlCode = `
@@ -26,7 +24,6 @@ export const generateLLMCode = ({
parameters
}: Record<string, any>) => {
const host = window.location.origin;
const api = url.replace(OPENAI_COMPATIBLE, GPUSTACK_API);
// ========================= Curl =========================
const curlCode = generateLLmCurlCode({ api: url, parameters });
@@ -35,7 +32,7 @@ export const generateLLMCode = ({
const pythonCode = `
from openai import OpenAI\n
client = OpenAI(
base_url="${host}/${GPUSTACK_API}",
base_url="${host}/${OPENAI_COMPATIBLE}",
api_key="YOUR_GPUSTACK_API_KEY"
)
@@ -52,7 +49,7 @@ const OpenAI = require("openai");
const openai = new OpenAI({
"apiKey": "YOUR_GPUSTACK_API_KEY",
"baseURL": "${host}/${GPUSTACK_API}"
"baseURL": "${host}/${OPENAI_COMPATIBLE}"
});
async function main() {
+2 -2
View File
@@ -4,8 +4,8 @@ import { RequestConfig, history } from '@umijs/max';
import { message } from 'antd';
import { DEFAULT_ENTER_PAGE } from './config/settings';
// no base URL APIs
const NoBaseURLAPIs = ['/auth', '/v1-openai', '/version', '/proxy', '/update'];
// no GPUSTACK BASE API
const NoBaseURLAPIs = ['/auth', '/v1', '/version', '/proxy', '/update'];
export const requestConfig: RequestConfig = {
errorConfig: {