Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
Modify prompt words
Browse files Browse the repository at this point in the history
  • Loading branch information
SIPC committed Feb 9, 2024
1 parent d4e8b97 commit 334fc30
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 45 deletions.
34 changes: 0 additions & 34 deletions lib/translate/gemini.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/pages/api/lib/chatgpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class ChatGPT {
messages: [
{
role: "user",
content: `将"${text}"从${source}翻译为${target}(!!!直接返回翻译内容不要打引号)`,
content: `请将以下文本从${source}翻译为${target}:“${text}”(要求:输出的结果只能出现翻译结果,需要准确且清晰,不得出现翻译结果以外的内容,输出结果不可以带任何特殊的文本样式,'',""不得出现)`,
},
],
temperature: 0.7,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/lib/gemini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Gemini {
{
parts: [
{
text: `将"${text}"从${sourceLanguage}翻译为${targetLanguage}(!!!直接返回翻译内容不要打引号)`,
text: `请将以下文本从${sourceLanguage}翻译为${targetLanguage}:“${text}”(要求:输出的结果只能出现翻译结果,需要准确且清晰,不得出现翻译结果以外的内容,输出结果不可以带任何特殊的文本样式,'',""不得出现)`,
},
],
},
Expand Down
25 changes: 16 additions & 9 deletions src/pages/api/translate.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";
import { ChatGPT, ChatGPTInstance } from "./lib/chatgpt";
import { DeepLX, DeeplXInstance } from "@/pages/api/lib/deeplx";
import { Microsoft, MicrosoftInstance } from "@/pages/api/lib/microsoft";
import { Google, GoogleInstance } from "@/pages/api/lib/google";
import { Niutrans, NiutransInstance } from "@/pages/api/lib/niutrans";
import { autodetect } from "@/pages/api/lib/autodetect";
import { GeminiInstance } from "./lib/gemini";
import { DeepLX, DeeplXInstance } from "./lib/deeplx";
import { Microsoft, MicrosoftInstance } from "./lib/microsoft";
import { Google, GoogleInstance } from "./lib/google";
import { Niutrans, NiutransInstance } from "./lib/niutrans";
import { M2m100 , M2m100Instance } from "./lib/m2m100";
import { Gemini ,GeminiInstance } from "./lib/gemini";
import { autodetect } from "./lib/autodetect";


type TranslateResult = {
chatgpt: string;
Expand All @@ -15,6 +17,7 @@ type TranslateResult = {
google: string;
gemini: string;
niutrans: string;
m2m100: string;
};

type TranslateResponse = {
Expand Down Expand Up @@ -45,9 +48,9 @@ export default async function handler(
try {
if (sourceLanguage.length === 0 || sourceLanguage === "auto")
sourceLanguage = autodetect(text);

// code from sipc
const [chatgpt, gemini, deeplx, microsoft, google, niutrans] =
const [chatgpt, gemini, deeplx, microsoft, google, niutrans, m2m100] =
await Promise.all([
ChatGPTInstance.translate(text, targetLanguage, sourceLanguage).catch(
(e) => e.message,
Expand All @@ -67,6 +70,9 @@ export default async function handler(
NiutransInstance.translate(text, targetLanguage, sourceLanguage).catch(
(e) => e.message,
),
M2m100Instance.translate(text, targetLanguage, sourceLanguage).catch(
(e) => e.message,
),
]);

res.status(200).json({
Expand All @@ -78,7 +84,8 @@ export default async function handler(
deeplx,
microsoft,
google,
niutrans
niutrans,
m2m100
},
});
} catch (e) {
Expand Down

0 comments on commit 334fc30

Please sign in to comment.