Sitelet https://github.com/microsoft/autogen/pull/8077/files
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Awaitable, Callable, Dict, List, Literal, Optional, Union
from typing import Any, Awaitable, Callable, Dict, List, Literal, Optional, Union

from autogen_core import ComponentModel
from autogen_core.models import ModelCapabilities, ModelInfo # type: ignore
Expand Down Expand Up @@ -57,6 +57,8 @@ class CreateArguments(TypedDict, total=False):
- 'low': Faster responses with less reasoning
- 'medium': Balanced reasoning and speed
- 'high': More thorough reasoning, may take longer"""
extra_body: Optional[Dict[str, Any]]
"""Additional vendor-specific or custom parameters to pass directly in the request body."""


AsyncAzureADTokenProvider = Callable[[], Union[str, Awaitable[str]]]
Expand Down Expand Up @@ -108,6 +110,7 @@ class CreateArgumentsConfigModel(BaseModel):
parallel_tool_calls: bool | None = None
# Controls the amount of effort the model uses for reasoning (reasoning models only)
reasoning_effort: Literal["minimal", "low", "medium", "high"] | None = None
extra_body: Dict[str, Any] | None = None


class BaseOpenAIClientConfigurationConfigModel(CreateArgumentsConfigModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3378,3 +3378,63 @@ async def test_reasoning_effort_validation() -> None:
}

ChatCompletionClient.load_component(config)


@pytest.mark.asyncio
async def test_extra_body_configuration_and_serialization() -> None:
"""Test extra_body parameter configuration, serialization, and deserialization."""
from autogen_core.models import ChatCompletionClient

# Test direct client initialization with extra_body
client = OpenAIChatCompletionClient(
model="gpt-4o",
api_key="fake_key",
extra_body={"enable_thinking": True, "custom_param": 123},
)
assert client._create_args["extra_body"] == {"enable_thinking": True, "custom_param": 123} # pyright: ignore[reportPrivateUsage]
assert client._raw_config["extra_body"] == {"enable_thinking": True, "custom_param": 123} # pyright: ignore[reportPrivateUsage]

# Test load_component with extra_body
config = {
"provider": "OpenAIChatCompletionClient",
"config": {
"model": "gpt-4o",
"api_key": "fake_key",
"extra_body": {"enable_thinking": True, "vendor_flag": "fast"},
},
}
loaded_client = ChatCompletionClient.load_component(config)
assert loaded_client._create_args["extra_body"] == {"enable_thinking": True, "vendor_flag": "fast"} # type: ignore[attr-defined] # pyright: ignore[reportPrivateUsage]
assert loaded_client._raw_config["extra_body"] == {"enable_thinking": True, "vendor_flag": "fast"} # type: ignore[attr-defined] # pyright: ignore[reportPrivateUsage]

# Test component dump payload inspection before reloading
dumped = client.dump_component()
assert dumped.config.extra_body == {"enable_thinking": True, "custom_param": 123}

# Test component dump and reload roundtrip
reloaded = OpenAIChatCompletionClient.load_component(dumped)
assert reloaded._create_args["extra_body"] == {"enable_thinking": True, "custom_param": 123} # pyright: ignore[reportPrivateUsage]
assert reloaded._raw_config["extra_body"] == {"enable_thinking": True, "custom_param": 123} # pyright: ignore[reportPrivateUsage]

# Verify the reloaded client's public dump matches original dump payload
reloaded_dumped = reloaded.dump_component()
assert reloaded_dumped.config.extra_body == {"enable_thinking": True, "custom_param": 123}

# Test AzureOpenAIChatCompletionClient dump and load roundtrip with extra_body
azure_client = AzureOpenAIChatCompletionClient(
model="gpt-4o",
azure_endpoint="https://fake.openai.azure.com/",
azure_deployment="gpt-4o-dep",
api_version="2024-06-01",
api_key="fake_key",
extra_body={"enable_thinking": True, "custom_param": 456},
)
assert azure_client._create_args["extra_body"] == {"enable_thinking": True, "custom_param": 456} # pyright: ignore[reportPrivateUsage]
azure_dumped = azure_client.dump_component()
assert azure_dumped.config.extra_body == {"enable_thinking": True, "custom_param": 456}

reloaded_azure = AzureOpenAIChatCompletionClient.load_component(azure_dumped)
assert reloaded_azure._create_args["extra_body"] == {"enable_thinking": True, "custom_param": 456} # pyright: ignore[reportPrivateUsage]
assert reloaded_azure.dump_component().config.extra_body == {"enable_thinking": True, "custom_param": 456}