Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiteLLMModel - detect message flatenning based on model information #553

Merged
Merged
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
13 changes: 12 additions & 1 deletion src/smolagents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from copy import deepcopy
from dataclasses import asdict, dataclass
from enum import Enum
from functools import cached_property
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

from huggingface_hub import InferenceClient
Expand Down Expand Up @@ -676,6 +677,16 @@ def __init__(
self.api_key = api_key
self.custom_role_conversions = custom_role_conversions

@cached_property
def _flatten_messages_as_text(self):
import litellm

model_info: dict = litellm.get_model_info(self.model_id)
if model_info["litellm_provider"] == "ollama":
return model_info["key"] != "llava"

return False

def __call__(
self,
messages: List[Dict[str, str]],
Expand All @@ -695,7 +706,7 @@ def __call__(
api_base=self.api_base,
api_key=self.api_key,
convert_images_to_image_urls=True,
flatten_messages_as_text=self.model_id.startswith("ollama"),
flatten_messages_as_text=self._flatten_messages_as_text,
custom_role_conversions=self.custom_role_conversions,
**kwargs,
)
Expand Down