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

Azure OpenAI API key not working for Autogen #601

Closed
anna11290 opened this issue Nov 8, 2023 · 14 comments
Closed

Azure OpenAI API key not working for Autogen #601

anna11290 opened this issue Nov 8, 2023 · 14 comments
Labels
question Further information is requested setup installation and setup issues

Comments

@anna11290
Copy link

Hello, I am trying to code an autogen bot using my Azure OpenAI Api key and my deployment I have created. I have used this key and deployment before in other projects not involving Autogen, and it has worked fine. However, when I try to use it for my Autogen code on a local Jupyter notebook, I get this error:

InvalidRequestError: The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.

I know that it's not my code and has to do with the Azure OpenAI API key itself, because when I tried my code with my own personal OpenAI API key, the code worked perfectly. However, for logistical reasons I must use my Azure OpenAI API key for this project. Does anyone know how to fix this? Here is my code for implementing my Azure OpenAI API key:

!pip install pyautogen
import sys
sys.path.append('./lib/python3.9/site-packages')
import autogen
config_list = [
{
'model' : 'gpt-3.5-turbo',
'api_key':'XXX',
'api_base' : 'XXX
'api_type' : 'azure',
'api_version' : '2023-05-15',
'deployment_name':'XXX'
}
]

@sonichi
Copy link
Collaborator

sonichi commented Nov 8, 2023

Which version of pyautogen are you using?

@sonichi sonichi added question Further information is requested setup installation and setup issues labels Nov 8, 2023
@sonichi
Copy link
Collaborator

sonichi commented Nov 8, 2023

"model" needs to be set to match the deployment_name while "deployment_name" can be removed.

@IyobedZekarias
Copy link

IyobedZekarias commented Nov 8, 2023

I'm getting the same error here. This is my OAI_CONFIG_LIST.json

{
        "model": "gpt-35-turbo",  
        "base_url": "xxx", 
        "api_type": "azure", 
        "api_version": "2023-07-01-preview", 
        "api_key": "xxx"
 }

I know this instance exists because I can use it with just a normal openai call but getting 'Resource not found' when using it with autogen.

pyautogen version 0.2.0b1
openai version 1.0.0b3

@afourney
Copy link
Member

afourney commented Nov 8, 2023

When you say it works with a regular OpenAI call, are you changing "model" -> "engine"?

I think Autogen does this automatically, but the OpenAI library does not. I would expect it to fail with this same configuration.

@IyobedZekarias
Copy link

Yes, I switch it to engine.
So, it looks like the version on openai that autogen is using, 1.0.0b3, doesn't include the AzureOpenAI function that openai version 1.1.0 has. This is necessary to handle a call to an azure openai instance.

@anna11290
Copy link
Author

Yes, I switch it to engine.
So, it looks like the version on openai that autogen is using, 1.0.0b3, doesn't include the AzureOpenAI function that openai version 1.1.0 has. This is necessary to handle a call to an azure openai instance.

Were you able to fix it yet?

@afourney
Copy link
Member

afourney commented Nov 8, 2023

Thanks for debugging. I think 0.2.0b2 or 0.2.0b3 moves to OpenAI 1.1.0. Perhaps this offers a fix? @sonichi knowns more.

@IyobedZekarias
Copy link

@anna11290

Yes, I switch it to engine.
So, it looks like the version on openai that autogen is using, 1.0.0b3, doesn't include the AzureOpenAI function that openai version 1.1.0 has. This is necessary to handle a call to an azure openai instance.

Were you able to fix it yet?

So, to fix it on mine I had to upgrade to 1.1.0 then I had to update the _client function call and the _process_for_azure function call in client.py to handle AzureOpenAI as well as OpenAI. It's a tad clunky since I don't know how all the code ties together but if you guys want a fix then I'd start there.

@yigitkonur
Copy link

To fix this issue, you need to install AutoGen with beta release:

pip install pyautogen==0.2.0b2

Here is how to load config to fix this problem to specify deployment_name:

import autogen

config_list = [
    {
        "model": "YOUR_DEPLOYMENT_NAME",  
        "base_url": "https://xxx.openai.azure.com", 
        "api_type": "azure", 
        "api_version": "2023-07-01-preview", 
        "api_key": "xxx"
 }
]

I've stuck for a lot time, that is why wanna share with you to help to fix it.

@sonichi
Copy link
Collaborator

sonichi commented Nov 9, 2023

pyautogen==0.2.0b3 uses openai==1.1.1

@Markusdreyer
Copy link
Contributor

"model" needs to be set to match the deployment_name while "deployment_name" can be removed.

This was not clear in the sample or documentation, so I created a PR for this: #734

@tonkatsu7
Copy link

To fix this issue, you need to install AutoGen with beta release:

pip install pyautogen==0.2.0b2

Here is how to load config to fix this problem to specify deployment_name:

import autogen

config_list = [
    {
        "model": "YOUR_DEPLOYMENT_NAME",  
        "base_url": "https://xxx.openai.azure.com", 
        "api_type": "azure", 
        "api_version": "2023-07-01-preview", 
        "api_key": "xxx"
 }
]

I've stuck for a lot time, that is why wanna share with you to help to fix it.

THANK YOU SO MUCH! Just spent a couple of hours on this 😆 Now we know that MS research scientists don't use AOAI!

@pq-dong
Copy link

pq-dong commented Nov 29, 2023

pyautogen==0.2.0b3 uses openai==1.1.1

thanks I solved the problem using this version.

I also tried version 0.2.0b1, and some errors appeared.

@sonichi sonichi closed this as completed Dec 3, 2023
@edmald
Copy link

edmald commented May 28, 2024

Hi everyone,

Is there a way to use Azure OpenAI and Autogen without having the API key? In my company, we only receive information for access via the token. Here are the details we have:

API_VERSION: '....'
AZURE_OPENAI_ENDPOINT: '....'
MODEL_NAME: '....'
URL_TOKEN: '....'

Any guidance on how to proceed with this setup would be greatly appreciated.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested setup installation and setup issues
Projects
None yet
Development

No branches or pull requests

9 participants