Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable streaming support for openai ChatCompletion #217 #465

Closed
wants to merge 5 commits into from

Conversation

Alvaromah
Copy link
Collaborator

Why are these changes needed?

The OpenAI API, along with other LLM frameworks, offers streaming capabilities that enhance debugging workflows by eliminating the need to wait for complete responses, resulting in a more efficient and time-saving process.

This is a simple and non very intrusive mechanism to support streaming.

To enable streaimg just use this code:

llm_config={
    "config_list": config_list,
    # Enable, disable streaming (defaults to False)
    "stream": True,
}

assistant = autogen.AssistantAgent(
    name="assistant",
    llm_config=llm_config,
)

Related issue number

Related to #217

Checks

@sonichi
Copy link
Contributor

sonichi commented Oct 28, 2023

Thanks. Are you aware of #393 and #203 ? We'll switch to openai v1 soon. Is it better to develop streaming support based on the newer version?

@Alvaromah
Copy link
Collaborator Author

As you know, OpenAI v1.0 is a total rewrite of the library with many breaking changes.
The more impact changes I've observed include:

  • You must instantiate a client, instead of using a global default.
  • The Azure API shape differs from the core API.

These changes may require adjustments in AutoGen codebase. However, once these updates are in place, implementing streaming should be straightforward, based on my testing.

On the other hand, I haven't noticed significant changes in the streaming behavior in version v1.0, aside from the new structure it returns in the updated version.

@sonichi
Copy link
Contributor

sonichi commented Oct 29, 2023

As you know, OpenAI v1.0 is a total rewrite of the library with many breaking changes. The more impact changes I've observed include:

  • You must instantiate a client, instead of using a global default.
  • The Azure API shape differs from the core API.

These changes may require adjustments in AutoGen codebase. However, once these updates are in place, implementing streaming should be straightforward, based on my testing.

On the other hand, I haven't noticed significant changes in the streaming behavior in version v1.0, aside from the new structure it returns in the updated version.

That's great. The changes are already in place in the PR branch #393 . The core functionalities work w/ openai v1.0 in that branch. If you could experiment with the streaming support based on that branch, we might have a chance to integrate the streaming support into v0.2 before its release.

@ragyabraham
Copy link
Collaborator

@Alvaromah I get the below error when I try to run this. Not running openai 1.0

ERROR:root:Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided.
Traceback (most recent call last):
  File "/Users/ragy/Documents/RNA/GitHub.nosync/agentcloud/agent-backend/src/utils/log_exception_context_manager.py", line 17, in log_exception
    yield
  File "/Users/ragy/Documents/RNA/GitHub.nosync/agentcloud/agent-backend/src/agents/base.py", line 107, in init_socket_generate_team
    user_proxy.initiate_chat(
  File "/Users/ragy/Library/Caches/pypoetry/virtualenvs/agent-backend-rnB-mn_B-py3.10/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 594, in initiate_chat
    self.send(self.generate_init_message(**context), recipient, silent=silent)
  File "/Users/ragy/Library/Caches/pypoetry/virtualenvs/agent-backend-rnB-mn_B-py3.10/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 346, in send
    raise ValueError(
ValueError: Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided.

@Alvaromah
Copy link
Collaborator Author

@Alvaromah I get the below error when I try to run this. Not running openai 1.0

ERROR:root:Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided.
Traceback (most recent call last):
  File "/Users/ragy/Documents/RNA/GitHub.nosync/agentcloud/agent-backend/src/utils/log_exception_context_manager.py", line 17, in log_exception
    yield
  File "/Users/ragy/Documents/RNA/GitHub.nosync/agentcloud/agent-backend/src/agents/base.py", line 107, in init_socket_generate_team
    user_proxy.initiate_chat(
  File "/Users/ragy/Library/Caches/pypoetry/virtualenvs/agent-backend-rnB-mn_B-py3.10/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 594, in initiate_chat
    self.send(self.generate_init_message(**context), recipient, silent=silent)
  File "/Users/ragy/Library/Caches/pypoetry/virtualenvs/agent-backend-rnB-mn_B-py3.10/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 346, in send
    raise ValueError(
ValueError: Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided.

Could you please provide a sample code to repro this error?
Are you using functions?

Thanks

@Alvaromah
Copy link
Collaborator Author

I made some changes in the streaming implementation to support more scenarios. However, this version is not compatible with OpenAI v1.0.
I am preparing another PR for dev/v0.2

@Alvaromah
Copy link
Collaborator Author

Created PR #491 for dev/v0.2 tested on openai v1.0.0b3

@ragyabraham
Copy link
Collaborator

@Alvaromah I get the below error when I try to run this. Not running openai 1.0

ERROR:root:Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided.
Traceback (most recent call last):
  File "/Users/ragy/Documents/RNA/GitHub.nosync/agentcloud/agent-backend/src/utils/log_exception_context_manager.py", line 17, in log_exception
    yield
  File "/Users/ragy/Documents/RNA/GitHub.nosync/agentcloud/agent-backend/src/agents/base.py", line 107, in init_socket_generate_team
    user_proxy.initiate_chat(
  File "/Users/ragy/Library/Caches/pypoetry/virtualenvs/agent-backend-rnB-mn_B-py3.10/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 594, in initiate_chat
    self.send(self.generate_init_message(**context), recipient, silent=silent)
  File "/Users/ragy/Library/Caches/pypoetry/virtualenvs/agent-backend-rnB-mn_B-py3.10/lib/python3.10/site-packages/autogen/agentchat/conversable_agent.py", line 346, in send
    raise ValueError(
ValueError: Message can't be converted into a valid ChatCompletion message. Either content or function_call must be provided.

Could you please provide a sample code to repro this error? Are you using functions?

Thanks

Sorry, it was actually an issue on my end. Working well for me now. Thank you

@codecov-commenter
Copy link

codecov-commenter commented Oct 31, 2023

Codecov Report

Attention: Patch coverage is 5.00000% with 38 lines in your changes missing coverage. Please review.

Project coverage is 1.25%. Comparing base (5694486) to head (3afc70d).
Report is 1654 commits behind head on main.

Files with missing lines Patch % Lines
autogen/oai/chat_completion_proxy.py 2.56% 38 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (5694486) and HEAD (3afc70d). Click for more details.

HEAD has 2 uploads less than BASE
Flag BASE (5694486) HEAD (3afc70d)
unittests 3 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #465       +/-   ##
==========================================
- Coverage   42.59%   1.25%   -41.35%     
==========================================
  Files          21      21               
  Lines        2526    2559       +33     
  Branches      566     573        +7     
==========================================
- Hits         1076      32     -1044     
- Misses       1359    2527     +1168     
+ Partials       91       0       -91     
Flag Coverage Δ
unittests 1.25% <5.00%> (-41.27%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AaronWard AaronWard requested review from AaronWard and removed request for AaronWard November 2, 2023 21:16
@Louis2602
Copy link

You are amazing!!!

@sonichi sonichi added the documentation Improvements or additions to documentation label Jan 11, 2024
@sonichi sonichi added async and removed documentation Improvements or additions to documentation async labels Jan 11, 2024
@gagb gagb closed this Aug 26, 2024
jackgerrits pushed a commit that referenced this pull request Oct 2, 2024
…ntation (#465)

* host agent runtime API and docs

* graceful shutdown of worker

* HostAgentRuntime --> WorkerAgentRuntimeHost

* Add unit tests for worker runtime

* Fix bug in worker runtime adding sender filed to proto. Documentation.

* wip

* Fix unit tests; refactor API

* fix formatting

* Fix

* Update

* Make source field optional in Event proto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants