Python: added generic types to ChatOptions and ChatResponse/AgentResponse for Response Format (#3305)

* added generic types to ChatOptions and ChatResponse/AgentResponse for response format

* fix typevar import

* fix for older python versions

* fix missing import

* fixed imports

* fixed mypy

* mypy fix
This commit is contained in:
Eduard van Valkenburg
2026-01-28 22:23:02 +01:00
committed by GitHub
Unverified
parent 1f8463f9bb
commit 1226828ec2
42 changed files with 486 additions and 281 deletions
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft. All rights reserved.
import sys
from typing import Any, ClassVar, Generic, TypedDict
from typing import Any, ClassVar, Generic
from agent_framework import ChatOptions, use_chat_middleware, use_function_invocation
from agent_framework._pydantic import AFBaseSettings
@@ -11,12 +11,16 @@ from agent_framework.openai._chat_client import OpenAIBaseChatClient
from foundry_local import FoundryLocalManager
from foundry_local.models import DeviceType
from openai import AsyncOpenAI
from pydantic import BaseModel
if sys.version_info >= (3, 13):
from typing import TypeVar # type: ignore # pragma: no cover
else:
from typing_extensions import TypeVar # type: ignore # pragma: no cover
if sys.version_info >= (3, 11):
from typing import TypedDict # type: ignore # pragma: no cover
else:
from typing_extensions import TypedDict # type: ignore # pragma: no cover
__all__ = [
"FoundryLocalChatOptions",
@@ -24,11 +28,13 @@ __all__ = [
"FoundryLocalSettings",
]
TResponseModel = TypeVar("TResponseModel", bound=BaseModel | None, default=None)
# region Foundry Local Chat Options TypedDict
class FoundryLocalChatOptions(ChatOptions, total=False):
class FoundryLocalChatOptions(ChatOptions[TResponseModel], Generic[TResponseModel], total=False):
"""Azure Foundry Local (local model deployment) chat options dict.
Extends base ChatOptions for local model inference via Foundry Local.