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

@ -82,7 +82,7 @@ export const OpenAISettings = () => {
<FormItem> <FormItem>
<FormLabel>{t`API Key`}</FormLabel> <FormLabel>{t`API Key`}</FormLabel>
<FormControl> <FormControl>
<Input type="password" placeholder="sk-..." {...field} /> <Input type="password" placeholder="sk-..." {...field} disabled={isEnabled} />
</FormControl> </FormControl>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>

View File

@ -17,8 +17,8 @@ type Mood = "casual" | "professional" | "confident" | "friendly";
export const changeTone = async (text: string, mood: Mood) => { export const changeTone = async (text: string, mood: Mood) => {
const prompt = PROMPT.replace("{mood}", mood).replace("{input}", text); const prompt = PROMPT.replace("{mood}", mood).replace("{input}", text);
const result = await openai().completions.create({ const result = await openai().chat.completions.create({
prompt, messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo", model: "gpt-3.5-turbo",
max_tokens: 1024, max_tokens: 1024,
temperature: 0.5, 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.`); 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) => { export const fixGrammar = async (text: string) => {
const prompt = PROMPT.replace("{input}", text); const prompt = PROMPT.replace("{input}", text);
const result = await openai().completions.create({ const result = await openai().chat.completions.create({
prompt, messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo", model: "gpt-3.5-turbo",
max_tokens: 1024, max_tokens: 1024,
temperature: 0, 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.`); 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) => { export const improveWriting = async (text: string) => {
const prompt = PROMPT.replace("{input}", text); const prompt = PROMPT.replace("{input}", text);
const result = await openai().completions.create({ const result = await openai().chat.completions.create({
prompt, messages: [{ role: "user", content: prompt }],
model: "gpt-3.5-turbo", model: "gpt-3.5-turbo",
max_tokens: 1024, max_tokens: 1024,
temperature: 0, 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.`); 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;
}; };