-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump mistralai to > 1.0.0 in preparation for latest models such as Pi…
…xtral Related to #521
- Loading branch information
1 parent
7c1f6e3
commit 861f53c
Showing
27 changed files
with
387 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 11 additions & 4 deletions
15
examples/learn/calls/custom_client/mistral/base_message_param.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import os | ||
|
||
from mirascope.core import BaseMessageParam, mistral | ||
from mistralai.async_client import MistralAsyncClient | ||
from mistralai.client import MistralClient | ||
from mistralai import Mistral | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
def recommend_book(genre: str) -> list[BaseMessageParam]: | ||
return [BaseMessageParam(role="user", content=f"Recommend a {genre} book")] | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralAsyncClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
async def recommend_book_async(genre: str) -> list[BaseMessageParam]: | ||
return [BaseMessageParam(role="user", content=f"Recommend a {genre} book")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import os | ||
|
||
from mirascope.core import Messages, mistral | ||
from mistralai.async_client import MistralAsyncClient | ||
from mistralai.client import MistralClient | ||
from mistralai import Mistral | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
def recommend_book(genre: str) -> Messages.Type: | ||
return Messages.User(f"Recommend a {genre} book") | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralAsyncClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
async def recommend_book_async(genre: str) -> Messages.Type: | ||
return Messages.User(f"Recommend a {genre} book") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import os | ||
|
||
from mirascope.core import mistral | ||
from mistralai.async_client import MistralAsyncClient | ||
from mistralai.client import MistralClient | ||
from mistralai import Mistral | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
def recommend_book(genre: str) -> str: | ||
return f"Recommend a {genre} book" | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralAsyncClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
async def recommend_book_async(genre: str) -> str: | ||
return f"Recommend a {genre} book" |
15 changes: 11 additions & 4 deletions
15
examples/learn/calls/custom_client/mistral/string_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import os | ||
|
||
from mirascope.core import mistral, prompt_template | ||
from mistralai.async_client import MistralAsyncClient | ||
from mistralai.client import MistralClient | ||
from mistralai import Mistral | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
@prompt_template("Recommend a {genre} book") | ||
def recommend_book(genre: str): ... | ||
|
||
|
||
@mistral.call("mistral-large-latest", client=MistralAsyncClient()) | ||
@mistral.call( | ||
"mistral-large-latest", | ||
client=Mistral(api_key=os.environ.get("MISTRAL_API_KEY", "")), | ||
) | ||
@prompt_template("Recommend a {genre} book") | ||
async def recommend_book_async(genre: str): ... |
8 changes: 5 additions & 3 deletions
8
examples/learn/response_models/basic_usage/mistral/official_sdk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,35 @@ | ||
"""Utility for converting `BaseMessageParam` to `ChatMessage`.""" | ||
|
||
from mistralai.models.chat_completion import ChatMessage | ||
from mistralai.models import ( | ||
AssistantMessage, | ||
SystemMessage, | ||
ToolMessage, | ||
UserMessage, | ||
) | ||
|
||
from ...base import BaseMessageParam | ||
|
||
|
||
def convert_message_params( | ||
message_params: list[BaseMessageParam | ChatMessage], | ||
) -> list[ChatMessage]: | ||
message_params: list[ | ||
BaseMessageParam | AssistantMessage | SystemMessage | ToolMessage | UserMessage | ||
], | ||
) -> list[BaseMessageParam]: | ||
converted_message_params = [] | ||
for message_param in message_params: | ||
if isinstance(message_param, ChatMessage): | ||
if not isinstance( | ||
message_param, | ||
BaseMessageParam, | ||
): | ||
converted_message_params.append(message_param) | ||
elif isinstance(content := message_param.content, str): | ||
converted_message_params.append(ChatMessage(**message_param.model_dump())) | ||
converted_message_params.append( | ||
BaseMessageParam(**message_param.model_dump()) | ||
) | ||
else: | ||
if len(content) != 1 or content[0].type != "text": | ||
raise ValueError("Mistral currently only supports text parts.") | ||
converted_message_params.append( | ||
ChatMessage(role=message_param.role, content=content[0].text) | ||
BaseMessageParam(role=message_param.role, content=content[0].text) | ||
) | ||
return converted_message_params |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.