Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion backend/.claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
]
}
}
7 changes: 4 additions & 3 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions backend/src/clients/openai.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
});
}
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions backend/src/constants/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down