(choice: OpenAI.ChatCompletion['choices'][0])
| 33 | } |
| 34 | |
| 35 | function extractOpenAIFunctions(choice: OpenAI.ChatCompletion['choices'][0]) { |
| 36 | const functionCalls: FunctionCall[] = []; |
| 37 | for (const toolCall of choice.message.tool_calls || []) { |
| 38 | // if our response contained a call to a function... |
| 39 | // TODO: update this to the new tools API from Openai |
| 40 | console.log('A function call was returned...'); |
| 41 | const name = toolCall.function.name; |
| 42 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment |
| 43 | let funcArguments: FunctionArguments = {}; |
| 44 | try { |
| 45 | // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment |
| 46 | funcArguments = JSON.parse(toolCall.function.arguments); |
| 47 | } catch (parseError) { |
| 48 | // in this case, we assume, that the first parameter was meant... |
| 49 | funcArguments = {}; |
| 50 | const toolProps = tools[name]?.parameters.properties; |
| 51 | if (toolProps) { |
| 52 | funcArguments[Object.keys(toolProps)[0]] = toolCall.function.arguments; |
| 53 | } |
| 54 | } |
| 55 | const functionCall: FunctionCall = { |
| 56 | name, |
| 57 | arguments: funcArguments, |
| 58 | }; |
| 59 | functionCalls.push(functionCall); |
| 60 | } |
| 61 | return functionCalls; |
| 62 | } |
| 63 | |
| 64 | export async function processChatTask( |
| 65 | task: LLMTask, |
no test coverage detected