Skip to content

Litellm Model

minisweagent.models.litellm_model

logger module-attribute

logger = getLogger('litellm_model')

LitellmModelConfig dataclass

LitellmModelConfig(
    model_name: str, model_kwargs: dict[str, Any] = dict()
)

model_name instance-attribute

model_name: str

model_kwargs class-attribute instance-attribute

model_kwargs: dict[str, Any] = field(default_factory=dict)

LitellmModel

LitellmModel(**kwargs)
Source code in src/minisweagent/models/litellm_model.py
26
27
28
29
def __init__(self, **kwargs):
    self.config = LitellmModelConfig(**kwargs)
    self.cost = 0.0
    self.n_calls = 0

config instance-attribute

config = LitellmModelConfig(**kwargs)

cost instance-attribute

cost = 0.0

n_calls instance-attribute

n_calls = 0

query

query(messages: list[dict[str, str]], **kwargs) -> dict
Source code in src/minisweagent/models/litellm_model.py
56
57
58
59
60
61
62
63
64
def query(self, messages: list[dict[str, str]], **kwargs) -> dict:
    response = self._query(messages, **kwargs)
    cost = litellm.cost_calculator.completion_cost(response)
    self.n_calls += 1
    self.cost += cost
    GLOBAL_MODEL_STATS.add(cost)
    return {
        "content": response.choices[0].message.content or "",  # type: ignore
    }