From 42788a2911468110e21ed75324128b8fc642ea33 Mon Sep 17 00:00:00 2001 From: Niek van der Maas Date: Tue, 21 Mar 2023 08:53:11 +0100 Subject: [PATCH] FIx default API base --- src/lib/Chat.svelte | 7 +++++-- vite.config.ts | 4 ---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/Chat.svelte b/src/lib/Chat.svelte index 3a1d2ce..9d90323 100644 --- a/src/lib/Chat.svelte +++ b/src/lib/Chat.svelte @@ -18,6 +18,9 @@ import { replace } from 'svelte-spa-router' import SvelteMarkdown from 'svelte-markdown' + // 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' + export let params = { chatId: '' } const chatId: number = parseInt(params.chatId) let updating: boolean = false @@ -145,7 +148,7 @@ // Send API request /* // Not working yet: a way to get the response as a stream - await fetchEventSource(import.meta.env.VITE_API_BASE + "/v1/chat/completions", { + await fetchEventSource(apiBase + "/v1/chat/completions", { method: "POST", headers: { Authorization: @@ -186,7 +189,7 @@ }, {}) } response = await ( - await fetch(import.meta.env.VITE_API_BASE + '/v1/chat/completions', { + await fetch(apiBase + '/v1/chat/completions', { method: 'POST', headers: { Authorization: `Bearer ${$apiKeyStorage}`, diff --git a/vite.config.ts b/vite.config.ts index 50d70f9..6a0cce6 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,10 +5,6 @@ import purgecss from '@fullhuman/postcss-purgecss' // https://vitejs.dev/config/ export default defineConfig(({ command, mode, ssrBuild }) => { - // Load env file based on `mode` in the current working directory. - const env = loadEnv(mode, process.cwd()) - // Set default api base url - env.VITE_API_BASE = 'https://api.openai.com' // Only run PurgeCSS in production builds if (command === 'build') { return {