I am using the OpenAI API and trying to translate Turkish data to Japanese using the GPT-3.5 model. However, the results I'm getting are not as expected. The provided JSON data contains Turkish language codes ("tr") that should be replaced with the correct Japanese language code.
I expect the output to have the correct Japanese language code ("ja") instead of "JA" and to show the proper translations for the provided Turkish data.
Can someone please help me identify the issue and suggest a solution to obtain the correct Turkish to Japanese translations using the OpenAI API and GPT-3.5 model? Thank you!
Here's the code snippet I'm using:
const { Configuration, OpenAIApi } = require("openai");
const { getLanguageString } = require('../../../helpers/auto_translate_helpers');
async function gptTranslateHelper(chunks, schema, target_language) {
const responseData = [];
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
try {
for (const chunk of chunks) {
const userMessage = {
"role": "user",
"content": `I am a restaurant owner and I manage my data in Turkish.My data : ${chunk.data} Please translate my data to ${getLanguageString(target_language)}. Replace all occurrences of "TR" with ${target_language}.
`,
};
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo-16k",
messages: [
{ "role": "system", "content": "You are a helpful assistant." },
userMessage,
],
functions: [{ name: "set_schema", parameters: schema }],
function_call: { name: "set_schema" },
});
const generatedText = completion.data.choices[0].message.content;
const parsedMenu = JSON.parse(generatedText);
responseData.push(...parsedMenu.data);
}
} catch (e) {
console.log(e);
}
console.log(responseData);
return responseData;
}
module.exports = { gptTranslateHelper };
Prompt:
I am a restaurant owner and I manage my data in Turkish.My data : [{"_id":"64adce3a897a661ba27dcc4b","name":{"tr":"Yemekler"}},{"_id":"64adce44897a661ba27dcc4c","name":{"tr":"İçecekler"}}] Please translate my data to Japanese. Replace all occurrences of "tr" with ja.
Incorrect Result:
[ { _id: '64adce3a897a661ba27dcc4b', name: { ja: 'Yemekler' } }, { _id: '64adce44897a661ba27dcc4c', name: { ja: 'İçecekler' } } ]