Override build_chat_completion_params for Mistral

This commit is contained in:
Mark Backman
2025-08-14 10:32:18 -04:00
parent b7ae2989ac
commit 7f0494aa04

View File

@@ -145,20 +145,15 @@ class MistralLLMService(OpenAILLMService):
if calls_to_execute: if calls_to_execute:
await super().run_function_calls(calls_to_execute) await super().run_function_calls(calls_to_execute)
async def get_chat_completions( def build_chat_completion_params(
self, context: OpenAILLMContext, messages: List[ChatCompletionMessageParam] self, context: OpenAILLMContext, messages: List[ChatCompletionMessageParam]
) -> AsyncStream[ChatCompletionChunk]: ) -> dict:
"""Create a streaming chat completion using Mistral's API. """Build parameters for Mistral chat completion request.
Args: Handles Mistral-specific requirements including:
context: The context object containing tools configuration - Assistant message prefix requirement for API compatibility
and other settings for the chat completion. - Parameter mapping (random_seed instead of seed)
messages: The list of messages comprising - Core completion settings
the conversation history and current request.
Returns:
A streaming response of chat completion
chunks that can be processed asynchronously.
""" """
# Apply Mistral's assistant prefix requirement for API compatibility # Apply Mistral's assistant prefix requirement for API compatibility
fixed_messages = self._apply_mistral_assistant_prefix(messages) fixed_messages = self._apply_mistral_assistant_prefix(messages)
@@ -184,5 +179,4 @@ class MistralLLMService(OpenAILLMService):
# Add any extra parameters # Add any extra parameters
params.update(self._settings["extra"]) params.update(self._settings["extra"])
chunks = await self._client.chat.completions.create(**params) return params
return chunks