allow overriding Core API URL

This commit is contained in:
josc146 2023-12-12 22:37:36 +08:00
parent 0c796c8cfc
commit b8f8837a8f
9 changed files with 27 additions and 7 deletions

View File

@ -317,5 +317,7 @@
"Please convert model to GGML format first": "モデルをGGML形式に変換してください", "Please convert model to GGML format first": "モデルをGGML形式に変換してください",
"Convert To GGML Format": "GGML形式に変換", "Convert To GGML Format": "GGML形式に変換",
"CPU (rwkv.cpp, Faster)": "CPU (rwkv.cpp, 高速)", "CPU (rwkv.cpp, Faster)": "CPU (rwkv.cpp, 高速)",
"Play With External Player": "外部プレーヤーで再生" "Play With External Player": "外部プレーヤーで再生",
"Core API URL": "コアAPI URL",
"Override core API URL(/chat/completions and /completions). If you don't know what this is, leave it blank.": "コアAPI URLを上書きします(/chat/completions と /completions)。何であるかわからない場合は空白のままにしてください。"
} }

View File

@ -317,5 +317,7 @@
"Please convert model to GGML format first": "请先将模型转换为GGML格式", "Please convert model to GGML format first": "请先将模型转换为GGML格式",
"Convert To GGML Format": "转换为GGML格式", "Convert To GGML Format": "转换为GGML格式",
"CPU (rwkv.cpp, Faster)": "CPU (rwkv.cpp, 更快)", "CPU (rwkv.cpp, Faster)": "CPU (rwkv.cpp, 更快)",
"Play With External Player": "使用外部播放器播放" "Play With External Player": "使用外部播放器播放",
"Core API URL": "核心 API URL",
"Override core API URL(/chat/completions and /completions). If you don't know what this is, leave it blank.": "覆盖核心的 API URL (/chat/completions 和 /completions)。如果你不知道这是什么,请留空"
} }

View File

@ -436,7 +436,7 @@ const ChatPanel: FC = observer(() => {
const chatSseController = new AbortController(); const chatSseController = new AbortController();
chatSseControllers[answerId] = chatSseController; chatSseControllers[answerId] = chatSseController;
fetchEventSource( // https://api.openai.com/v1/chat/completions || http://127.0.0.1:${port}/v1/chat/completions fetchEventSource( // https://api.openai.com/v1/chat/completions || http://127.0.0.1:${port}/v1/chat/completions
getServerRoot(port) + '/v1/chat/completions', getServerRoot(port, true) + '/v1/chat/completions',
{ {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -82,7 +82,7 @@ const CompletionPanel: FC = observer(() => {
let answer = ''; let answer = '';
completionSseController = new AbortController(); completionSseController = new AbortController();
fetchEventSource( // https://api.openai.com/v1/completions || http://127.0.0.1:${port}/v1/completions fetchEventSource( // https://api.openai.com/v1/completions || http://127.0.0.1:${port}/v1/completions
getServerRoot(port) + '/v1/completions', getServerRoot(port, true) + '/v1/completions',
{ {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -173,7 +173,7 @@ const CompositionPanel: FC = observer(() => {
let answer = ''; let answer = '';
compositionSseController = new AbortController(); compositionSseController = new AbortController();
fetchEventSource( // https://api.openai.com/v1/completions || http://127.0.0.1:${port}/v1/completions fetchEventSource( // https://api.openai.com/v1/completions || http://127.0.0.1:${port}/v1/completions
getServerRoot(port) + '/v1/completions', getServerRoot(port, true) + '/v1/completions',
{ {
method: 'POST', method: 'POST',
headers: { headers: {

View File

@ -186,6 +186,16 @@ export const AdvancedGeneralSettings: FC = observer(() => {
</Dropdown> </Dropdown>
</div> </div>
} /> } />
<Labeled label={t('Core API URL')}
desc={t('Override core API URL(/chat/completions and /completions). If you don\'t know what this is, leave it blank.')}
content={
<Input style={{ minWidth: 0 }} className="grow" value={commonStore.settings.coreApiUrl}
onChange={(e, data) => {
commonStore.setSettings({
coreApiUrl: data.value
});
}} />
} />
</div>; </div>;
}); });

View File

@ -175,7 +175,8 @@ class CommonStore {
apiUrl: '', apiUrl: '',
apiKey: '', apiKey: '',
apiChatModelName: 'rwkv', apiChatModelName: 'rwkv',
apiCompletionModelName: 'rwkv' apiCompletionModelName: 'rwkv',
coreApiUrl: ''
}; };
// about // about
about: AboutContent = manifest.about; about: AboutContent = manifest.about;

View File

@ -19,4 +19,5 @@ export type SettingsType = {
apiKey: string apiKey: string
apiChatModelName: string apiChatModelName: string
apiCompletionModelName: string apiCompletionModelName: string
coreApiUrl: string
} }

View File

@ -303,7 +303,11 @@ export function bytesToReadable(size: number) {
else return bytesToGb(size) + ' GB'; else return bytesToGb(size) + ' GB';
} }
export function getServerRoot(defaultLocalPort: number) { export function getServerRoot(defaultLocalPort: number, isCore: boolean = false) {
const coreCustomApiUrl = commonStore.settings.coreApiUrl.trim().replace(/\/$/, '');
if (isCore && coreCustomApiUrl)
return coreCustomApiUrl;
const defaultRoot = `http://127.0.0.1:${defaultLocalPort}`; const defaultRoot = `http://127.0.0.1:${defaultLocalPort}`;
if (commonStore.status.status !== ModelStatus.Offline) if (commonStore.status.status !== ModelStatus.Offline)
return defaultRoot; return defaultRoot;