From d2c8e44adb42a5b4d8756f2e94a594ef0bd3c556 Mon Sep 17 00:00:00 2001 From: Okysu Date: Mon, 5 Feb 2024 02:04:46 +0800 Subject: [PATCH] feat: support custom URL and model. --- .env.example | 2 ++ packages/ai/.env.example | 2 ++ packages/ai/src/config.ts | 6 ++++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index e570b8b..8ffac3f 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,3 @@ OPENAI_API_KEY= +MODEL_NAME="gpt-3.5-turbo-1106" +AI_SERVICE_URL="https://api.openai.com/v1" \ No newline at end of file diff --git a/packages/ai/.env.example b/packages/ai/.env.example index e570b8b..8ffac3f 100644 --- a/packages/ai/.env.example +++ b/packages/ai/.env.example @@ -1 +1,3 @@ OPENAI_API_KEY= +MODEL_NAME="gpt-3.5-turbo-1106" +AI_SERVICE_URL="https://api.openai.com/v1" \ No newline at end of file diff --git a/packages/ai/src/config.ts b/packages/ai/src/config.ts index a3606bd..48579f2 100644 --- a/packages/ai/src/config.ts +++ b/packages/ai/src/config.ts @@ -4,12 +4,14 @@ import OpenAI from 'openai' const deepseekApiUrl = 'https://api.deepseek.com/v1' +const aiServiceUrl = process.env.AI_SERVICE_URL || deepseekApiUrl + export const openai = new OpenAI({ - baseURL: deepseekApiUrl, + baseURL: aiServiceUrl, apiKey: process.env.OPENAI_API_KEY, // This is the default and can be omitted }) -export const baseModel = 'deepseek-chat' +export const baseModel = process.env.MODEL_NAME || 'deepseek-chat' export const baseChatCompletionCreateParams: Partial = { max_tokens: 300,