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:
co-authored by
Claude Opus 4.6
parent
cef29d40bd
commit
4e83ce95cd
@@ -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,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,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);
|
||||||
|
|
||||||
|
|||||||
@@ -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 },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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 },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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 },
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
@@ -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 },
|
||||||
|
|||||||
Reference in New Issue
Block a user