Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Created October 16, 2023 23:58
Show Gist options
  • Save fsndzomga/f63bf90ba9e957a97d3adc0f36aa1218 to your computer and use it in GitHub Desktop.
Save fsndzomga/f63bf90ba9e957a97d3adc0f36aa1218 to your computer and use it in GitHub Desktop.
import autogen
from autogen.retrieve_utils import TEXT_FORMATS
from autogen.agentchat.contrib.retrieve_assistant_agent import RetrieveAssistantAgent
from autogen.agentchat.contrib.retrieve_user_proxy_agent import RetrieveUserProxyAgent
import chromadb
# Define the configuration list for different models
config_list = [
{
'model': 'gpt-4',
'api_key': '<your OpenAI API key here>',
},
{
'model': 'gpt-4',
'api_key': '<your Azure OpenAI API key here>',
'api_base': '<your Azure OpenAI API base here>',
'api_type': 'azure',
'api_version': '2023-06-01-preview',
},
{
'model': 'gpt-3.5-turbo',
'api_key': '<your Azure OpenAI API key here>',
'api_base': '<your Azure OpenAI API base here>',
'api_type': 'azure',
'api_version': '2023-06-01-preview',
},
]
# Ensure there are configurations available
assert len(config_list) > 0
# Load configuration list from JSON
config_list = autogen.config_list_from_json(
env_or_file="OAI_CONFIG_LIST",
file_location=".",
filter_dict={
"model": {
"gpt-4",
"gpt4",
"gpt-4-32k",
"gpt-4-32k-0314",
"gpt-35-turbo",
"gpt-3.5-turbo",
}
},
)
# Print accepted file formats for `docs_path`
print("Accepted file formats for `docs_path`:")
print(TEXT_FORMATS)
# Start logging for autogen ChatCompletion
autogen.ChatCompletion.start_logging()
# Create a RetrieveAssistantAgent instance
assistant = RetrieveAssistantAgent(
name="assistant",
system_message="You are a helpful assistant.",
llm_config={
"request_timeout": 600,
"seed": 42,
"config_list": config_list,
},
)
# Create a RetrieveUserProxyAgent instance
ragproxyagent = RetrieveUserProxyAgent(
name="ragproxyagent",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,
retrieve_config={
"task": "code",
"docs_path": "../website/docs/reference",
"chunk_token_size": 2000,
"model": config_list[0]["model"],
"client": chromadb.PersistentClient(path="/tmp/chromadb"),
"embedding_model": "all-mpnet-base-v2",
},
)
# Reset the assistant before starting a new conversation
assistant.reset()
# Define the code problem and initiate chat with the assistant
code_problem = "How can I use FLAML to perform a classification task and use spark to do parallel training. Train 30 seconds and force cancel jobs if time limit is reached."
ragproxyagent.initiate_chat(assistant, problem=code_problem, search_string="spark")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment