mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Introducing Local MCP Servers (#389)
* mcp parts * mcp parts 2 * removed structured output in favor of handling in chatresponse, mcp as AITool and running samples * updated naming * fixed test
This commit is contained in:
committed by
GitHub
Unverified
parent
80b0920e58
commit
ad3d8171bf
@@ -144,7 +144,8 @@ class OpenAIAssistantsClient(OpenAIConfigBase, ChatClientBase):
|
||||
**kwargs: Any,
|
||||
) -> ChatResponse:
|
||||
return await ChatResponse.from_chat_response_generator(
|
||||
updates=self._inner_get_streaming_response(messages=messages, chat_options=chat_options, **kwargs)
|
||||
updates=self._inner_get_streaming_response(messages=messages, chat_options=chat_options, **kwargs),
|
||||
output_format_type=chat_options.response_format,
|
||||
)
|
||||
|
||||
async def _inner_get_streaming_response(
|
||||
|
||||
@@ -61,7 +61,9 @@ class OpenAIChatClientBase(OpenAIHandler, ChatClientBase):
|
||||
) -> ChatResponse:
|
||||
options_dict = self._prepare_options(messages, chat_options)
|
||||
try:
|
||||
return self._create_chat_response(await self.client.chat.completions.create(stream=False, **options_dict))
|
||||
return self._create_chat_response(
|
||||
await self.client.chat.completions.create(stream=False, **options_dict), chat_options
|
||||
)
|
||||
except BadRequestError as ex:
|
||||
if ex.code == "content_filter":
|
||||
raise OpenAIContentFilterException(
|
||||
@@ -143,7 +145,7 @@ class OpenAIChatClientBase(OpenAIHandler, ChatClientBase):
|
||||
options_dict["response_format"] = type_to_response_format_param(chat_options.response_format)
|
||||
return options_dict
|
||||
|
||||
def _create_chat_response(self, response: ChatCompletion) -> "ChatResponse":
|
||||
def _create_chat_response(self, response: ChatCompletion, chat_options: ChatOptions) -> "ChatResponse":
|
||||
"""Create a chat message content object from a choice."""
|
||||
response_metadata = self._get_metadata_from_chat_response(response)
|
||||
messages: list[ChatMessage] = []
|
||||
@@ -166,6 +168,7 @@ class OpenAIChatClientBase(OpenAIHandler, ChatClientBase):
|
||||
model_id=response.model,
|
||||
additional_properties=response_metadata,
|
||||
finish_reason=finish_reason,
|
||||
response_format=chat_options.response_format,
|
||||
)
|
||||
|
||||
def _create_chat_response_update(
|
||||
|
||||
@@ -44,7 +44,6 @@ from .._types import (
|
||||
FunctionCallContent,
|
||||
FunctionResultContent,
|
||||
HostedFileContent,
|
||||
StructuredResponse,
|
||||
TextContent,
|
||||
TextSpanRegion,
|
||||
UsageDetails,
|
||||
@@ -605,7 +604,8 @@ class OpenAIResponsesClientBase(OpenAIHandler, ChatClientBase):
|
||||
args["usage_details"] = usage_details
|
||||
if structured_response:
|
||||
args["value"] = structured_response
|
||||
return StructuredResponse(**args)
|
||||
elif chat_options.response_format:
|
||||
args["response_format"] = chat_options.response_format
|
||||
return ChatResponse(**args)
|
||||
|
||||
def _create_streaming_response_content(
|
||||
|
||||
Reference in New Issue
Block a user