use docker
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-11-03 21:03:28 +08:00
parent a528b78e43
commit 5cf100c111
28 changed files with 145 additions and 189 deletions

View File

@@ -1,67 +0,0 @@
import { callZhipuAPI } from "@/utils";
import { NextRequest, NextResponse } from "next/server";
async function getTextinfo(text: string) {
console.log(`get textinfo of ${text}`);
const messages = [
{
role: "user",
content: `
请推断以下文本的语言、locale生成宽式国际音标IPA以JSON格式返回
[${text}]
结果如:
{
"text": "你好。",
"lang": "mandarin",
"ipa": "[ni˨˩˦ xɑʊ˨˩˦]",
"locale": "zh-CN"
}
注意:
直接返回json文本
ipa一定要加[]
lang的值是小写字母的英文的语言名称
locale如果可能有多个选取最可能的一个其中使用符号"-"
`,
},
];
try {
const response = await callZhipuAPI(messages);
let to_parse = response.choices[0].message.content.trim() as string;
if (to_parse.startsWith("`"))
to_parse = to_parse.slice(7, to_parse.length - 3);
if (to_parse.length === 0) throw Error("ai啥也每说");
return JSON.parse(to_parse);
} catch (error) {
console.error(error);
return null;
}
}
export async function GET(request: NextRequest) {
try {
const searchParams = request.nextUrl.searchParams;
const text = searchParams.get("text");
if (!text) {
return NextResponse.json(
{ error: "查询参数错误", message: "text参数是必需的" },
{ status: 400 },
);
}
const textInfo = await getTextinfo(text);
if (!textInfo) {
return NextResponse.json(
{ error: "服务暂时不可用", message: "LLM API 请求失败" },
{ status: 503 },
);
}
return NextResponse.json(textInfo, { status: 200 });
} catch (error) {
console.error("API 错误:", error);
return NextResponse.json(
{ error: "服务器内部错误", message: "请稍后重试" },
{ status: 500 },
);
}
}

View File

@@ -1,5 +1,4 @@
import type { Metadata } from "next";
import { Geist, Geist_Mono } from "next/font/google";
import "./globals.css";
import type { Viewport } from "next";
import { NextIntlClientProvider } from "next-intl";
@@ -9,16 +8,6 @@ export const viewport: Viewport = {
initialScale: 1.0,
};
const geistSans = Geist({
variable: "--font-geist-sans",
subsets: ["latin"],
});
const geistMono = Geist_Mono({
variable: "--font-geist-mono",
subsets: ["latin"],
});
export const metadata: Metadata = {
title: "Learn Languages",
description: "A Website to Learn Languages",
@@ -32,7 +21,7 @@ export default async function RootLayout({
return (
<html lang="en">
<body
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
className={`antialiased`}
>
<NextIntlClientProvider>{children}</NextIntlClientProvider>
</body>

View File

@@ -43,7 +43,7 @@ export default getRequestConfig(async () => {
return locale;
})();
const messagesPath = join(process.cwd(), "messages", locale);
const messagesPath = join(process.cwd(), "public/messages", locale);
const messages = loadMessagesFromDir(messagesPath);
return {