Skip to content

Commit 95e0041

Browse files
authored
add support for mistral api via litellm (#1356)
1 parent 38bbd10 commit 95e0041

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

guidance/models/experimental/_litellm.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ def _wrapped_completion(
2626
) -> Iterator["ChatCompletionChunk"]:
2727
"""Wrapped completion call within a context manager."""
2828
kwargs["stream"] = True # Ensure we are streaming here
29+
if logprobs:
30+
# only add logprobs if needed. Some EPs like Mistral does not allow logprobs
31+
kwargs["logprobs"] = logprobs
2932
stream_wrapper = self.router.completion(
3033
model=model,
3134
messages=messages,
32-
logprobs=logprobs,
3335
**kwargs,
3436
)
3537

@@ -58,7 +60,17 @@ def streaming_chat_completions(
5860

5961

6062
class LiteLLMInterpreter(BaseOpenAIInterpreter):
61-
SUPPORTED_ENDPOINT_TYPES = ["openai", "azure_ai", "azure", "gemini", "anthropic", "xai", "hosted_vllm", "groq"]
63+
SUPPORTED_ENDPOINT_TYPES = [
64+
"openai",
65+
"azure_ai",
66+
"azure",
67+
"gemini",
68+
"anthropic",
69+
"xai",
70+
"hosted_vllm",
71+
"groq",
72+
"mistral",
73+
]
6274

6375
def __init__(self, model_description: dict, **kwargs):
6476
try:
@@ -242,6 +254,10 @@ def _process_kwargs(self, **kwargs):
242254
kwargs.pop("top_k", None)
243255
kwargs.pop("min_p", None)
244256
kwargs.pop("repetition_penalty", None)
257+
if self.ep_type == "mistral":
258+
kwargs.pop("top_k", None)
259+
kwargs.pop("min_p", None)
260+
kwargs.pop("repetition_penalty", None)
245261

246262
return kwargs
247263

0 commit comments

Comments
 (0)