Skip to content

Commit

Permalink
Cache mistral models
Browse files Browse the repository at this point in the history
ashpreetbedi committed Jan 30, 2025
1 parent 8ec1a33 commit 9ee3a60
Showing 4 changed files with 19 additions and 9 deletions.
13 changes: 13 additions & 0 deletions cookbook/models/mistral/mistral_small.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Run `pip install duckduckgo-search` to install dependencies."""

from agno.agent import Agent
from agno.models.mistral import MistralChat
from agno.tools.duckduckgo import DuckDuckGoTools

agent = Agent(
model=MistralChat(id="mistral-small-latest"),
tools=[DuckDuckGoTools()],
show_tool_calls=True,
markdown=True,
)
agent.print_response("Whats happening in France?", stream=True)
2 changes: 0 additions & 2 deletions cookbook/models/mistral/tool_use.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Run `pip install duckduckgo-search` to install dependencies."""

import os

from agno.agent import Agent
from agno.models.mistral import MistralChat
from agno.tools.duckduckgo import DuckDuckGoTools
11 changes: 5 additions & 6 deletions libs/agno/agno/models/mistral/mistral.py
Original file line number Diff line number Diff line change
@@ -96,7 +96,8 @@ def client(self) -> MistralClient:
_client_params["timeout"] = self.timeout
if self.client_params:
_client_params.update(self.client_params)
return MistralClient(**_client_params)
self.mistral_client = MistralClient(**_client_params)
return self.mistral_client

@property
def api_kwargs(self) -> Dict[str, Any]:
@@ -181,10 +182,9 @@ def invoke(self, messages: List[Message]) -> ChatCompletionResponse:
ChatCompletionResponse: The response from the model.
"""
mistral_messages = self._prepare_messages(messages)
logger.debug(f"Mistral messages: {mistral_messages}")
response = self.client.chat.complete(
messages=mistral_messages,
model=self.id,
messages=mistral_messages,
**self.api_kwargs,
)
if response is None:
@@ -202,10 +202,9 @@ def invoke_stream(self, messages: List[Message]) -> Iterator[Any]:
Iterator[Any]: The streamed response.
"""
mistral_messages = self._prepare_messages(messages)
logger.debug(f"Mistral messages sending to stream endpoint: {mistral_messages}")
response = self.client.chat.stream(
messages=mistral_messages,
model=self.id,
messages=mistral_messages,
**self.api_kwargs,
)
if response is None:
@@ -358,7 +357,7 @@ def response(self, messages: List[Message]) -> ModelResponse:
assistant_message.log()

# -*- Parse and run tool calls
logger.debug(f"Functions: {self._functions}")
# logger.debug(f"Functions: {self._functions}")

# -*- Handle tool calls
if self._handle_tool_calls(assistant_message, messages, model_response):
2 changes: 1 addition & 1 deletion libs/agno/agno/playground/settings.py
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ def set_cors_origin_list(cls, cors_origin_list):
"https://agno.com",
"https://www.agno.com",
"https://app.agno.com",
"https://app-stg.agno.com"
"https://app-stg.agno.com",
]
)

0 comments on commit 9ee3a60

Please sign in to comment.