Autogen supports a concept of config\_list which allows definitions of the LLM provider and model to be used. The AI Gateway seamlessly integrates into the Autogen framework through a custom config we create.
from autogen import AssistantAgent, UserProxyAgent, config_list_from_jsonconfig_list = [ { "api_key": 'Your OpenAI Key', "model": "@openai/gpt-3.5-turbo", "base_url": "https://aigw.portkey.ai/v1", "api_type": "openai", }]assistant = AssistantAgent("assistant", llm_config={"config_list": config_list})user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding", "use_docker": False}) # IMPORTANT: set to True to run code in docker, recommendeduser_proxy.initiate_chat(assistant, message="Say this is also a test - part 2.")# This initiates an automated chat between the two agents to solve the task
Notice that we updated the base_url to AI Gateway and then added default_headers to enable the AI Gateway specific features.When we execute this script, it would yield the same results as without the AI Gateway, but every request can now be inspected in the AI Gateway Analytics & Logs UI - including token, cost, accuracy calculations.
All the config parameters supported in the AI Gateway are available for use as part of the headers. Let’s look at some examples:
Using 3,000+ models in Autogen through the AI Gateway
Since the AI Gateway seamlessly connects to 3,000+ models across providers, you can easily connect any of these to now run with Autogen.Let’s see an example using Mistral-7B on Anyscale running with Autogen seamlessly:
from autogen import AssistantAgent, UserProxyAgent, config_list_from_jsonconfig_list = [ { "api_key": 'Your Anyscale API Key', "model": "@anyscale/mistralai/Mistral-7B-Instruct-v0.1", "base_url": "https://aigw.portkey.ai/v1", "api_type": "openai", # the AI Gateway conforms to the openai api_type }]assistant = AssistantAgent("assistant", llm_config={"config_list": config_list})user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding", "use_docker": False}) # IMPORTANT: set to True to run code in docker, recommendeduser_proxy.initiate_chat(assistant, message="Say this is also a test - part 2.")# This initiates an automated chat between the two agents to solve the task
Model Catalog in the AI Gateway lets you manage provider credentials centrally. Add your Anyscale API key to Model Catalog and use the AI Provider slug in your config.