diff --git a/.env b/.env index c38b184..8b9c4bf 100644 --- a/.env +++ b/.env @@ -1,2 +1,4 @@ # Uncomment the following line to use the mocked API #VITE_API_BASE=http://localhost:5174 +#VITE_ENDPOINT_COMPLETIONS=/v1/chat/completions +#VITE_ENDPOINT_COMPLETIONS=/v1/models diff --git a/src/lib/ApiUtil.svelte b/src/lib/ApiUtil.svelte new file mode 100644 index 0000000..afd59d1 --- /dev/null +++ b/src/lib/ApiUtil.svelte @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/src/lib/Chat.svelte b/src/lib/Chat.svelte index 676f039..71e6e68 100644 --- a/src/lib/Chat.svelte +++ b/src/lib/Chat.svelte @@ -50,9 +50,7 @@ import PromptInput from './PromptInput.svelte' import { ChatCompletionResponse } from './ChatCompletionResponse.svelte' import { fetchEventSource } from '@microsoft/fetch-event-source' - - // This makes it possible to override the OpenAI API base URL in the .env file - const apiBase = import.meta.env.VITE_API_BASE || 'https://api.openai.com' + import { getApiBase, getEndpointCompletions } from './ApiUtil.svelte' export let params = { chatId: '' } const chatId: number = parseInt(params.chatId) @@ -394,7 +392,7 @@ updatingMessage = '' scrollToBottom() }) - fetchEventSource(apiBase + '/v1/chat/completions', { + fetchEventSource(getApiBase() + getEndpointCompletions(), { ...fetchOptions, onmessage (ev) { // Remove updating indicator @@ -423,7 +421,7 @@ scrollToBottom() }) } else { - const response = await fetch(apiBase + '/v1/chat/completions', fetchOptions) + const response = await fetch(getApiBase() + getEndpointCompletions(), fetchOptions) const json = await response.json() // Remove updating indicator diff --git a/src/lib/ChatSettingsModal.svelte b/src/lib/ChatSettingsModal.svelte index 802c0f2..a4b492b 100644 --- a/src/lib/ChatSettingsModal.svelte +++ b/src/lib/ChatSettingsModal.svelte @@ -35,12 +35,10 @@ import { replace } from 'svelte-spa-router' import { openModal } from 'svelte-modals' import PromptConfirm from './PromptConfirm.svelte' + import { getApiBase, getEndpointModels } from './ApiUtil.svelte' export let chatId:number export const show = () => { showSettings() } - - // This makes it possible to override the OpenAI API base URL in the .env file - const apiBase = import.meta.env.VITE_API_BASE || 'https://api.openai.com' let showSettingsModal = 0 let showProfileMenu:boolean = false @@ -179,7 +177,7 @@ // Load available models from OpenAI const allModels = (await ( - await fetch(apiBase + '/v1/models', { + await fetch(getApiBase() + getEndpointModels(), { method: 'GET', headers: { Authorization: `Bearer ${$apiKeyStorage}`,