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

NotFoundError when specifying azure_deployment in AzureOpenAI client #1163

Open
1 task done
IANTHEREAL opened this issue Feb 19, 2024 · 2 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@IANTHEREAL
Copy link

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

When initializing the AzureOpenAI client with the azure_deployment parameter specified, a NotFoundError with error code 404 is raised upon calling client.beta.assistants.list(). However, omitting the azure_deployment parameter results in the expected behavior with no errors.

(autogen) ➜  autogen git:(main) ✗ python test.py
Traceback (most recent call last):
  File "/Users/ianz/Work/autogen/test.py", line 11, in <module>
    print(client.beta.assistants.list())
  File "/Users/ianz/Work/miniconda3/envs/autogen/lib/python3.10/site-packages/openai/resources/beta/assistants/assistants.py", line 270, in list
    return self._get_api_list(
  File "/Users/ianz/Work/miniconda3/envs/autogen/lib/python3.10/site-packages/openai/_base_client.py", line 1145, in get_api_list
    return self._request_api_list(model, page, opts)
  File "/Users/ianz/Work/miniconda3/envs/autogen/lib/python3.10/site-packages/openai/_base_client.py", line 990, in _request_api_list
    return self.request(page, options, stream=False)
  File "/Users/ianz/Work/miniconda3/envs/autogen/lib/python3.10/site-packages/openai/_base_client.py", line 856, in request
    return self._request(
  File "/Users/ianz/Work/miniconda3/envs/autogen/lib/python3.10/site-packages/openai/_base_client.py", line 908, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.NotFoundError: Error code: 404 - {'error': {'code': '404', 'message': 'Resource not found'}}

To Reproduce

import os
from openai import AzureOpenAI
    
client = AzureOpenAI(
    api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
    api_version="2024-02-15-preview",
    azure_endpoint = os.getenv("AZURE_OPENAI_API_BASE"),
    azure_deployment = "gpt-4-turbo"
)

print(client.beta.assistants.list())

Code snippets

No response

OS

macOS

Python version

Python 3.10.13

Library version

1.3.7

@kristapratico
Copy link
Contributor

@IANTHEREAL This is a good call out. For Azure assistants APIs, azure_deployment is not supported. To explain, Assistants is a bit different than other deployment-based features, in that it does not require the deployment name in the URL like: {endpoint}/openai/deployments/{azure_deployment}/chat/completions. While the client-level azure_deployment keyword argument is meant as a convenience to add the deployment name to the URL for you, we see in this case that it's not needed and results in 404. For Assistants APIs where you do need to pass the name of your deployment, i.e. assistants.create, you should pass it at the method-level:

my_assistant = client.beta.assistants.create(
    instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
    name="Math Tutor",
    tools=[{"type": "code_interpreter"}],
    model="deployment-name",
)

@rattrayalex - I think the AzureOpenAI docstring should be updated to mention that azure_deployment is not supported for the assistants APIs. I can open a PR.

@rattrayalex
Copy link
Collaborator

Please do, thank you Krista!

cc @RobertCraigie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants