mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-05-13 01:46:08 +08:00
Allow configuring OpenAI base URL
This commit is contained in:
@@ -9,6 +9,8 @@ JWT_REFRESH_SECRET=changeme
|
||||
# OpenAI
|
||||
OPENAI_API_KEY=sk-your-openai-key
|
||||
OPENAI_PROJECT=
|
||||
OPENAI_BASE_URL=
|
||||
# Optional: specify a custom API endpoint, e.g. http://localhost:1234/v1
|
||||
LLM_MODEL=gpt-5-nano
|
||||
TTS_MODEL=tts-1
|
||||
VOICE_ID=alloy
|
||||
|
||||
@@ -16,6 +16,7 @@ export default defineNuxtConfig({
|
||||
runtimeConfig: {
|
||||
openaiKey: process.env.OPENAI_API_KEY,
|
||||
openaiProject: process.env.OPENAI_PROJECT,
|
||||
openaiBaseUrl: process.env.OPENAI_BASE_URL,
|
||||
llmModel: process.env.LLM_MODEL || 'gpt-5-nano',
|
||||
ttsModel: process.env.TTS_MODEL || 'tts-1',
|
||||
defaultVoiceId: process.env.VOICE_ID || 'alloy',
|
||||
|
||||
@@ -4,11 +4,14 @@ import fs from "node:fs";
|
||||
import { normalizeRadioPhrase } from "../../shared/utils/radioSpeech";
|
||||
import { getServerRuntimeConfig } from "./runtimeConfig";
|
||||
|
||||
const { openaiKey, openaiProject, llmModel, ttsModel } = getServerRuntimeConfig();
|
||||
const { openaiKey, openaiProject, openaiBaseUrl, llmModel, ttsModel } = getServerRuntimeConfig();
|
||||
const normalizeClientOptions: ConstructorParameters<typeof OpenAI>[0] = { apiKey: openaiKey };
|
||||
if (openaiProject) {
|
||||
normalizeClientOptions.project = openaiProject;
|
||||
}
|
||||
if (openaiBaseUrl) {
|
||||
normalizeClientOptions.baseURL = openaiBaseUrl;
|
||||
}
|
||||
|
||||
export const normalize = new OpenAI(normalizeClientOptions);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ const httpsAgent = new https.Agent({
|
||||
|
||||
function ensureOpenAI(): OpenAI {
|
||||
if (!openaiClient) {
|
||||
const {openaiKey, openaiProject, llmModel} = getServerRuntimeConfig()
|
||||
const {openaiKey, openaiProject, openaiBaseUrl, llmModel} = getServerRuntimeConfig()
|
||||
if (!openaiKey) {
|
||||
throw new Error('OPENAI_API_KEY is missing. Please set the key before using AI features.')
|
||||
}
|
||||
@@ -39,6 +39,9 @@ function ensureOpenAI(): OpenAI {
|
||||
if (openaiProject) {
|
||||
clientOptions.project = openaiProject
|
||||
}
|
||||
if (openaiBaseUrl) {
|
||||
clientOptions.baseURL = openaiBaseUrl
|
||||
}
|
||||
console.log("using connection opened client")
|
||||
openaiClient = new OpenAI(clientOptions)
|
||||
cachedModel = llmModel
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useRuntimeConfig } from '#imports'
|
||||
export interface ServerRuntimeConfig {
|
||||
openaiKey: string
|
||||
openaiProject?: string
|
||||
openaiBaseUrl?: string
|
||||
llmModel: string
|
||||
ttsModel: string
|
||||
voiceId: string
|
||||
@@ -62,9 +63,13 @@ export function getServerRuntimeConfig(): ServerRuntimeConfig {
|
||||
warnedMissingOpenAIKey = true
|
||||
}
|
||||
|
||||
const openaiProject = String(runtimeConfig.openaiProject || '').trim() || undefined
|
||||
const openaiBaseUrl = String(runtimeConfig.openaiBaseUrl || '').trim() || undefined
|
||||
|
||||
const config: ServerRuntimeConfig = {
|
||||
openaiKey,
|
||||
openaiProject: String(runtimeConfig.openaiProject || '').trim() || undefined,
|
||||
openaiProject,
|
||||
openaiBaseUrl,
|
||||
llmModel: String(runtimeConfig.llmModel || '').trim() || 'gpt-5-nano',
|
||||
ttsModel: String(runtimeConfig.ttsModel || '').trim() || 'tts-1',
|
||||
voiceId: String(runtimeConfig.defaultVoiceId || '').trim() || 'alloy',
|
||||
|
||||
Reference in New Issue
Block a user