diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5bfbabd..2d960bb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,7 +34,9 @@ jobs: - name: Write .env file run: | cat > /tmp/.env << EOF - OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} + AI_API_KEY=${{ secrets.AI_API_KEY }} + AI_MODEL=${{ vars.AI_MODEL }} + AI_BASE_URL=${{ vars.AI_BASE_URL }} TENCENT_SECRET_ID=${{ secrets.TENCENT_SECRET_ID }} TENCENT_SECRET_KEY=${{ secrets.TENCENT_SECRET_KEY }} EOF diff --git a/backend/.claude/settings.local.json b/backend/.claude/settings.local.json index f8a396f..5209da3 100644 --- a/backend/.claude/settings.local.json +++ b/backend/.claude/settings.local.json @@ -16,7 +16,9 @@ "Bash(fi)", "Bash(done)", "Bash(npm run format:*)", - "Bash(timeout 8 npm run dev:*)" + "Bash(timeout 8 npm run dev:*)", + "Bash(git -C \"C:\\\\Users\\\\Shijia Huang\\\\WeChatProjects\\\\miniprogram-2\" diff HEAD -- backend/src/constants/config.ts)", + "Bash(git -C \"C:\\\\Users\\\\Shijia Huang\\\\WeChatProjects\\\\miniprogram-2\" diff HEAD -- backend/src/clients/openai.client.ts)" ] } } diff --git a/backend/.env.example b/backend/.env.example index b6fd2ca..cecd011 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -27,9 +27,10 @@ GAME_MOVE_TIMEOUT=30000 # Logging LOG_LEVEL=debug -# OpenAI Configuration -OPENAI_API_KEY=YOUR_OPENAI_API_KEY -OPENAI_MODEL=gpt-4o +# AI Configuration +AI_API_KEY=YOUR_AI_API_KEY +AI_MODEL=deepseek-chat +AI_BASE_URL=https://api.deepseek.com/v1 # LLM Worker Configuration LLM_WORKER_POLL_INTERVAL_MS=500 diff --git a/backend/src/clients/openai.client.ts b/backend/src/clients/openai.client.ts index c0cb98d..e16b22a 100644 --- a/backend/src/clients/openai.client.ts +++ b/backend/src/clients/openai.client.ts @@ -12,7 +12,7 @@ import crypto from 'crypto'; import OpenAI from 'openai'; -import { OPENAI_CONFIG } from '../constants/config'; +import { AI_CONFIG } from '../constants/config'; import { JUDGMENT_SYSTEM_PROMPT, buildJudgmentUserContent, @@ -30,13 +30,13 @@ const REQUEST_TIMEOUT_MS = 60_000; * Create a singleton OpenAI client instance */ function createClient(): OpenAI { - if (!OPENAI_CONFIG.API_KEY) { - throw new Error('OPENAI_API_KEY 未配置,无法调用 LLM'); + if (!AI_CONFIG.API_KEY) { + throw new Error('AI_API_KEY 未配置,无法调用 LLM'); } return new OpenAI({ - apiKey: OPENAI_CONFIG.API_KEY, - ...(OPENAI_CONFIG.BASE_URL ? { baseURL: OPENAI_CONFIG.BASE_URL } : {}), + apiKey: AI_CONFIG.API_KEY, + ...(AI_CONFIG.BASE_URL ? { baseURL: AI_CONFIG.BASE_URL } : {}), timeout: REQUEST_TIMEOUT_MS, }); } @@ -267,7 +267,7 @@ export async function createJudgmentVerdict( const response = await client.chat.completions.create( { - model: OPENAI_CONFIG.MODEL, + model: AI_CONFIG.MODEL, messages: [ { role: 'system', diff --git a/backend/src/constants/config.ts b/backend/src/constants/config.ts index 8b0cd4c..3f6113c 100644 --- a/backend/src/constants/config.ts +++ b/backend/src/constants/config.ts @@ -37,13 +37,13 @@ export const VERDICT_CONFIG = { MAX_RETRIES: 3, } as const; -export const OPENAI_CONFIG = { - /** OpenAI API key */ - API_KEY: process.env.OPENAI_API_KEY || '', - /** OpenAI model to use */ - MODEL: process.env.OPENAI_MODEL || 'gpt-4o', - /** Optional base URL for OpenAI-compatible APIs */ - BASE_URL: process.env.OPENAI_BASE_URL, +export const AI_CONFIG = { + /** AI API key */ + API_KEY: process.env.AI_API_KEY || '', + /** AI model to use */ + MODEL: process.env.AI_MODEL || '', + /** Optional base URL for AI-compatible APIs */ + BASE_URL: process.env.AI_BASE_URL || '', } as const; export const TENCENT_CONFIG = {