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

Error when closing AzureAIChatCompletionClient upon a validation error #5414

Closed
pamelafox opened this issue Feb 7, 2025 · 4 comments · Fixed by #5417
Closed

Error when closing AzureAIChatCompletionClient upon a validation error #5414

pamelafox opened this issue Feb 7, 2025 · 4 comments · Fixed by #5417

Comments

@pamelafox
Copy link
Member

What happened?

I'm attempting to use AzureAIChatCompletionClient with the travel_planning example, with this client:

client = AzureAIChatCompletionClient(
        model="gpt-4o",
        endpoint="https://models.inference.ai.azure.com",
        credential=AzureKeyCredential(os.environ["GITHUB_TOKEN"]),
        model_info={
            "json_output": True,
            "function_calling": True,
            "vision": True,
            "model": "gpt-4o",
        },
    )

However, I get this error:

Exception ignored in: <function AzureAIChatCompletionClient.__del__ at 0x740702f232e0>
Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.12/site-packages/autogen_ext/models/azure/_azure_ai_client.py", line 516, in __del__
    asyncio.get_running_loop().create_task(self._client.close())
                                           ^^^^^^^^^^^^
AttributeError: 'AzureAIChatCompletionClient' object has no attribute '_client'
Exception ignored in: <function AzureAIChatCompletionClient.__del__ at 0x740702f232e0>
Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.12/site-packages/autogen_ext/models/azure/_azure_ai_client.py", line 516, in __del__
    asyncio.get_running_loop().create_task(self._client.close())
                                           ^^^^^^^^^^^^
AttributeError: 'AzureAIChatCompletionClient' object has no attribute '_client'
Exception ignored in: <function AzureAIChatCompletionClient.__del__ at 0x740702f232e0>
Traceback (most recent call last):
  File "/home/codespace/.python/current/lib/python3.12/site-packages/autogen_ext/models/azure/_azure_ai_client.py", line 516, in __del__
    asyncio.get_running_loop().create_task(self._client.close())
                                           ^^^^^^^^^^^^
AttributeError: 'AzureAIChatCompletionClient' object has no attribute '_client'

What did you expect to happen?

Success

How can we reproduce it (as minimally and precisely as possible)?

Open travel_planning.ipynb, use that client instead

AutoGen version

latest (editable install from Codespaces)

Which package was this bug in

Extensions

Model used

gpt-4o, GitHub models

Python version

3.12

Operating system

Linux

Any additional info you think would be helpful for fixing this bug

No response

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 7, 2025

Your model family is incorrect. That value error led to another exception caused by the closing of the client not finding an instance of the underlying azure ai inference client. Update your code to this:

import asyncio
import os
from azure.core.credentials import AzureKeyCredential
from autogen_ext.models.azure import AzureAIChatCompletionClient
from autogen_core.models import UserMessage, ModelFamily


async def main():
    client = AzureAIChatCompletionClient(
        model="gpt-4o",
        endpoint="https://models.inference.ai.azure.com",
        credential=AzureKeyCredential(os.environ["GITHUB_TOKEN"]),
        model_info={
            "json_output": True,
            "function_calling": True,
            "vision": True,
            "family": ModelFamily.GPT_4O,
        },
    )

    result = await client.create([UserMessage(content="What is the capital of France?", source="user")])
    print(result)


if __name__ == "__main__":
    asyncio.run(main())

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 7, 2025

Keep this issue open, we will need to update the handling of the closing error.

@ekzhu ekzhu changed the title Error when using AzureAIChatCompletionClient Error when closing AzureAIChatCompletionClient upon a validation error Feb 7, 2025
@ekzhu ekzhu added this to the python-v0.4.6 milestone Feb 7, 2025
@pamelafox
Copy link
Member Author

Ah okay, I was guessing the family as the example given had "unknown", a string. Might help if the example code had a ModelFamily.

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 7, 2025

@pamelafox if you use Python extension in VSCode it's easier with auto suggestions from valid family values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants