Wednesday, October 23, 2024

OpenAI API : Functions vs Tools vs Structured Outputs vs Assistants

similar functionality, different name = unnecessary confusion

Functions VS Tools - What is the difference? - API - OpenAI Developer Forum

functions have been deprecated, and tools are the way forward. Tools: A list of tools the model may call. Currently, only functions are supported as a tool.

API Reference - OpenAI API

Deprecated in favor of tools.

API Reference - OpenAI API

A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.


Assistants overview - OpenAI API

  • Assistants can call OpenAI’s models with specific instructions to tune their personality and capabilities.
  • Assistants can access multiple tools in parallel. These can be both OpenAI-hosted tools — like code_interpreter and file_search — or tools you build / host (via function calling).
  • Assistants can access persistent Threads. Threads simplify AI application development by storing message history and truncating it when the conversation gets too long for the model’s context length. You create a Thread once, and simply append Messages to it as your users reply.
  • Assistants can access files in several formats — either as part of their creation or as part of Threads between Assistants and users. When using tools, Assistants can also create files (e.g., images, spreadsheets, etc) and cite files they reference in the Messages they create.
AssistantPurpose-built AI that uses OpenAI’s models and calls tools
ThreadA conversation session between an Assistant and a user. Threads store Messages and automatically handle truncation to fit content into a model’s context.
MessageA message created by an Assistant or a user. Messages can include text, images, and other files. Messages stored as a list on the Thread.
RunAn invocation of an Assistant on a Thread. The Assistant uses its configuration and the Thread’s Messages to perform tasks by calling models and tools. As part of a Run, the Assistant appends Messages to the Thread.
Run StepA detailed list of steps the Assistant took as part of a Run. An Assistant can call tools or create Messages during its run. Examining Run Steps allows you to introspect how the Assistant is getting to its final results.




Assistant Tools - OpenAI API


openai/openai-assistants-quickstart: OpenAI Assistants API quickstart with Next.js. @GitHub


Function Calling - OpenAI API


As an alternative to function calling you can instead constrain the model's regular output to match a JSON Schema of your choosing. Learn more about when to use function calling vs when to control the model's normal output by using response_format.

When you turn it on by setting strict: true, in your function definition, Structured Outputs ensures that the arguments generated by the model for a function call exactly match the JSON Schema you provided in the function definition.