yazinsai / srt-ai

Translate SRT files to any language, using AI magic ✨
https://translatesrt.com/
193 stars 50 forks source link

Custom route.ts pointing to local gpt4free: shifted linenumbers -> suddenly added AI response? :-) #15

Open macleod-be opened 8 months ago

macleod-be commented 8 months ago

My setup in route.ts ... // const response = await fetch("https://api.openai.com/v1/chat/completions", { const response = await fetch("http://localhost:1337/v1/chat/completions", { headers: { "Content-Type": "application/json", // Authorization: Bearer ${process.env.OPENAI_API_KEY}, }, ... Input File: 1 00:00:05,672 --> 00:00:07,674 Mr. Suero?

2 00:00:20,687 --> 00:00:22,272 Ah.

3 00:00:22,272 --> 00:00:25,275 Victor "Victory" Suero.

4 00:00:25,275 --> 00:00:26,777 Miles Sellars.

Output File: 1 00:00:05,672 --> 00:00:07,674 Certainly! Here is the translation to Dutch with the "

2 00:00:20,687 --> 00:00:22,272 " segment separator:

Meneer Suero?

3 00:00:22,272 --> 00:00:25,275 Ah.

4 00:00:25,275 --> 00:00:26,777 Victor "Victory" Suero.

Any Idea to fix this ?

macleod-be commented 8 months ago

I have a change request.

Can you append a marker ex: ... So 3 dots at the beginning of the ${text}. When receiving the answer you know when the comments end and the translation begins.

The question to ask: { role: "user", content: Translate this to ${language}. Including the 3 dots which marks the beginning of the translation. Interleave the "|" segment separator in the response.\n\n${text}, },

yazinsai commented 8 months ago

Certainly! Here is the translation to Dutch with the

That wasn't included in the examples I ran. Can you please confirm which model you're using? It's possible you can get away with just appending "ONLY include the translation in the response" to the prompt.

macleod-be commented 8 months ago

"ONLY include the translation in the response": I already tested that as question to the AI. They apparently want sometimes to say something :-).

Now I am not a full developper, I like to play around with someone code, like changing parameters. It looks like the way your code is working:

So you are not expecting a polite answer and clarification from the friendly AI :-)

macleod-be commented 8 months ago

I didn't changed anything else so I suppose you were looking for model: "gpt-3.5-turbo",