( missingParam: string, action: Action, previousConversation: ChatGPTMessage[], model: string, )
| 53 | } |
| 54 | |
| 55 | async function getMissingParam( |
| 56 | missingParam: string, |
| 57 | action: Action, |
| 58 | previousConversation: ChatGPTMessage[], |
| 59 | model: string, |
| 60 | ): Promise<string | null> { |
| 61 | console.log(`Parameter ${missingParam} is missing. Attempt to get it`); |
| 62 | const correctionPrompt = requestCorrectionPrompt(missingParam, action); |
| 63 | if (!correctionPrompt) return null; |
| 64 | const prompt = removeOldestFunctionCalls( |
| 65 | [...previousConversation].concat(correctionPrompt), |
| 66 | "4", |
| 67 | 200, |
| 68 | ); |
| 69 | console.log("Request correction prompt:\n", prompt); |
| 70 | let response = await getLLMResponse( |
| 71 | prompt, |
| 72 | { |
| 73 | frequency_penalty: 0, |
| 74 | max_tokens: 200, |
| 75 | }, |
| 76 | model, |
| 77 | ); |
| 78 | response = response.trim().replace(/\n/g, ""); |
| 79 | console.log("Response from gpt:\n", response); |
| 80 | try { |
| 81 | // Type casts to the most appropriate type, errors and returns a string if no casting possible |
| 82 | response = JSON.parse(response); |
| 83 | } catch {} |
| 84 | return response; |
| 85 | } |
| 86 | |
| 87 | function getRequiredParams(action: Action): string[] { |
| 88 | if (!action.parameters) return []; |
no test coverage detected