You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was a bit confused on how this works. It would be nice to just have something like load_dotenv() to handle the keys. But anyways - Just going off the examples in the /notebooks directory i made a file called OAI_CONFIG_LIST (with no filetype)
And then i pass the config_list to the initiate_chat function.
assistant=AssistantAgent("assistant")
user_proxy=UserProxyAgent("user_proxy")
user_proxy.initiate_chat(assistant,
message="Plot a chart of META and TESLA stock price change YTD.",
config_list=config_list
)
This worked for me
Update
If you'd rather use load_dotenv() this worked for me.
I was a bit confused on how this works. It would be nice to just have something like load_dotenv() to handle the keys. But anyways - Just going off the examples in the /notebooks directory i made a file called OAI_CONFIG_LIST (with no filetype)
And then i pass the config_list to the initiate_chat function.
assistant=AssistantAgent("assistant")
user_proxy=UserProxyAgent("user_proxy")
user_proxy.initiate_chat(assistant,
message="Plot a chart of META and TESLA stock price change YTD.",
config_list=config_list
)
This worked for me
Update
If you'd rather use load_dotenv() this worked for me.
I'm trying to solve the same problem using fastchat with a local llm as in the documentation but it fails because I don't provide an openai key:
from autogen import AssistantAgent, UserProxyAgent, oai
config_list=[
{
"model": "chatglm2-6b",
"api_base": "http://localhost:8000/v1",
"api_type": "open_ai",
"api_key": "NULL", # just a placeholder
}
]
response = oai.Completion.create(config_list=config_list, prompt="Hi")
print(response) # works fine
assistant = AssistantAgent("assistant")
user_proxy = UserProxyAgent("user_proxy")
user_proxy.initiate_chat(assistant, message="Plot a chart of META and TESLA stock price change YTD.", config_list=config_list)
# fails with the error: openai.error.AuthenticationError: No API key provided.
I'm trying to solve the same problem using fastchat with a local llm as in the documentation but it fails because I don't provide an openai key:
from autogen import AssistantAgent, UserProxyAgent, oai
config_list=[
{
"model": "chatglm2-6b",
"api_base": "http://localhost:8000/v1",
"api_type": "open_ai",
"api_key": "NULL", # just a placeholder
}
]
response = oai.Completion.create(config_list=config_list, prompt="Hi")
print(response) # works fine
assistant = AssistantAgent("assistant")
user_proxy = UserProxyAgent("user_proxy")
user_proxy.initiate_chat(assistant, message="Plot a chart of META and TESLA stock price change YTD.", config_list=config_list)
# fails with the error: openai.error.AuthenticationError: No API key provided.
Please add llm_config={"config_list": config_list} in the constructor of AssistantAgent
Update: i found that my previous example was throwing an error because the json was being parsed as a string. Here is working example of setting up your config list using dotenv. This will allow you to dynamically create the json file required by autogen.config_list_from_json() when you're using a .env file
importtempfilefromdotenvimportfind_dotenv, load_dotenvload_dotenv(find_dotenv())
env_var= [
{
'model': 'gpt-4',
'api_key': os.getenv('OPENAI_API_KEY')
},
{
'model': 'gpt-3.5-turbo',
'api_key': os.getenv('OPENAI_API_KEY')
}
]
# Create a temporary file# Write the JSON structure to a temporary file and pass it to config_list_from_jsonwithtempfile.NamedTemporaryFile(mode='w+', delete=True) astemp:
env_var=json.dumps(env_var)
temp.write(env_var)
temp.flush()
# Setting configurations for autogenconfig_list=autogen.config_list_from_json(
env_or_file=temp.name,
filter_dict={
"model": {
"gpt-4",
"gpt-3.5-turbo",
}
}
)
assertlen(config_list) >0print("models to use: ", [config_list[i]["model"] foriinrange(len(config_list))])
Activity
sonichi commentedon Sep 20, 2023
Could you read https://microsoft.github.io/autogen/docs/Use-Cases/enhanced_inference#runtime-error and see if the issue is addressed?
rustyorb commentedon Sep 27, 2023
Is there a working example of this file, in JSON format? I can get this file to work or parse right when I create it.
AaronWard commentedon Sep 27, 2023
I was a bit confused on how this works. It would be nice to just have something like
load_dotenv()to handle the keys. But anyways - Just going off the examples in the/notebooksdirectory i made a file calledOAI_CONFIG_LIST(with no filetype)[ { "model": "gpt-4", "api_key": "***" }, { "model": "gpt-3.5-turbo", "api_key": "***" } ]In my notebook:
When printing
config_list[{'model': 'gpt-4', 'api_key': '***'}, {'model': 'gpt-3.5-turbo', 'api_key': '***}]And then i pass the
config_listto theinitiate_chatfunction.This worked for me
Update
If you'd rather use
load_dotenv()this worked for me.rustyorb commentedon Sep 27, 2023
This is tremendously helpful, thank you.
sonichi commentedon Sep 27, 2023
Thanks. You can also have a single env var which contains the entire json and load it directly:
EdFries commentedon Sep 27, 2023
I'm trying to solve the same problem using fastchat with a local llm as in the documentation but it fails because I don't provide an openai key:
sonichi commentedon Sep 27, 2023
Please add
llm_config={"config_list": config_list}in the constructor ofAssistantAgentEdFries commentedon Sep 27, 2023
Thanks, that worked!
sonichi commentedon Sep 27, 2023
Added to FAQ: https://microsoft.github.io/autogen/docs/FAQ/#set-your-api-endpoints
AaronWard commentedon Sep 28, 2023
Update: i found that my previous example was throwing an error because the json was being parsed as a string. Here is working example of setting up your config list using
dotenv. This will allow you to dynamically create the json file required byautogen.config_list_from_json()when you're using a.envfilemodels to use: ['gpt-4', 'gpt-3.5-turbo']Merge pull request #3 from microsoft/main
Ollama Client (with tool calling) (microsoft#3)
cjy8s commentedon Sep 26, 2024
Gives me this warning now:
AaronWard commentedon Sep 27, 2024
Christopher Yates (@cjy8s) You can just use the
config_list_from_dotenvfunction instead of writing a temporary file.devcontainer with cosmos + qdrant (#3)
Renaming things (#3)
Merge dotnet conflict (#3)