Allow API endpoints to be changed in env
This commit is contained in:
parent
fdd46fdd06
commit
a51cea24d4
2
.env
2
.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
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<script context="module" lang="ts">
|
||||
// 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'
|
||||
const endpointCompletions = import.meta.env.VITE_ENDPOINT_COMPLETIONS || '/v1/chat/completions'
|
||||
const endpointModels = import.meta.env.VITE_ENDPOINT_COMPLETIONS || '/v1/models'
|
||||
|
||||
export const getApiBase = ():string => apiBase
|
||||
export const getEndpointCompletions = ():string => endpointCompletions
|
||||
export const getEndpointModels = ():string => endpointModels
|
||||
</script>
|
|
@ -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
|
||||
|
|
|
@ -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}`,
|
||||
|
|
Loading…
Reference in New Issue