Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/321208008_ai-translation-assistant.json

1 line
12 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "321208008/ai-translation-assistant", "files": {"app/api/translate/route.ts": {"3e1ae8f79238786fc174aaee13f5abc0e476fc3a": {"t": 1785745570.983372, "n": 5134, "h": "2865686c8f093188", "c": "import { NextResponse } from 'next/server';\nimport OpenAI from 'openai';\nimport { sign } from '@/lib/server/tencent-sign';\n\nexport async function POST(request: Request) {\n try {\n const { text, targetLanguage, service } = await request.json();\n\n if (!text || !targetLanguage || !service) {\n return NextResponse.json(\n { error: '缺少必要参数' },\n { status: 400 }\n );\n }\n\n let result: string;\n\n switch (service) {\n case 'deepseek':\n result = await translateWithDeepSeek(text, targetLanguage);\n break;\n case 'qwen':\n result = await translateWithQwen(text, targetLanguage);\n break;\n case 'zhipu':\n result = await translateWithZhipu(text, targetLanguage);\n break;\n case '4o-mini':\n result = await translateWith4oMini(text, targetLanguage);\n break;\n case 'hunyuan':\n result = await translateWithHunyuan(text, targetLanguage);\n break;\n default:\n throw new Error('不支持的翻译服务');\n }\n\n return NextResponse.json({ text: result });\n } catch (error: any) {\n console.error('Translation error:', error);\n return NextResponse.json(\n { error: error.message || '翻译失败' },\n { status: 500 }\n );\n }\n}\n\nasync function translateWithDeepSeek(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_DEEPSEEK_API_KEY;\n if (!apiKey) {\n throw new Error('DeepSeek API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://api.deepseek.com/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'deepseek-chat',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWithQwen(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_QWEN_API_KEY;\n if (!apiKey) {\n throw new Error('Qwen API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'qwen-max',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWithZhipu(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_ZHIPU_API_KEY;\n if (!apiKey) {\n throw new Error('Zhipu API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://open.bigmodel.cn/api/paas/v4'\n });\n\n const response = await openai.chat.completions.create({\n model: 'glm-4',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWith4oMini(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_OPENAI_API_KEY;\n if (!apiKey) {\n throw new Error('OpenAI API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://api.openai.com/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'gpt-4o-mini',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWithHunyuan(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_TENCENT_API_KEY;\n if (!apiKey) {\n throw new Error('Tencent API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://api.hunyuan.cloud.tencent.com/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'hunyuan-turbo',\n messages: [\n {\n role: 'system',\n content: `你是一个专业的翻译助手,请直接翻译文本,不要添加任何解释。`\n },\n {\n role: 'user',\n content: `将以下文本翻译成${targetLanguage}:\\n\\n${text}`\n }\n ],\n temperature: 0.1,\n top_p: 0.7,\n // @ts-expect-error key is not yet public\n enable_enhancement: true\n });\n\n return response.choices[0].message.content || '';\n} "}, "8adb090f331995dee5709606bbfe1b47b116d040": {"t": 1785754353.3770957, "n": 5134, "h": "2865686c8f093188", "c": "import { NextResponse } from 'next/server';\nimport OpenAI from 'openai';\nimport { sign } from '@/lib/server/tencent-sign';\n\nexport async function POST(request: Request) {\n try {\n const { text, targetLanguage, service } = await request.json();\n\n if (!text || !targetLanguage || !service) {\n return NextResponse.json(\n { error: '缺少必要参数' },\n { status: 400 }\n );\n }\n\n let result: string;\n\n switch (service) {\n case 'deepseek':\n result = await translateWithDeepSeek(text, targetLanguage);\n break;\n case 'qwen':\n result = await translateWithQwen(text, targetLanguage);\n break;\n case 'zhipu':\n result = await translateWithZhipu(text, targetLanguage);\n break;\n case '4o-mini':\n result = await translateWith4oMini(text, targetLanguage);\n break;\n case 'hunyuan':\n result = await translateWithHunyuan(text, targetLanguage);\n break;\n default:\n throw new Error('不支持的翻译服务');\n }\n\n return NextResponse.json({ text: result });\n } catch (error: any) {\n console.error('Translation error:', error);\n return NextResponse.json(\n { error: error.message || '翻译失败' },\n { status: 500 }\n );\n }\n}\n\nasync function translateWithDeepSeek(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_DEEPSEEK_API_KEY;\n if (!apiKey) {\n throw new Error('DeepSeek API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://api.deepseek.com/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'deepseek-chat',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWithQwen(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_QWEN_API_KEY;\n if (!apiKey) {\n throw new Error('Qwen API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://dashscope.aliyuncs.com/compatible-mode/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'qwen-max',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWithZhipu(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_ZHIPU_API_KEY;\n if (!apiKey) {\n throw new Error('Zhipu API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://open.bigmodel.cn/api/paas/v4'\n });\n\n const response = await openai.chat.completions.create({\n model: 'glm-4',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWith4oMini(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_OPENAI_API_KEY;\n if (!apiKey) {\n throw new Error('OpenAI API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://api.openai.com/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'gpt-4o-mini',\n messages: [\n {\n role: 'system',\n content: `You are a professional translator. Translate the following text to ${targetLanguage}. Only return the translated text, no explanations.`\n },\n {\n role: 'user',\n content: text\n }\n ],\n temperature: 0.3,\n max_tokens: 2000\n });\n\n return response.choices[0].message.content || '';\n}\n\nasync function translateWithHunyuan(text: string, targetLanguage: string) {\n const apiKey = process.env.NEXT_PUBLIC_TENCENT_API_KEY;\n if (!apiKey) {\n throw new Error('Tencent API key not found');\n }\n\n const openai = new OpenAI({\n apiKey: apiKey,\n baseURL: 'https://api.hunyuan.cloud.tencent.com/v1'\n });\n\n const response = await openai.chat.completions.create({\n model: 'hunyuan-turbo',\n messages: [\n {\n role: 'system',\n content: `你是一个专业的翻译助手,请直接翻译文本,不要添加任何解释。`\n },\n {\n role: 'user',\n content: `将以下文本翻译成${targetLanguage}:\\n\\n${text}`\n }\n ],\n temperature: 0.1,\n top_p: 0.7,\n // @ts-expect-error key is not yet public\n enable_enhancement: true\n });\n\n return response.choices[0].message.content || '';\n} "}, "562a87c85475ee6caca2f26456b3bd8ab5bd0400": {"t": 1785754354.8863933, "n": 978, "h": "70f4863dca06c571", "c": "import { NextResponse } from 'next/server';\nimport { translateWithZhipu } from '@/lib/zhipu';\n\nexport async function POST(request: Request) {\n try {\n const { text, targetLanguage, service } = await request.json();\n\n if (!text) {\n return NextResponse.json(\n { success: false, message: '未提供文本' },\n { status: 400 }\n );\n }\n\n if (!targetLanguage) {\n return NextResponse.json(\n { success: false, message: '未提供目标语言' },\n { status: 400 }\n );\n }\n\n let result: string;\n\n switch (service) {\n case 'zhipu':\n result = await translateWithZhipu(text, targetLanguage);\n break;\n default:\n result = await translateWithZhipu(text, targetLanguage);\n }\n\n return NextResponse.json({ success: true, result });\n } catch (error: any) {\n console.error('翻译错误:', error);\n return NextResponse.json(\n { success: false, message: error.message || '翻译失败' },\n { status: 500 }\n );\n }\n} "}}}}