(prompt, attempt)
| 67 | } |
| 68 | |
| 69 | async callOpenAI(prompt, attempt) { |
| 70 | if (attempt > 3) { |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | if (attempt > 0) { |
| 75 | prompt = "YOU MUST ONLY RESPOND WITH VALID JSON OBJECTS\N" + prompt; |
| 76 | } |
| 77 | |
| 78 | const response = await openai.createChatCompletion({ |
| 79 | model: "gpt-3.5-turbo", |
| 80 | messages: [{ role: "user", content: prompt }], |
| 81 | }); |
| 82 | |
| 83 | console.log('OpenAI response', response.data.choices[0].message.content) |
| 84 | |
| 85 | const responseObject = this.cleanAndProcess(response.data.choices[0].message.content); |
| 86 | if (responseObject) { |
| 87 | return responseObject; |
| 88 | } |
| 89 | |
| 90 | return await this.callOpenAI(prompt, attempt + 1); |
| 91 | } |
| 92 | |
| 93 | cleanAndProcess(text) { |
| 94 | const extractedJson = extract(text)[0]; |
no test coverage detected