-
-
Notifications
You must be signed in to change notification settings - Fork 11.6k
[Misc] add AutoGen integration #18712
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| --- | ||
| title: AutoGen | ||
| --- | ||
| [](){ #deployment-autogen } | ||
|
|
||
| [AutoGen](https://github.com/microsoft/autogen) is a framework for creating multi-agent AI applications that can act autonomously or work alongside humans. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Setup vLLM environment | ||
|
|
||
| - Setup [AutoGen](https://microsoft.github.io/autogen/0.2/docs/installation/) environment | ||
|
|
||
| ```console | ||
| pip install vllm | ||
|
|
||
| # Install AgentChat and OpenAI client from Extensions | ||
| # AutoGen requires Python 3.10 or later. | ||
| pip install -U "autogen-agentchat" "autogen-ext[openai]" | ||
| ``` | ||
|
|
||
| ## Deploy | ||
|
|
||
| - Start the vLLM server with the supported chat completion model, e.g. | ||
|
|
||
| ```console | ||
| python -m vllm.entrypoints.openai.api_server \ | ||
| --model mistralai/Mistral-7B-Instruct-v0.2 | ||
| ``` | ||
|
|
||
| - Call it with AutoGen: | ||
|
|
||
| ```python | ||
| import asyncio | ||
| from autogen_core.models import UserMessage | ||
| from autogen_ext.models.openai import OpenAIChatCompletionClient | ||
| from autogen_core.models import ModelFamily | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| # Create a model client | ||
| model_client = OpenAIChatCompletionClient( | ||
| model="mistralai/Mistral-7B-Instruct-v0.2", | ||
| base_url="http://{your-vllm-host-ip}:{your-vllm-host-port}/v1", | ||
| api_key="EMPTY", | ||
| model_info={ | ||
| "vision": False, | ||
| "function_calling": False, | ||
| "json_output": False, | ||
| "family": ModelFamily.MISTRAL, | ||
| "structured_output": True, | ||
| }, | ||
| ) | ||
|
|
||
| messages = [UserMessage(content="Write a very short story about a dragon.", source="user")] | ||
|
|
||
| # Create a stream. | ||
| stream = model_client.create_stream(messages=messages) | ||
|
|
||
| # Iterate over the stream and print the responses. | ||
| print("Streamed responses:") | ||
| async for response in stream: | ||
| if isinstance(response, str): | ||
| # A partial response is a string. | ||
| print(response, flush=True, end="") | ||
| else: | ||
| # The last response is a CreateResult object with the complete message. | ||
| print("\n\n------------\n") | ||
| print("The complete response:", flush=True) | ||
| print(response.content, flush=True) | ||
|
|
||
| # Close the client when done. | ||
| await model_client.close() | ||
|
|
||
|
|
||
| asyncio.run(main()) | ||
| ``` | ||
|
|
||
| For details, see the tutorial: | ||
|
|
||
| - [Using vLLM in AutoGen](https://microsoft.github.io/autogen/0.2/docs/topics/non-openai-models/local-vllm/) | ||
|
|
||
| - [OpenAI-compatible API examples](https://microsoft.github.io/autogen/stable/reference/python/autogen_ext.models.openai.html#autogen_ext.models.openai.OpenAIChatCompletionClient) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.