Automatically calling tools/functions with Assistants

Hey all - In the JS lib there is a helper function chat.completions.runTools that automatically calls a js function and passes the output back to the ai to craft the response message or call another function. This has been very handy.

It doesn’t look like that exists for the Assistants api: https://platform.openai.com/docs/assistants/tools/function-calling/quickstart

You have to listen for the tool that requires action event.event === "thread.run.requires_action" and then call the function and pass the output to run.submitToolOutputs .

I’m pretty lazy and I’m hoping someone knows of the runTools equivalent for assistants so I don’t have to implement this for a migration to the assistants api.

2 Likes

Ok I guess I’m not thaaat lazy.

Here’s some help for anyone that finds this thread:

I borrowed from this https://platform.openai.com/docs/assistants/tools/function-calling/quickstart?context=without-streaming

And created this:

JS functional ( :-1: classes) wrapper that automatically calls functions/tools passed into an assistant api call.

Don’t be scared of all the setup code. The adapted (improved) part is lines 207-223 that finds and calls the function and passes back to the LLM. The rest sets up the test run.

Happy hacking!

1 Like