From a7ea16729805807cb5373810cf59c6067b5dd7a5 Mon Sep 17 00:00:00 2001 From: jialin Date: Tue, 25 Jun 2024 15:12:24 +0800 Subject: [PATCH] chore: completion api change --- config/proxy.ts | 2 +- pnpm-lock.yaml | 32 ++++++++++++++++--- src/config/hotkeys.ts | 13 ++++++++ src/pages/playground/apis/index.ts | 10 ++++-- .../playground/components/params-settings.tsx | 14 +++----- src/request-config.ts | 2 +- 6 files changed, 56 insertions(+), 17 deletions(-) create mode 100644 src/config/hotkeys.ts diff --git a/config/proxy.ts b/config/proxy.ts index 4d04c15f..4b4c43ea 100644 --- a/config/proxy.ts +++ b/config/proxy.ts @@ -1,4 +1,4 @@ -const proxyTableList = ['cli', 'v1', 'auth']; +const proxyTableList = ['cli', 'v1', 'auth', 'v1-openai']; // @ts-ingore export default function createProxyTable(target?: string) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aaeeb11d..a15ff623 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4249,7 +4249,7 @@ packages: dependencies: '@babel/core': 7.24.5 postcss: 7.0.39 - postcss-syntax: 0.36.2(postcss@8.4.38) + postcss-syntax: 0.36.2(postcss@7.0.39) transitivePeerDependencies: - supports-color dev: false @@ -4276,7 +4276,7 @@ packages: postcss-syntax: '>=0.36.2' dependencies: postcss: 7.0.39 - postcss-syntax: 0.36.2(postcss@8.4.38) + postcss-syntax: 0.36.2(postcss@7.0.39) remark: 13.0.0 unist-util-find-all-after: 3.0.2 transitivePeerDependencies: @@ -12393,7 +12393,7 @@ packages: dependencies: htmlparser2: 3.10.1 postcss: 7.0.39 - postcss-syntax: 0.36.2(postcss@8.4.38) + postcss-syntax: 0.36.2(postcss@7.0.39) dev: false /postcss-image-set-function@4.0.7(postcss@8.4.38): @@ -12683,6 +12683,30 @@ packages: lodash: 4.17.21 postcss: 8.4.38 + /postcss-syntax@0.36.2(postcss@7.0.39): + resolution: {integrity: sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==} + peerDependencies: + postcss: '>=5.0.0' + postcss-html: '*' + postcss-jsx: '*' + postcss-less: '*' + postcss-markdown: '*' + postcss-scss: '*' + peerDependenciesMeta: + postcss-html: + optional: true + postcss-jsx: + optional: true + postcss-less: + optional: true + postcss-markdown: + optional: true + postcss-scss: + optional: true + dependencies: + postcss: 7.0.39 + dev: false + /postcss-syntax@0.36.2(postcss@8.4.38): resolution: {integrity: sha512-nBRg/i7E3SOHWxF3PpF5WnJM/jQ1YpY9000OaVXlAQj6Zp/kIqJxEDWIZ67tAd7NLuk7zqN4yqe9nc0oNAOs1w==} peerDependencies: @@ -15759,7 +15783,7 @@ packages: postcss-sass: 0.4.4 postcss-scss: 2.1.1 postcss-selector-parser: 6.0.16 - postcss-syntax: 0.36.2(postcss@8.4.38) + postcss-syntax: 0.36.2(postcss@7.0.39) postcss-value-parser: 4.2.0 resolve-from: 5.0.0 slash: 3.0.0 diff --git a/src/config/hotkeys.ts b/src/config/hotkeys.ts new file mode 100644 index 00000000..6027ed38 --- /dev/null +++ b/src/config/hotkeys.ts @@ -0,0 +1,13 @@ +export default { + Create: ['ctrl+n', 'cmd+n'], + Save: ['ctrl+s', 'cmd+s'], + SaveAs: ['ctrl+shift+s', 'cmd+shift+s'], + Open: ['ctrl+o', 'cmd+o'], + Cancel: ['ctrl+w', 'cmd+w'], + Delete: ['delete'], + Copy: ['ctrl+c', 'cmd+c'], + Refresh: ['ctrl+r', 'cmd+r'], + Edit: ['ctrl+e', 'cmd+e'], + Search: ['ctrl+f', 'cmd+f'], + Reset: ['ctrl+shift+r', 'cmd+shift+r'] +}; diff --git a/src/pages/playground/apis/index.ts b/src/pages/playground/apis/index.ts index 66d1b4be..24ded23f 100644 --- a/src/pages/playground/apis/index.ts +++ b/src/pages/playground/apis/index.ts @@ -1,6 +1,8 @@ import { request } from '@umijs/max'; -export const CHAT_API = '/chat/completions'; +export const CHAT_API = '/v1-openai/chat/completions'; + +export const OPENAI_MODELS = '/v1-openai/models'; export async function execChatCompletions(params: any) { return request(`${CHAT_API}`, { @@ -9,8 +11,12 @@ export async function execChatCompletions(params: any) { }); } +export const queryModelsList = async () => { + return request(`${OPENAI_MODELS}`); +}; + export const fetchChatStream = async (params: any) => { - const response = await fetch(`/v1${CHAT_API}`, { + const response = await fetch(`${CHAT_API}`, { method: 'POST', body: JSON.stringify(params), headers: { diff --git a/src/pages/playground/components/params-settings.tsx b/src/pages/playground/components/params-settings.tsx index 0a344e5b..743350a1 100644 --- a/src/pages/playground/components/params-settings.tsx +++ b/src/pages/playground/components/params-settings.tsx @@ -2,11 +2,11 @@ import FieldWrapper from '@/components/seal-form/field-wrapper'; import SealInput from '@/components/seal-form/seal-input'; import SealSelect from '@/components/seal-form/seal-select'; import { INPUT_WIDTH } from '@/constants'; -import { queryModelsList } from '@/pages/llmodels/apis'; import { useIntl } from '@umijs/max'; import { Button, Form, InputNumber, Slider } from 'antd'; import _ from 'lodash'; import { useEffect, useState } from 'react'; +import { queryModelsList } from '../apis'; import CustomLabelStyles from '../style/custom-label.less'; type ParamsSettingsFormProps = { @@ -44,15 +44,11 @@ const ParamsSettings: React.FC = ({ useEffect(() => { const getModelList = async () => { try { - const params = { - page: 1, - perPage: 100 - }; - const res = await queryModelsList(params); - const list = _.map(res.items || [], (item: any) => { + const res = await queryModelsList(); + const list = _.map(res.data || [], (item: any) => { return { - value: item.name, - label: item.name + value: item.id, + label: item.id }; }); setModelList(list); diff --git a/src/request-config.ts b/src/request-config.ts index e14cee09..eadad7b9 100644 --- a/src/request-config.ts +++ b/src/request-config.ts @@ -1,7 +1,7 @@ import { RequestConfig } from '@umijs/max'; import { message } from 'antd'; -const NoBaseURLAPIs = ['/auth']; +const NoBaseURLAPIs = ['/auth', '/v1-openai']; export const requestConfig: RequestConfig = { errorConfig: {