microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
31.56k stars 4.59k forks source link

Azure OpenAI API key not working for Autogen #601

Closed anna11290 closed 10 months ago

anna11290 commented 11 months ago

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 commented 11 months ago

Which version of pyautogen are you using?

sonichi commented 11 months ago

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

IyobedZekarias commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

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 commented 11 months ago

pyautogen==0.2.0b3 uses openai==1.1.1

Markusdreyer commented 10 months ago

"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: https://github.com/microsoft/autogen/pull/734

tonkatsu7 commented 10 months ago

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 commented 10 months ago

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.

edmald commented 4 months ago

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!