openai / openai-python

The official Python library for the OpenAI API
https://pypi.org/project/openai/
Apache License 2.0
22.41k stars 3.12k forks source link

Better implementation for `assistant` `function` calls #1399

Closed hesenp closed 5 months ago

hesenp commented 5 months ago

Confirm this is a feature request for the Python library and not the underlying OpenAI API.

Describe the feature or improvement you're requesting

Why the current Implementation for assistant function calling is cumbersome

I feel the implementation for function calls in Python is quite cumberson with assistant. If I understand the documentations correctly, the initial approach requires developers to handle threads, runs, and tool outputs manually. Each step, from starting conversations and defining tools to gathering and submitting outputs, involves multiple function calls. This complexity makes the process error-prone and less intuitive for developers.

To just get started with assistant (no function calls yet), we need to define four things:

To enable function calls, we need to wrap the function results in yet another object tool_outputs_stream. I feel there could be better implementations out there. As a result, I asked chatGPT on what could be a better implementation.

Desired improvement

I guess we should introduces a unified "Assistant with Function Call Capability" object. This single object manages all aspects of function-based interactions, offering an interface for setting up an assistant, starting conversations, handling messages, collecting function outputs, and submitting results.

I have asked ChatGPT to generate a mockup AssistantWithFunctionCalls. Please let me know if there is interest in bringing this feature in?

ChatGPT conversation

Additional context

No response

hesenp commented 5 months ago

Ah never mind. seems langchain has some wrapper along this line.