mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: updated doc generation setup and some slight api enhancements (#267)
* updated doc generation setup and some slight api enhancements * small fix in index
This commit is contained in:
committed by
GitHub
Unverified
parent
139f033b05
commit
42c7a59640
@@ -4,6 +4,7 @@ import importlib.metadata
|
||||
|
||||
from ._chat_client import AzureChatClient
|
||||
from ._entra_id_authentication import get_entra_auth_token
|
||||
from ._shared import AzureOpenAISettings
|
||||
|
||||
try:
|
||||
__version__ = importlib.metadata.version(__name__)
|
||||
@@ -12,6 +13,7 @@ except importlib.metadata.PackageNotFoundError:
|
||||
|
||||
__all__ = [
|
||||
"AzureChatClient",
|
||||
"AzureOpenAISettings",
|
||||
"__version__",
|
||||
"get_entra_auth_token",
|
||||
]
|
||||
|
||||
@@ -16,8 +16,8 @@ from agent_framework import (
|
||||
TextContent,
|
||||
)
|
||||
from agent_framework.exceptions import ServiceInitializationError
|
||||
from agent_framework.openai import OpenAIModelTypes
|
||||
from agent_framework.openai._chat_client import OpenAIChatClientBase
|
||||
from agent_framework.openai._shared import OpenAIModelTypes
|
||||
from openai.lib.azure import AsyncAzureADTokenProvider, AsyncAzureOpenAI
|
||||
from openai.types.chat.chat_completion import ChatCompletion, Choice
|
||||
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk
|
||||
@@ -59,25 +59,25 @@ class AzureChatClient(AzureOpenAIConfigBase, OpenAIChatClientBase):
|
||||
"""Initialize an AzureChatCompletion service.
|
||||
|
||||
Args:
|
||||
api_key (str | None): The optional api key. If provided, will override the value in the
|
||||
api_key: The optional api key. If provided, will override the value in the
|
||||
env vars or .env file.
|
||||
deployment_name (str | None): The optional deployment. If provided, will override the value
|
||||
deployment_name: The optional deployment. If provided, will override the value
|
||||
(chat_deployment_name) in the env vars or .env file.
|
||||
endpoint (str | None): The optional deployment endpoint. If provided will override the value
|
||||
endpoint: The optional deployment endpoint. If provided will override the value
|
||||
in the env vars or .env file.
|
||||
base_url (str | None): The optional deployment base_url. If provided will override the value
|
||||
base_url: The optional deployment base_url. If provided will override the value
|
||||
in the env vars or .env file.
|
||||
api_version (str | None): The optional deployment api version. If provided will override the value
|
||||
api_version: The optional deployment api version. If provided will override the value
|
||||
in the env vars or .env file.
|
||||
ad_token (str | None): The Azure Active Directory token. (Optional)
|
||||
ad_token_provider (AsyncAzureADTokenProvider): The Azure Active Directory token provider. (Optional)
|
||||
token_endpoint (str | None): The token endpoint to request an Azure token. (Optional)
|
||||
default_headers (Mapping[str, str]): The default headers mapping of string keys to
|
||||
ad_token: The Azure Active Directory token. (Optional)
|
||||
ad_token_provider: The Azure Active Directory token provider. (Optional)
|
||||
token_endpoint: The token endpoint to request an Azure token. (Optional)
|
||||
default_headers: The default headers mapping of string keys to
|
||||
string values for HTTP requests. (Optional)
|
||||
async_client (AsyncAzureOpenAI | None): An existing client to use. (Optional)
|
||||
env_file_path (str | None): Use the environment settings file as a fallback to using env vars.
|
||||
env_file_encoding (str | None): The encoding of the environment settings file, defaults to 'utf-8'.
|
||||
instruction_role (str | None): The role to use for 'instruction' messages, for example, summarization
|
||||
async_client: An existing client to use. (Optional)
|
||||
env_file_path: Use the environment settings file as a fallback to using env vars.
|
||||
env_file_encoding: The encoding of the environment settings file, defaults to 'utf-8'.
|
||||
instruction_role: The role to use for 'instruction' messages, for example, summarization
|
||||
prompts could use `developer` or `system`. (Optional)
|
||||
"""
|
||||
try:
|
||||
@@ -120,7 +120,7 @@ class AzureChatClient(AzureOpenAIConfigBase, OpenAIChatClientBase):
|
||||
Args:
|
||||
settings: A dictionary of settings for the service.
|
||||
should contain keys: service_id, and optionally:
|
||||
ad_auth, ad_token_provider, default_headers
|
||||
ad_auth, ad_token_provider, default_headers
|
||||
"""
|
||||
return AzureChatClient(
|
||||
api_key=settings.get("api_key"),
|
||||
@@ -193,7 +193,7 @@ class AzureChatClient(AzureOpenAIConfigBase, OpenAIChatClientBase):
|
||||
return None # pragma: no cover
|
||||
|
||||
@staticmethod
|
||||
def split_message(message: "ChatResponse") -> ChatResponse:
|
||||
def _split_message(message: "ChatResponse") -> ChatResponse:
|
||||
"""Split an Azure On Your Data response into separate ChatMessages within the ChatResponse.
|
||||
|
||||
If the message does not have three contents, and those three are one each of:
|
||||
|
||||
@@ -6,9 +6,9 @@ from collections.abc import Awaitable, Callable, Mapping
|
||||
from copy import copy
|
||||
from typing import Any, ClassVar, Final
|
||||
|
||||
from agent_framework import AFBaseSettings, HttpsUrl
|
||||
from agent_framework._pydantic import AFBaseSettings, HttpsUrl
|
||||
from agent_framework.exceptions import ServiceInitializationError
|
||||
from agent_framework.openai import OpenAIHandler, OpenAIModelTypes
|
||||
from agent_framework.openai._shared import OpenAIHandler, OpenAIModelTypes
|
||||
from agent_framework.telemetry import USER_AGENT_KEY
|
||||
from openai.lib.azure import AsyncAzureOpenAI
|
||||
from pydantic import ConfigDict, SecretStr, validate_call
|
||||
@@ -30,75 +30,79 @@ class AzureOpenAISettings(AFBaseSettings):
|
||||
with the encoding 'utf-8'. If the settings are not found in the .env file, the settings
|
||||
are ignored; however, validation will fail alerting that the settings are missing.
|
||||
|
||||
Optional settings for prefix 'AZURE_OPENAI_' are:
|
||||
- chat_deployment_name: str - The name of the Azure Chat deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_CHAT_DEPLOYMENT_NAME)
|
||||
- responses_deployment_name: str - The name of the Azure Responses deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME)
|
||||
- text_deployment_name: str - The name of the Azure Text deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_TEXT_DEPLOYMENT_NAME)
|
||||
- embedding_deployment_name: str - The name of the Azure Embedding deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME)
|
||||
- text_to_image_deployment_name: str - The name of the Azure Text to Image deployment. This
|
||||
value will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME)
|
||||
- audio_to_text_deployment_name: str - The name of the Azure Audio to Text deployment. This
|
||||
value will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_AUDIO_TO_TEXT_DEPLOYMENT_NAME)
|
||||
- text_to_audio_deployment_name: str - The name of the Azure Text to Audio deployment. This
|
||||
value will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_TEXT_TO_AUDIO_DEPLOYMENT_NAME)
|
||||
- realtime_deployment_name: str - The name of the Azure Realtime deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_REALTIME_DEPLOYMENT_NAME)
|
||||
- api_key: SecretStr - The API key for the Azure deployment. This value can be
|
||||
found in the Keys & Endpoint section when examining your resource in
|
||||
the Azure portal. You can use either KEY1 or KEY2.
|
||||
(Env var AZURE_OPENAI_API_KEY)
|
||||
- base_url: HttpsUrl | None - base_url: The url of the Azure deployment. This value
|
||||
can be found in the Keys & Endpoint section when examining
|
||||
your resource from the Azure portal, the base_url consists of the endpoint,
|
||||
followed by /openai/deployments/{deployment_name}/,
|
||||
use endpoint if you only want to supply the endpoint.
|
||||
(Env var AZURE_OPENAI_BASE_URL)
|
||||
- endpoint: HttpsUrl - The endpoint of the Azure deployment. This value
|
||||
can be found in the Keys & Endpoint section when examining
|
||||
your resource from the Azure portal, the endpoint should end in openai.azure.com.
|
||||
If both base_url and endpoint are supplied, base_url will be used.
|
||||
(Env var AZURE_OPENAI_ENDPOINT)
|
||||
- api_version: str | None - The API version to use. The default value is "2024-02-01".
|
||||
(Env var AZURE_OPENAI_API_VERSION)
|
||||
- token_endpoint: str - The token endpoint to use to retrieve the authentication token.
|
||||
The default value is "https://cognitiveservices.azure.com/.default".
|
||||
(Env var AZURE_OPENAI_TOKEN_ENDPOINT)
|
||||
Attributes:
|
||||
chat_deployment_name: The name of the Azure Chat deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_CHAT_DEPLOYMENT_NAME)
|
||||
responses_deployment_name: The name of the Azure Responses deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME)
|
||||
text_deployment_name: The name of the Azure Text deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_TEXT_DEPLOYMENT_NAME)
|
||||
embedding_deployment_name: The name of the Azure Embedding deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME)
|
||||
text_to_image_deployment_name: The name of the Azure Text to Image deployment. This
|
||||
value will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_TEXT_TO_IMAGE_DEPLOYMENT_NAME)
|
||||
audio_to_text_deployment_name: The name of the Azure Audio to Text deployment. This
|
||||
value will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_AUDIO_TO_TEXT_DEPLOYMENT_NAME)
|
||||
text_to_audio_deployment_name: The name of the Azure Text to Audio deployment. This
|
||||
value will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_TEXT_TO_AUDIO_DEPLOYMENT_NAME)
|
||||
realtime_deployment_name: The name of the Azure Realtime deployment. This value
|
||||
will correspond to the custom name you chose for your deployment
|
||||
when you deployed a model. This value can be found under
|
||||
Resource Management > Deployments in the Azure portal or, alternatively,
|
||||
under Management > Deployments in Azure AI Foundry.
|
||||
(Env var AZURE_OPENAI_REALTIME_DEPLOYMENT_NAME)
|
||||
api_key: The API key for the Azure deployment. This value can be
|
||||
found in the Keys & Endpoint section when examining your resource in
|
||||
the Azure portal. You can use either KEY1 or KEY2.
|
||||
(Env var AZURE_OPENAI_API_KEY)
|
||||
base_url: The url of the Azure deployment. This value
|
||||
can be found in the Keys & Endpoint section when examining
|
||||
your resource from the Azure portal, the base_url consists of the endpoint,
|
||||
followed by /openai/deployments/{deployment_name}/,
|
||||
use endpoint if you only want to supply the endpoint.
|
||||
(Env var AZURE_OPENAI_BASE_URL)
|
||||
endpoint: The endpoint of the Azure deployment. This value
|
||||
can be found in the Keys & Endpoint section when examining
|
||||
your resource from the Azure portal, the endpoint should end in openai.azure.com.
|
||||
If both base_url and endpoint are supplied, base_url will be used.
|
||||
(Env var AZURE_OPENAI_ENDPOINT)
|
||||
api_version: The API version to use. The default value is "2024-02-01".
|
||||
(Env var AZURE_OPENAI_API_VERSION)
|
||||
token_endpoint: The token endpoint to use to retrieve the authentication token.
|
||||
The default value is "https://cognitiveservices.azure.com/.default".
|
||||
(Env var AZURE_OPENAI_TOKEN_ENDPOINT)
|
||||
|
||||
Parameters:
|
||||
env_file_path: The path to the .env file to load settings from.
|
||||
env_file_encoding: The encoding of the .env file, defaults to 'utf-8'.
|
||||
"""
|
||||
|
||||
env_prefix: ClassVar[str] = "AZURE_OPENAI_"
|
||||
|
||||
@@ -476,7 +476,7 @@ async def test_azure_on_your_data_split_messages(
|
||||
content = await azure_chat_client.get_response(
|
||||
messages=messages_in,
|
||||
)
|
||||
message = azure_chat_client.split_message(content)
|
||||
message = azure_chat_client._split_message(content)
|
||||
assert len(content.messages) == 1
|
||||
assert len(content.messages[0].contents) == 3
|
||||
assert isinstance(content.messages[0].contents[0], FunctionCallContent)
|
||||
|
||||
@@ -7,7 +7,6 @@ from collections.abc import AsyncIterable, MutableMapping, MutableSequence
|
||||
from typing import Any, ClassVar
|
||||
|
||||
from agent_framework import (
|
||||
AFBaseSettings,
|
||||
AIContents,
|
||||
AIFunction,
|
||||
ChatClientBase,
|
||||
@@ -28,6 +27,7 @@ from agent_framework import (
|
||||
use_tool_calling,
|
||||
)
|
||||
from agent_framework._clients import ai_function_to_json_schema_spec
|
||||
from agent_framework._pydantic import AFBaseSettings
|
||||
from agent_framework.exceptions import ServiceInitializationError
|
||||
from agent_framework.telemetry import use_telemetry
|
||||
from azure.ai.agents.models import (
|
||||
@@ -74,14 +74,16 @@ class FoundrySettings(AFBaseSettings):
|
||||
with the encoding 'utf-8'. If the settings are not found in the .env file, the settings
|
||||
are ignored; however, validation will fail alerting that the settings are missing.
|
||||
|
||||
Optional settings for prefix 'FOUNDRY_' are:
|
||||
- project_endpoint: str | None - The Azure AI Foundry project endpoint URL.
|
||||
(Env var FOUNDRY_PROJECT_ENDPOINT)
|
||||
- model_deployment_name: str | None - The name of the model deployment to use.
|
||||
(Env var FOUNDRY_MODEL_DEPLOYMENT_NAME)
|
||||
- agent_name: str | None - Default name for automatically created agents.
|
||||
(Env var FOUNDRY_AGENT_NAME)
|
||||
- env_file_path: str | None - if provided, the .env settings are read from this file path location
|
||||
Attributes:
|
||||
project_endpoint: The Azure AI Foundry project endpoint URL.
|
||||
(Env var FOUNDRY_PROJECT_ENDPOINT)
|
||||
model_deployment_name: The name of the model deployment to use.
|
||||
(Env var FOUNDRY_MODEL_DEPLOYMENT_NAME)
|
||||
agent_name: Default name for automatically created agents.
|
||||
(Env var FOUNDRY_AGENT_NAME)
|
||||
Parameters:
|
||||
env_file_path: If provided, the .env settings are read from this file path location.
|
||||
env_file_encoding: The encoding of the .env file, defaults to 'utf-8'.
|
||||
"""
|
||||
|
||||
env_prefix: ClassVar[str] = "FOUNDRY_"
|
||||
|
||||
@@ -11,6 +11,5 @@ except importlib.metadata.PackageNotFoundError:
|
||||
from ._agents import * # noqa: F403
|
||||
from ._clients import * # noqa: F403
|
||||
from ._logging import * # noqa: F403
|
||||
from ._pydantic import * # noqa: F403
|
||||
from ._tools import * # noqa: F403
|
||||
from ._types import * # noqa: F403
|
||||
|
||||
@@ -225,22 +225,21 @@ def use_tool_calling(cls: type[TChatClientBase]) -> type[TChatClientBase]:
|
||||
|
||||
Remarks:
|
||||
This only works on classes that derive from ChatClientBase
|
||||
and the _inner_get_response
|
||||
and _inner_get_streaming_response methods.
|
||||
It also sets a __maximum_iterations_per_request attribute on the class.
|
||||
and the `_inner_get_response`
|
||||
and `_inner_get_streaming_response` methods.
|
||||
It also sets a `__maximum_iterations_per_request` attribute on the class.
|
||||
if you want to expose this to end_users, do a version of this:
|
||||
|
||||
```python
|
||||
@use_tool_calling
|
||||
class MyChatClient(ChatClientBase):
|
||||
@property
|
||||
|
||||
def maximum_iterations_per_request(self):
|
||||
return getattr(self, "__maximum_iterations_per_request", 10)
|
||||
|
||||
@maximum_iterations_per_request.setter
|
||||
|
||||
def maximum_iterations_per_request(self, value: int) -> None:
|
||||
setattr(self, "__maximum_iterations_per_request", value)
|
||||
```
|
||||
|
||||
"""
|
||||
setattr(cls, "__maximum_iterations_per_request", 10)
|
||||
|
||||
|
||||
@@ -29,11 +29,11 @@ class AFBaseSettings(BaseSettings):
|
||||
|
||||
In the case where a value is specified for the same Settings field in multiple ways,
|
||||
the selected value is determined as follows (in descending order of priority):
|
||||
- Arguments passed to the Settings class initializer.
|
||||
- Environment variables, e.g. my_prefix_special_function as described above.
|
||||
- Variables loaded from a dotenv (.env) file.
|
||||
- Variables loaded from the secrets directory.
|
||||
- The default field values for the Settings model.
|
||||
- Arguments passed to the Settings class initializer.
|
||||
- Environment variables, e.g. my_prefix_special_function as described above.
|
||||
- Variables loaded from a dotenv (.env) file.
|
||||
- Variables loaded from the secrets directory.
|
||||
- The default field values for the Settings model.
|
||||
"""
|
||||
|
||||
env_prefix: ClassVar[str] = ""
|
||||
|
||||
@@ -146,15 +146,17 @@ def ai_function(
|
||||
) -> AIFunction[Any, ReturnT]:
|
||||
"""Decorate a function to turn it into a AIFunction that can be passed to models and executed automatically.
|
||||
|
||||
Remarks:
|
||||
In order to add descriptions to parameters, use:
|
||||
This function will create a Pydantic model from the function's signature,
|
||||
which will be used to validate the arguments passed to the function.
|
||||
And will be used to generate the JSON schema for the function's parameters.
|
||||
In order to add descriptions to parameters, in your function signature,
|
||||
use the `Annotated` type from `typing` and the `Field` class from `pydantic`:
|
||||
|
||||
```python
|
||||
from typing import Annotated
|
||||
from pydantic import Field
|
||||
from typing import Annotated
|
||||
|
||||
arg: Annotated[<type>, Field(description="<description>")]
|
||||
```
|
||||
from pydantic import Field
|
||||
|
||||
<field_name>: Annotated[<type>, Field(description="<description>")]
|
||||
|
||||
Args:
|
||||
func: The function to wrap. If None, returns a decorator.
|
||||
|
||||
@@ -312,9 +312,7 @@ class AIContent(AFBaseModel):
|
||||
|
||||
type: Literal["ai"] = "ai"
|
||||
additional_properties: dict[str, Any] | None = None
|
||||
"""Additional properties for the content."""
|
||||
raw_representation: Any | None = Field(default=None, repr=False)
|
||||
"""The raw representation of the content from an underlying implementation."""
|
||||
|
||||
|
||||
class TextContent(AIContent):
|
||||
@@ -367,7 +365,9 @@ class TextReasoningContent(AIContent):
|
||||
raw_representation: Optional raw representation of the content.
|
||||
|
||||
|
||||
""" # TODO(): Should we merge these two classes, and use a property to distinguish them?
|
||||
"""
|
||||
|
||||
# TODO(eavanvalkenburg): Should we merge these two classes, and use a property to distinguish them?
|
||||
|
||||
text: str
|
||||
type: Literal["text_reasoning"] = "text_reasoning" # type: ignore[assignment]
|
||||
@@ -536,9 +536,7 @@ class UriContent(AIContent):
|
||||
|
||||
type: Literal["uri"] = "uri" # type: ignore[assignment]
|
||||
uri: str
|
||||
"""The URI of the content, e.g., 'https://example.com/image.png'."""
|
||||
media_type: str
|
||||
"""The media type of the content, e.g., 'image/png', 'application/json', etc."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -604,11 +602,8 @@ class ErrorContent(AIContent):
|
||||
|
||||
type: Literal["error"] = "error" # type: ignore[assignment]
|
||||
error_code: str | None = None
|
||||
"""The error code associated with the error."""
|
||||
details: str | None = None
|
||||
"""Additional details about the error."""
|
||||
message: str | None
|
||||
"""The error message."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -660,13 +655,9 @@ class FunctionCallContent(AIContent):
|
||||
|
||||
type: Literal["function_call"] = "function_call" # type: ignore[assignment]
|
||||
call_id: str
|
||||
"""The function call identifier."""
|
||||
name: str
|
||||
"""The name of the function requested."""
|
||||
arguments: str | dict[str, Any | None] | None = None
|
||||
"""The arguments requested to be provided to the function."""
|
||||
exception: Exception | None = None
|
||||
"""Any exception that occurred while mapping the original function call data to this representation."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -753,11 +744,8 @@ class FunctionResultContent(AIContent):
|
||||
|
||||
type: Literal["function_result"] = "function_result" # type: ignore[assignment]
|
||||
call_id: str
|
||||
"""The identifier of the function call for which this is the result."""
|
||||
result: Any | None = None
|
||||
"""The result of the function call, or a generic error message if the function call failed."""
|
||||
exception: Exception | None = None
|
||||
"""An exception that occurred if the function call failed."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -802,7 +790,6 @@ class UsageContent(AIContent):
|
||||
|
||||
type: Literal["usage"] = "usage" # type: ignore[assignment]
|
||||
details: UsageDetails
|
||||
"""The usage information."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -812,14 +799,7 @@ class UsageContent(AIContent):
|
||||
raw_representation: Any | None = None,
|
||||
**kwargs: Any,
|
||||
) -> None:
|
||||
"""Initializes a UsageContent instance.
|
||||
|
||||
Args:
|
||||
details: The usage information.
|
||||
additional_properties: Optional additional properties associated with the content.
|
||||
raw_representation: Optional raw representation of the content.
|
||||
**kwargs: Any additional keyword arguments.
|
||||
"""
|
||||
"""Initializes a UsageContent instance."""
|
||||
super().__init__(
|
||||
details=details, # type: ignore[reportCallIssue]
|
||||
raw_representation=raw_representation,
|
||||
@@ -890,15 +870,6 @@ class ChatFinishReason(AFBaseModel):
|
||||
|
||||
Attributes:
|
||||
value: The string representation of the finish reason.
|
||||
|
||||
Properties:
|
||||
CONTENT_FILTER: The model filtered content, whether for safety, prohibited content, sensitive content,
|
||||
or other such issues.
|
||||
LENGTH: The model reached the maximum length allowed for the request and/or response (typically in
|
||||
terms of tokens).
|
||||
STOP: The model encountered a natural stop point or provided stop sequence.
|
||||
TOOL_CALLS: The model requested the use of a tool that was defined in the request.
|
||||
|
||||
"""
|
||||
|
||||
value: str
|
||||
|
||||
@@ -7,6 +7,7 @@ PACKAGE_NAME = "agent_framework_azure"
|
||||
PACKAGE_EXTRA = "azure"
|
||||
_IMPORTS = [
|
||||
"AzureChatClient",
|
||||
"AzureOpenAISettings",
|
||||
"get_entra_auth_token",
|
||||
"__version__",
|
||||
]
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
from agent_framework_azure import (
|
||||
AzureChatClient,
|
||||
AzureOpenAISettings,
|
||||
__version__,
|
||||
get_entra_auth_token,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
"AzureChatClient",
|
||||
"AzureOpenAISettings",
|
||||
"__version__",
|
||||
"get_entra_auth_token",
|
||||
]
|
||||
|
||||
@@ -5,7 +5,7 @@ from typing import Any
|
||||
|
||||
PACKAGE_NAME = "agent_framework_foundry"
|
||||
PACKAGE_EXTRA = "foundry"
|
||||
_IMPORTS = ["__version__", "FoundryChatClient"]
|
||||
_IMPORTS = ["__version__", "FoundryChatClient", "FoundrySettings"]
|
||||
|
||||
|
||||
def __getattr__(name: str) -> Any:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
from agent_framework_foundry import FoundryChatClient, __version__
|
||||
from agent_framework_foundry import FoundryChatClient, FoundrySettings, __version__
|
||||
|
||||
__all__ = ["FoundryChatClient", "__version__"]
|
||||
__all__ = ["FoundryChatClient", "FoundrySettings", "__version__"]
|
||||
|
||||
@@ -286,26 +286,27 @@ class OpenAIChatClient(OpenAIConfigBase, OpenAIChatClientBase):
|
||||
org_id: str | None = None,
|
||||
default_headers: Mapping[str, str] | None = None,
|
||||
async_client: AsyncOpenAI | None = None,
|
||||
instruction_role: str | None = None,
|
||||
env_file_path: str | None = None,
|
||||
env_file_encoding: str | None = None,
|
||||
instruction_role: str | None = None,
|
||||
) -> None:
|
||||
"""Initialize an OpenAIChatCompletion service.
|
||||
|
||||
Args:
|
||||
ai_model_id (str): OpenAI model name, see
|
||||
ai_model_id: OpenAI model name, see
|
||||
https://platform.openai.com/docs/models
|
||||
api_key (str | None): The optional API key to use. If provided will override,
|
||||
api_key: The optional API key to use. If provided will override,
|
||||
the env vars or .env file value.
|
||||
org_id (str | None): The optional org ID to use. If provided will override,
|
||||
org_id: The optional org ID to use. If provided will override,
|
||||
the env vars or .env file value.
|
||||
default_headers: The default headers mapping of string keys to
|
||||
string values for HTTP requests. (Optional)
|
||||
async_client (Optional[AsyncOpenAI]): An existing client to use. (Optional)
|
||||
env_file_path (str | None): Use the environment settings file as a fallback
|
||||
async_client: An existing client to use. (Optional)
|
||||
instruction_role: The role to use for 'instruction' messages, for example,
|
||||
"system" or "developer". If not provided, the default is "system".
|
||||
env_file_path: Use the environment settings file as a fallback
|
||||
to environment variables. (Optional)
|
||||
env_file_encoding (str | None): The encoding of the environment settings file. (Optional)
|
||||
instruction_role (str | None): The role to use for 'instruction' messages, for example,
|
||||
env_file_encoding: The encoding of the environment settings file. (Optional)
|
||||
"""
|
||||
try:
|
||||
openai_settings = OpenAISettings(
|
||||
|
||||
@@ -66,26 +66,27 @@ class OpenAIResponsesClient(OpenAIConfigBase, ChatClientBase, OpenAIHandler):
|
||||
org_id: str | None = None,
|
||||
default_headers: Mapping[str, str] | None = None,
|
||||
async_client: AsyncOpenAI | None = None,
|
||||
instruction_role: str | None = None,
|
||||
env_file_path: str | None = None,
|
||||
env_file_encoding: str | None = None,
|
||||
instruction_role: str | None = None,
|
||||
) -> None:
|
||||
"""Initialize an OpenAIChatCompletion service.
|
||||
|
||||
Args:
|
||||
ai_model_id (str): OpenAI model name, see
|
||||
ai_model_id: OpenAI model name, see
|
||||
https://platform.openai.com/docs/models
|
||||
api_key (str | None): The optional API key to use. If provided will override,
|
||||
api_key: The optional API key to use. If provided will override,
|
||||
the env vars or .env file value.
|
||||
org_id (str | None): The optional org ID to use. If provided will override,
|
||||
org_id: The optional org ID to use. If provided will override,
|
||||
the env vars or .env file value.
|
||||
default_headers: The default headers mapping of string keys to
|
||||
string values for HTTP requests. (Optional)
|
||||
async_client (Optional[AsyncOpenAI]): An existing client to use. (Optional)
|
||||
env_file_path (str | None): Use the environment settings file as a fallback
|
||||
async_client: An existing client to use. (Optional)
|
||||
instruction_role: The role to use for 'instruction' messages, for example,
|
||||
"system" or "developer". If not provided, the default is "system".
|
||||
env_file_path: Use the environment settings file as a fallback
|
||||
to environment variables. (Optional)
|
||||
env_file_encoding (str | None): The encoding of the environment settings file. (Optional)
|
||||
instruction_role (str | None): The role to use for 'instruction' messages, for example,
|
||||
env_file_encoding: The encoding of the environment settings file. (Optional)
|
||||
"""
|
||||
try:
|
||||
openai_settings = OpenAISettings(
|
||||
|
||||
@@ -54,43 +54,44 @@ OPTION_TYPE = Union[
|
||||
|
||||
|
||||
__all__ = [
|
||||
"OpenAIHandler",
|
||||
"OpenAIModelTypes",
|
||||
"OpenAISettings",
|
||||
]
|
||||
|
||||
|
||||
class OpenAISettings(AFBaseSettings):
|
||||
"""OpenAI model settings.
|
||||
"""OpenAI environment settings.
|
||||
|
||||
The settings are first loaded from environment variables with the prefix 'OPENAI_'.
|
||||
If the environment variables are not found, the settings can be loaded from a .env file with the
|
||||
encoding 'utf-8'. If the settings are not found in the .env file, the settings are ignored;
|
||||
however, validation will fail alerting that the settings are missing.
|
||||
|
||||
Optional settings for prefix 'OPENAI_' are:
|
||||
- api_key: SecretStr - OpenAI API key, see https://platform.openai.com/account/api-keys
|
||||
(Env var OPENAI_API_KEY)
|
||||
- org_id: str | None - This is usually optional unless your account belongs to multiple organizations.
|
||||
(Env var OPENAI_ORG_ID)
|
||||
- chat_model_id: str | None - The OpenAI chat model ID to use, for example, gpt-3.5-turbo or gpt-4.
|
||||
(Env var OPENAI_CHAT_MODEL_ID)
|
||||
- responses_model_id: str | None - The OpenAI responses model ID to use, for example, gpt-4o or o1.
|
||||
(Env var OPENAI_RESPONSES_MODEL_ID)
|
||||
- text_model_id: str | None - The OpenAI text model ID to use, for example, gpt-3.5-turbo-instruct.
|
||||
(Env var OPENAI_TEXT_MODEL_ID)
|
||||
- embedding_model_id: str | None - The OpenAI embedding model ID to use, for example, text-embedding-ada-002.
|
||||
(Env var OPENAI_EMBEDDING_MODEL_ID)
|
||||
- text_to_image_model_id: str | None - The OpenAI text to image model ID to use, for example, dall-e-3.
|
||||
(Env var OPENAI_TEXT_TO_IMAGE_MODEL_ID)
|
||||
- audio_to_text_model_id: str | None - The OpenAI audio to text model ID to use, for example, whisper-1.
|
||||
(Env var OPENAI_AUDIO_TO_TEXT_MODEL_ID)
|
||||
- text_to_audio_model_id: str | None - The OpenAI text to audio model ID to use, for example, jukebox-1.
|
||||
(Env var OPENAI_TEXT_TO_AUDIO_MODEL_ID)
|
||||
- realtime_model_id: str | None - The OpenAI realtime model ID to use,
|
||||
for example, gpt-4o-realtime-preview-2024-12-17.
|
||||
(Env var OPENAI_REALTIME_MODEL_ID)
|
||||
- env_file_path: str | None - if provided, the .env settings are read from this file path location
|
||||
Attributes:
|
||||
api_key: OpenAI API key, see https://platform.openai.com/account/api-keys
|
||||
(Env var OPENAI_API_KEY)
|
||||
org_id: This is usually optional unless your account belongs to multiple organizations.
|
||||
(Env var OPENAI_ORG_ID)
|
||||
chat_model_id: The OpenAI chat model ID to use, for example, gpt-3.5-turbo or gpt-4.
|
||||
(Env var OPENAI_CHAT_MODEL_ID)
|
||||
responses_model_id: The OpenAI responses model ID to use, for example, gpt-4o or o1.
|
||||
(Env var OPENAI_RESPONSES_MODEL_ID)
|
||||
text_model_id: The OpenAI text model ID to use, for example, gpt-3.5-turbo-instruct.
|
||||
(Env var OPENAI_TEXT_MODEL_ID)
|
||||
embedding_model_id: The OpenAI embedding model ID to use, for example, text-embedding-ada-002.
|
||||
(Env var OPENAI_EMBEDDING_MODEL_ID)
|
||||
text_to_image_model_id: The OpenAI text to image model ID to use, for example, dall-e-3.
|
||||
(Env var OPENAI_TEXT_TO_IMAGE_MODEL_ID)
|
||||
audio_to_text_model_id: The OpenAI audio to text model ID to use, for example, whisper-1.
|
||||
(Env var OPENAI_AUDIO_TO_TEXT_MODEL_ID)
|
||||
text_to_audio_model_id: The OpenAI text to audio model ID to use, for example, jukebox-1.
|
||||
(Env var OPENAI_TEXT_TO_AUDIO_MODEL_ID)
|
||||
realtime_model_id: The OpenAI realtime model ID to use,
|
||||
for example, gpt-4o-realtime-preview-2024-12-17.
|
||||
(Env var OPENAI_REALTIME_MODEL_ID)
|
||||
|
||||
Parameters:
|
||||
env_file_path: The path to the .env file to load settings from.
|
||||
env_file_encoding: The encoding of the .env file, defaults to 'utf-8'.
|
||||
"""
|
||||
|
||||
env_prefix: ClassVar[str] = "OPENAI_"
|
||||
|
||||
Reference in New Issue
Block a user