-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Added Azure AI Chat Completion Client #4723
base: main
Are you sure you want to change the base?
Added Azure AI Chat Completion Client #4723
Conversation
@yanivvak can you review this? |
@ekzhu @rohanthacker
|
python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py
Show resolved
Hide resolved
python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py
Show resolved
Hide resolved
python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py
Show resolved
Hide resolved
python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py
Show resolved
Hide resolved
@lspinheiro could you help reviewing this PR? |
|
||
class AzureAIChatCompletionClient(ChatCompletionClient): | ||
def __init__(self, **kwargs: Unpack[AzureAIChatCompletionClientConfig]): | ||
if "endpoint" not in kwargs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this part could benefit from some better separation of concerns between config validation and instantiation. e.g.
class AzureAIChatCompletionClient(ChatCompletionClient):
def __init__(self, **kwargs: Unpack[AzureAIClientConfiguration]):
config = self._validate_config(kwargs)
self._client = self._create_client(config)
self._create_args = self._prepare_create_args(config)
# ...
@staticmethod
def _validate_config(config: Mapping[str, Any]) -> AzureAIClientConfiguration:
# Validation logic here
return config
Looks quite good and is consistent with the openai client. I have a minor comment about the config validation. @jackgerrits may have more options since a lot of the design decisions here are driven by his original implementation of the openai client. If anything doesn't make since in this context he would be the best person to evaluate. |
* Added: object-level usage data * Added: doc string * Added: check existing response_format value * Added: _validate_config and _create_client
d53421b
to
daf43de
Compare
content = choice.message.content or "" | ||
|
||
response = CreateResult( | ||
finish_reason=finish_reason, # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the latest update to canonicalize the finish_reason. See OpenAIChatCompletionClient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rohanthacker Is this PR ready to review? It looks good from code perspective. @srjoglekar246 could you help to use it in an assistant agent and running some teams on it to test it out?
|
||
def __init__(self, **kwargs: Unpack[AzureAIChatCompletionClientConfig]): | ||
config = self._validate_config(kwargs) | ||
self._model_capabilities = config["model_capabilities"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Model Capabilities are deprecated, use ModelInfo
. See OpenAIChatCompletionClient: https://github.com/microsoft/autogen/blob/main/python/packages/autogen-ext/src/autogen_ext/models/openai/_openai_client.py#L912-L913
client = AzureAIChatCompletionClient( | ||
endpoint="endpoint", | ||
credential=AzureKeyCredential("api_key"), | ||
model_capabilities={ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use model_info
as model_capabilities
is deprecated.
@rohanthacker I made this PR ready for review. |
@ekzhu For context, this works for Azure AI Inference. I tested on a Phi-4 deployment I created. from semantic_kernel import Kernel
from semantic_kernel.memory.null_memory import NullMemory
from semantic_kernel.connectors.ai.azure_ai_inference import AzureAIInferenceChatCompletion
from semantic_kernel.connectors.ai.azure_ai_inference import AzureAIInferenceChatPromptExecutionSettings
from autogen_core.models import SystemMessage, UserMessage, LLMMessage
from autogen_ext.models.semantic_kernel import SKChatCompletionAdapter
kernel = Kernel(memory=NullMemory())
execution_settings = AzureAIInferenceChatPromptExecutionSettings(
max_tokens=100,
temperature=0.5,
top_p=0.9,
)
chat_completion_service = AzureAIInferenceChatCompletion(ai_model_id="Phi-4")
model_adapter = SKChatCompletionAdapter(sk_client=chat_completion_service)
messages: list[LLMMessage] = [
SystemMessage(content="You are a helpful assistant."),
UserMessage(content="What is 2 + 2?", source="user"),
]
azure_result = await model_adapter.create(
messages=messages,
extra_create_args={"kernel": kernel, "prompt_execution_settings": execution_settings},
)
print("Azure result:", azure_result.content) |
@@ -56,6 +56,11 @@ redis = [ | |||
grpc = [ | |||
"grpcio~=1.62.0", # TODO: update this once we have a stable version. | |||
] | |||
|
|||
azure-ai-inference = [ | |||
"azure-ai-inference>=1.0.0b6", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be merged with the azure
extra, because if you want to use this you need azure-identity
anyway.
Related issue number
#4683 Adds initial support for Azure AI Chat Completion Client
Checks