load api base url from env;
This commit is contained in:
parent
bd719a9480
commit
5e5a7a7473
|
@ -23,3 +23,4 @@ dist-ssr
|
|||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
*.env
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
"@sveltejs/vite-plugin-svelte": "^2.0.2",
|
||||
"@tsconfig/svelte": "^3.0.0",
|
||||
"@types/marked": "^4.0.8",
|
||||
"@types/node": "^18.15.3",
|
||||
"bulma": "^0.9.4",
|
||||
"bulma-prefers-dark": "^0.1.0-beta.1",
|
||||
"copy-to-clipboard": "^3.3.3",
|
||||
|
@ -652,6 +653,12 @@
|
|||
"integrity": "sha512-HVNzMT5QlWCOdeuBsgXP8EZzKUf0+AXzN+sLmjvaB3ZlLqO+e4u0uXrdw9ub69wBKFs+c6/pA4r9sy6cCDvImw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "18.15.3",
|
||||
"resolved": "https://mirrors.cloud.tencent.com/npm/@types/node/-/node-18.15.3.tgz",
|
||||
"integrity": "sha512-p6ua9zBxz5otCmbpb5D3U4B5Nanw6Pk3PPyX05xnxbB/fRv71N7CPmORg7uAD5P70T0xmx1pzAx/FUfa5X+3cw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/pug": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.6.tgz",
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
"@sveltejs/vite-plugin-svelte": "^2.0.2",
|
||||
"@tsconfig/svelte": "^3.0.0",
|
||||
"@types/marked": "^4.0.8",
|
||||
"@types/node": "^18.15.3",
|
||||
"bulma": "^0.9.4",
|
||||
"bulma-prefers-dark": "^0.1.0-beta.1",
|
||||
"copy-to-clipboard": "^3.3.3",
|
||||
|
|
|
@ -144,7 +144,7 @@
|
|||
// Send API request
|
||||
/*
|
||||
// Not working yet: a way to get the response as a stream
|
||||
await fetchEventSource("https://api.openai.com/v1/chat/completions", {
|
||||
await fetchEventSource(import.meta.env.VITE_API_BASE + "/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization:
|
||||
|
@ -185,7 +185,7 @@
|
|||
}, {})
|
||||
}
|
||||
response = await (
|
||||
await fetch('https://api.openai.com/v1/chat/completions', {
|
||||
await fetch(import.meta.env.VITE_API_BASE + '/v1/chat/completions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${$apiKeyStorage}`,
|
||||
|
@ -275,7 +275,7 @@
|
|||
|
||||
// Load available models from OpenAI
|
||||
const allModels = (await (
|
||||
await fetch('https://api.openai.com/v1/models', {
|
||||
await fetch(import.meta.env.VITE_API_BASE + '/v1/models', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${$apiKeyStorage}`,
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue