mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
Python : CQ MyPy Fix for MistralAI Connector (#7182)
### Motivation and Context 1. I saw that you are having spikes regarding enabling MyPy 2. On ##7049 i had the Liskov Principle commented 3. In #7144 is saw how you plan to solve this so i decided to adjust the mistral connector to this ### Description The PR contains changes to be compliant to MyPy in Mistral AI Connector. Changes input Parameter for MistralAIChatCompletion from MistralAIPromptExecutionSettings to PromptExecutionSettings. Adding Test Cases for MistralAIPromptExecutionSettings and PromptExecutionSettings.  ### Tasks - [x] Changes input Parameter for Liskov - [x] Settings conversion - [x] Adjust TestCases to 100% ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Nico Möller <[email protected]> Co-authored-by: Evan Mattson <[email protected]>
This commit is contained in:
co-authored by
Nico Möller
Evan Mattson
parent
6a0077c5d3
commit
6944914017
+13
-4
@@ -20,6 +20,7 @@ from semantic_kernel.connectors.ai.mistral_ai.prompt_execution_settings.mistral_
|
||||
MistralAIChatPromptExecutionSettings,
|
||||
)
|
||||
from semantic_kernel.connectors.ai.mistral_ai.settings.mistral_ai_settings import MistralAISettings
|
||||
from semantic_kernel.connectors.ai.prompt_execution_settings import PromptExecutionSettings
|
||||
from semantic_kernel.contents.chat_history import ChatHistory
|
||||
from semantic_kernel.contents.chat_message_content import ChatMessageContent
|
||||
from semantic_kernel.contents.function_call_content import FunctionCallContent
|
||||
@@ -95,20 +96,24 @@ class MistralAIChatCompletion(ChatCompletionClientBase):
|
||||
async def get_chat_message_contents(
|
||||
self,
|
||||
chat_history: "ChatHistory",
|
||||
settings: "MistralAIChatPromptExecutionSettings", # type: ignore[override]
|
||||
settings: "PromptExecutionSettings",
|
||||
**kwargs: Any,
|
||||
) -> list["ChatMessageContent"]:
|
||||
"""Executes a chat completion request and returns the result.
|
||||
|
||||
Args:
|
||||
chat_history (ChatHistory): The chat history to use for the chat completion.
|
||||
settings (MistralAIChatPromptExecutionSettings): The settings to use
|
||||
settings (PromptExecutionSettings): The settings to use
|
||||
for the chat completion request.
|
||||
kwargs (Dict[str, Any]): The optional arguments.
|
||||
|
||||
Returns:
|
||||
List[ChatMessageContent]: The completion result(s).
|
||||
"""
|
||||
if not isinstance(settings, MistralAIChatPromptExecutionSettings):
|
||||
settings = self.get_prompt_execution_settings_from_settings(settings)
|
||||
assert isinstance(settings, MistralAIChatPromptExecutionSettings) # nosec
|
||||
|
||||
if not settings.ai_model_id:
|
||||
settings.ai_model_id = self.ai_model_id
|
||||
|
||||
@@ -128,14 +133,14 @@ class MistralAIChatCompletion(ChatCompletionClientBase):
|
||||
async def get_streaming_chat_message_contents(
|
||||
self,
|
||||
chat_history: ChatHistory,
|
||||
settings: MistralAIChatPromptExecutionSettings, # type: ignore[override]
|
||||
settings: PromptExecutionSettings,
|
||||
**kwargs: Any,
|
||||
) -> AsyncGenerator[list[StreamingChatMessageContent], Any]:
|
||||
"""Executes a streaming chat completion request and returns the result.
|
||||
|
||||
Args:
|
||||
chat_history (ChatHistory): The chat history to use for the chat completion.
|
||||
settings (MistralAIChatPromptExecutionSettings): The settings to use
|
||||
settings (PromptExecutionSettings): The settings to use
|
||||
for the chat completion request.
|
||||
kwargs (Dict[str, Any]): The optional arguments.
|
||||
|
||||
@@ -143,6 +148,10 @@ class MistralAIChatCompletion(ChatCompletionClientBase):
|
||||
List[StreamingChatMessageContent]: A stream of
|
||||
StreamingChatMessageContent when using Azure.
|
||||
"""
|
||||
if not isinstance(settings, MistralAIChatPromptExecutionSettings):
|
||||
settings = self.get_prompt_execution_settings_from_settings(settings)
|
||||
assert isinstance(settings, MistralAIChatPromptExecutionSettings) # nosec
|
||||
|
||||
if not settings.ai_model_id:
|
||||
settings.ai_model_id = self.ai_model_id
|
||||
|
||||
|
||||
Reference in New Issue
Block a user