refactor: remove Anki import/export and simplify card system
- Remove Anki apkg import/export functionality - Remove OCR feature module - Remove note and note-type modules - Simplify card/deck modules (remove spaced repetition complexity) - Update translator and dictionary features - Clean up unused translations and update i18n files - Simplify prisma schema
This commit is contained in:
@@ -1,12 +1,5 @@
|
||||
"use server";
|
||||
|
||||
import OpenAI from "openai";
|
||||
|
||||
const openai = new OpenAI({
|
||||
apiKey: process.env.ZHIPU_API_KEY,
|
||||
baseURL: "https://open.bigmodel.cn/api/paas/v4",
|
||||
});
|
||||
|
||||
type Messages = Array<
|
||||
| { role: "system"; content: string }
|
||||
| { role: "user"; content: string }
|
||||
@@ -20,13 +13,29 @@ async function getAnswer(prompt: string | Messages): Promise<string> {
|
||||
? [{ role: "user", content: prompt }]
|
||||
: prompt;
|
||||
|
||||
const response = await openai.chat.completions.create({
|
||||
model: process.env.ZHIPU_MODEL_NAME || "glm-4",
|
||||
messages: messages as OpenAI.Chat.Completions.ChatCompletionMessageParam[],
|
||||
temperature: 0.2,
|
||||
const response = await fetch("https://open.bigmodel.cn/api/paas/v4/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${process.env.ZHIPU_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: process.env.ZHIPU_MODEL_NAME || "glm-4.6",
|
||||
messages,
|
||||
temperature: 0.2,
|
||||
thinking: {
|
||||
type: "disabled"
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
const content = response.choices[0]?.message?.content;
|
||||
if (!response.ok) {
|
||||
throw new Error(`AI API 请求失败: ${response.status}`);
|
||||
}
|
||||
|
||||
const data = await response.json() as { choices?: Array<{ message?: { content?: string } }> };
|
||||
const content = data.choices?.[0]?.message?.content;
|
||||
|
||||
if (!content) {
|
||||
throw new Error("AI API 返回空响应");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user