fix: openai chat completions api upgrade, closes #1586

This commit is contained in:
Amruth Pillai
2023-11-26 15:32:56 +01:00
parent 9298a7473e
commit 062748eb5c
4 changed files with 10 additions and 10 deletions

View File

@@ -17,8 +17,8 @@ type Mood = "casual" | "professional" | "confident" | "friendly";
export const changeTone = async (text: string, mood: Mood) => {
const prompt = PROMPT.replace("{mood}", mood).replace("{input}", text);
const result = await openai().completions.create({
prompt,
const result = await openai().chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
max_tokens: 1024,
temperature: 0.5,
@@ -30,5 +30,5 @@ export const changeTone = async (text: string, mood: Mood) => {
throw new Error(t`OpenAI did not return any choices for your text.`);
}
return result.choices[0].text;
return result.choices[0].message.content ?? text;
};

View File

@@ -15,8 +15,8 @@ Revised Text: """`;
export const fixGrammar = async (text: string) => {
const prompt = PROMPT.replace("{input}", text);
const result = await openai().completions.create({
prompt,
const result = await openai().chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
max_tokens: 1024,
temperature: 0,
@@ -28,5 +28,5 @@ export const fixGrammar = async (text: string) => {
throw new Error(t`OpenAI did not return any choices for your text.`);
}
return result.choices[0].text;
return result.choices[0].message.content ?? text;
};

View File

@@ -15,8 +15,8 @@ Revised Text: """`;
export const improveWriting = async (text: string) => {
const prompt = PROMPT.replace("{input}", text);
const result = await openai().completions.create({
prompt,
const result = await openai().chat.completions.create({
messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
max_tokens: 1024,
temperature: 0,
@@ -28,5 +28,5 @@ export const improveWriting = async (text: string) => {
throw new Error(t`OpenAI did not return any choices for your text.`);
}
return result.choices[0].text;
return result.choices[0].message.content ?? text;
};