MCPcopy Index your code
hub / github.com/Xyntopia/taskyon / extractOpenAIFunctions

Function extractOpenAIFunctions

src/modules/taskWorker.ts:35–62  ·  view source on GitHub ↗
(choice: OpenAI.ChatCompletion['choices'][0])

Source from the content-addressed store, hash-verified

33}
34
35function 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
64export async function processChatTask(
65 task: LLMTask,

Callers 1

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected