Switch LLM provider to DeepSeek v4 Pro

- Create shared openai client (src/lib/openai.ts) pointing to api.deepseek.com
- Replace all gpt-4o-mini model references with deepseek-v4-pro
- Refactor 3 API routes to use shared client instead of inline OpenAI() calls
- Add OPENAI_BASE_URL env var for endpoint configuration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jackyu66git
2026-05-20 12:45:25 +08:00
co-authored by Claude Opus 4.6
parent cef29d40bd
commit 4e83ce95cd
8 changed files with 15 additions and 12 deletions
+1 -3
View File
@@ -1,5 +1,5 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import OpenAI from "openai"; import { openai } from "@/lib/openai";
import { generateAllWeeklySummaries } from "@/lib/engines/summary-generator"; import { generateAllWeeklySummaries } from "@/lib/engines/summary-generator";
export async function POST(req: Request) { export async function POST(req: Request) {
@@ -18,8 +18,6 @@ export async function POST(req: Request) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
} }
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
try { try {
const results = await generateAllWeeklySummaries(openai); const results = await generateAllWeeklySummaries(openai);
const succeeded = results.filter((r) => r.success).length; const succeeded = results.filter((r) => r.success).length;
+1 -2
View File
@@ -1,6 +1,6 @@
import { auth } from "@clerk/nextjs/server"; import { auth } from "@clerk/nextjs/server";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import OpenAI from "openai"; import { openai } from "@/lib/openai";
import { prisma } from "@/lib/prisma"; import { prisma } from "@/lib/prisma";
import { processReflection } from "@/lib/engines/reflection-analyzer"; import { processReflection } from "@/lib/engines/reflection-analyzer";
import { computeStateUpdate } from "@/lib/engines/progress-tracker"; import { computeStateUpdate } from "@/lib/engines/progress-tracker";
@@ -49,7 +49,6 @@ export async function POST(req: Request) {
); );
} }
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
// Process reflection through LLM #2 // Process reflection through LLM #2
const reflection = await processReflection( const reflection = await processReflection(
+1 -3
View File
@@ -1,14 +1,12 @@
import { auth } from "@clerk/nextjs/server"; import { auth } from "@clerk/nextjs/server";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import OpenAI from "openai"; import { openai } from "@/lib/openai";
import { generateDailyTask } from "@/lib/engines/task-selector"; import { generateDailyTask } from "@/lib/engines/task-selector";
export async function POST() { export async function POST() {
const { userId } = await auth(); const { userId } = await auth();
if (!userId) return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); if (!userId) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
try { try {
const result = await generateDailyTask(userId, openai); const result = await generateDailyTask(userId, openai);
+1 -1
View File
@@ -98,7 +98,7 @@ export async function analyzeReflection(
try { try {
const response = await openai.chat.completions.create({ const response = await openai.chat.completions.create({
model: "gpt-4o-mini", model: "deepseek-v4-pro",
messages: [ messages: [
{ role: "system", content: REFLECTION_PROMPT }, { role: "system", content: REFLECTION_PROMPT },
{ {
+1 -1
View File
@@ -106,7 +106,7 @@ export async function generateWeeklySummary(
try { try {
const response = await openai.chat.completions.create({ const response = await openai.chat.completions.create({
model: "gpt-4o-mini", model: "deepseek-v4-pro",
messages: [ messages: [
{ role: "system", content: SUMMARY_PROMPT }, { role: "system", content: SUMMARY_PROMPT },
{ {
+1 -1
View File
@@ -123,7 +123,7 @@ export async function generateTask(
try { try {
const response = await openai.chat.completions.create({ const response = await openai.chat.completions.create({
model: "gpt-4o-mini", model: "deepseek-v4-pro",
messages: [ messages: [
{ role: "system", content: TASK_PROMPT }, { role: "system", content: TASK_PROMPT },
{ {
+8
View File
@@ -0,0 +1,8 @@
import OpenAI from "openai";
const baseURL = process.env.OPENAI_BASE_URL || "https://api.deepseek.com";
export const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL,
});
+1 -1
View File
@@ -43,7 +43,7 @@ export async function llmSafetyCheck(
): Promise<SafetyResult> { ): Promise<SafetyResult> {
try { try {
const response = await openai.chat.completions.create({ const response = await openai.chat.completions.create({
model: "gpt-4o-mini", model: "deepseek-v4-pro",
messages: [ messages: [
{ role: "system", content: SELF_REVIEW_PROMPT }, { role: "system", content: SELF_REVIEW_PROMPT },
{ role: "user", content: text }, { role: "user", content: text },