-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.js
24 lines (19 loc) · 862 Bytes
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import openai from "./openaiApi.js";
import config from "./config.js";
export async function fixJSONFormat(input) {
const fixingMessagePrompt =
`This text in the block below (surrounded by ===) is an invalid JSON response. Please clear any text that surrounds it or anything that may make it a broken JSON format. Please fix that and return only the JSON that's fixed. Don't return anything besides the JSON.
===
${input}
===`
const completion = await openai.createCompletion({
model: "text-davinci-003",
prompt: fixingMessagePrompt,
temperature: 0,
max_tokens: config.max_tokens
});
const fixed_message_text = completion.data.choices[0].text.trim();
console.log(`Fixed message text: ${fixed_message_text}`);
const fixed_json = JSON.parse(fixed_message_text);
return fixed_json;
}