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

Add support for JsonSchemaFormat in AzureAIChatCompletionClient #5233

Open
rohanthacker opened this issue Jan 28, 2025 · 1 comment
Open

Comments

@rohanthacker
Copy link
Contributor

rohanthacker commented Jan 28, 2025

What happened?

The Azure SDK for python which is used by the AzureAIChatCompletionClient added support for chat completions response message in JSON format that adheres to a given JSON schema. The autgen-ext module for this client should be updated to support this feature.

What did you expect to happen?

As user I should have the option to pass a pydantic model that the model will adhere to

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

import os
import asyncio

from pydantic import BaseModel

from autogen_core.models import UserMessage
from autogen_ext.models.azure import AzureAIChatCompletionClient
from azure.ai.inference.models import JsonSchemaFormat
from azure.core.credentials import AzureKeyCredential

class Response(BaseModel):
    thoughts: str
    response: str

async def main():
    schema = Response.model_json_schema()
    print(schema)
    format = JsonSchemaFormat(
        name="Response",
        schema=schema,
        description="Response from the model",
        strict=True,
    )
    client = AzureAIChatCompletionClient(
        model="gpt-4o-mini",
        api_version="2024-08-01-preview",
        endpoint="https://models.inference.ai.azure.com",
        # To authenticate with the model you will need to generate a personal access token (PAT) in your GitHub settings.
        # Create your PAT token by following instructions here: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
        credential=AzureKeyCredential(os.environ["GITHUB_TOKEN"]),
        model_info={
            "json_output": False,
            "function_calling": False,
            "vision": False,
            "family": "unknown",
        },
    )

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

asyncio.run(main())

AutoGen version

0.4.3

Which package was this bug in

Extensions

Model used

No response

Python version

No response

Operating system

No response

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

Reference Links:
https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/ai/azure-ai-inference/CHANGELOG.md
Discussion History -> #5199

@ekzhu
Copy link
Collaborator

ekzhu commented Jan 28, 2025

I think to make the interface simpler and consistent with OpenAIChatCompletionClient is useful here. Ideally, user can choose to pass in just the BaseModel class defining the output schema, and that's it.

@ekzhu ekzhu added this to the 0.4.x milestone Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants