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

Bump mistralai to > 1.0.0 in preparation for latest models such as Pixtral #531

Merged
merged 20 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion docs/WELCOME.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Make your first call to an LLM to extract the title and author of a book from th
{% if provider == "Anthropic" %}
```python hl_lines="19-38 43"
{% elif provider == "Mistral" %}
```python hl_lines="19-40 45"
```python hl_lines="21-46 51"
{% elif provider == "Gemini" %}
```python hl_lines="19-57 62"
{% elif provider == "Cohere" %}
Expand Down
2 changes: 1 addition & 1 deletion docs/WHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Let's compare structured outputs using Mirascope vs. the official SDKs:
{% if provider == "Anthropic" %}
```python hl_lines="19-38 43"
{% elif provider == "Mistral" %}
```python hl_lines="19-40 45"
```python hl_lines="21-46 51"
{% elif provider == "Gemini" %}
```python hl_lines="19-57 62"
{% elif provider == "Cohere" %}
Expand Down
12 changes: 9 additions & 3 deletions docs/learn/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,14 @@ __Decorator Parameter:__

{% if provider == "LiteLLM" %}
```python
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
{% elif provider in ["OpenAI", "Vertex AI"] %}
```python hl_lines="2 5"
{% elif provider == "Azure AI" %}
```python hl_lines="1-2 8-10"
{% elif provider == "Bedrock" %}
```python hl_lines="7-10 14"
{% elif provider == "Mistral" %}
```python hl_lines="4 8"
{% else %}
```python hl_lines="1 5"
{% endif %}
Expand All @@ -198,12 +200,14 @@ __Dynamic Configuration:__

{% if provider == "LiteLLM" %}
```python
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
{% elif provider in ["OpenAI", "Vertex AI"] %}
```python hl_lines="2 11"
{% elif provider == "Azure AI" %}
```python hl_lines="1-2 12-14"
{% elif provider == "Bedrock" %}
```python hl_lines="5-8 17"
{% elif provider == "Mistral" %}
```python hl_lines="4 15"
{% else %}
```python hl_lines="1 11"
{% endif %}
Expand All @@ -217,12 +221,14 @@ __Dynamic Configuration:__

{% if provider == "LiteLLM" %}
```python
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
{% elif provider in ["OpenAI", "Vertex AI"] %}
```python hl_lines="2 9"
{% elif provider == "Azure AI" %}
```python hl_lines="1-2 10-12"
{% elif provider == "Bedrock" %}
```python hl_lines="5-8 15"
{% elif provider == "Mistral" %}
```python hl_lines="4 11"
{% else %}
```python hl_lines="1 9"
{% endif %}
Expand Down
10 changes: 9 additions & 1 deletion docs/learn/calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ Let's take a look at a basic example using Mirascope vs. official provider SDKs:
```python hl_lines="5-9"
{% elif provider == "Azure AI" %}
```python hl_lines="11-18"
{% elif provider == "Mistral" %}
```python hl_lines="10-15"
{% else %}
```python hl_lines="7-11"
{% endif %}
Expand Down Expand Up @@ -360,12 +362,14 @@ You can pass a client to the `call` decorator using the `client` parameter:

{% if provider == "LiteLLM" %}
```python
{% elif provider in ["OpenAI", "Mistral", "Vertex AI"] %}
{% elif provider in ["OpenAI", "Vertex AI"] %}
```python hl_lines="2 5"
{% elif provider == "Azure AI" %}
```python hl_lines="1-2 8-10"
{% elif provider == "Bedrock" %}
```python hl_lines="1 6"
{% elif provider == "Mistral" %}
```python hl_lines="4 8"
{% else %}
```python hl_lines="1 5"
{% endif %}
Expand Down Expand Up @@ -393,6 +397,8 @@ You can also configure the client dynamically at runtime through the dynamic con
```python hl_lines="1-2 12-14"
{% elif provider == "Bedrock" %}
```python hl_lines="1 11"
{% elif provider == "Mistral" %}
```python hl_lines="4 13"
{% else %}
```python hl_lines="2 11"
{% endif %}
Expand All @@ -410,6 +416,8 @@ You can also configure the client dynamically at runtime through the dynamic con
```python hl_lines="1-2 10-11"
{% elif provider == "Bedrock" %}
```python hl_lines="1 11"
{% elif provider == "Mistral" %}
```python hl_lines="4 11"
{% else %}
```python hl_lines="2 9"
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion docs/learn/response_models.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Let's take a look at a basic example using Mirascope vs. official provider SDKs:
{% if provider == "Anthropic" %}
```python hl_lines="19-38 43"
{% elif provider == "Mistral" %}
```python hl_lines="19-40 45"
```python hl_lines="21-46 51"
{% elif provider == "Gemini" %}
```python hl_lines="19-57 62"
{% elif provider == "Cohere" %}
Expand Down
2 changes: 2 additions & 0 deletions docs/learn/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ Let's take a look at a basic example of each using Mirascope vs. official provid
```python hl_lines="16-22 31-43 45-47"
{% elif provider == "Vertex AI" %}
```python hl_lines="6-12 18-34 36-43"
{% elif provider == "Mistral" %}
```python hl_lines="10-16 23-36 38-44"
{% else %}
```python hl_lines="8-14 21-34 36-38"
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os

from mirascope.core import BaseMessageParam, mistral
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest", client=MistralAsyncClient())
@mistral.call(
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
willbakst marked this conversation as resolved.
Show resolved Hide resolved
)
async def recommend_book_async(genre: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Recommend a {genre} book")]
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os

from mirascope.core import Messages, mistral
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest", client=MistralAsyncClient())
@mistral.call(
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
)
async def recommend_book_async(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book")
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os

from mirascope.core import mistral
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest", client=MistralAsyncClient())
@mistral.call(
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
)
async def recommend_book_async(genre: str) -> str:
return f"Recommend a {genre} book"
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import os

from mirascope.core import mistral, prompt_template
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest", client=MistralAsyncClient())
@mistral.call(
"mistral-large-latest", client=Mistral(api_key=os.environ["MISTRAL_API_KEY"])
)
@prompt_template("Recommend a {genre} book")
async def recommend_book_async(genre: str): ...
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os

from mirascope.core import BaseMessageParam, mistral
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest")
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
return {
"messages": [
BaseMessageParam(role="user", content=f"Recommend a {genre} book")
],
"client": MistralAsyncClient(),
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os

from mirascope.core import Messages, mistral
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest")
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
return {
"messages": [Messages.User(f"Recommend a {genre} book")],
"client": MistralAsyncClient(),
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os

from mirascope.core import mistral, Messages
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest")
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
return {
"messages": [Messages.User(f"Recommend a {genre} book")],
"client": MistralAsyncClient(),
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os

from mirascope.core import mistral, prompt_template
from mistralai.async_client import MistralAsyncClient
from mistralai import Mistral


@mistral.call("mistral-large-latest")
@prompt_template("Recommend a {genre} book")
async def recommend_book(genre: str) -> mistral.AsyncMistralDynamicConfig:
async def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
return {
"client": MistralAsyncClient(),
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
}
14 changes: 9 additions & 5 deletions examples/learn/calls/basic_usage/mistral/official_sdk_call.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from mistralai.client import MistralClient
import os
from typing import cast

client = MistralClient()
from mistralai import Mistral

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])

def recommend_book(genre: str) -> str:
completion = client.chat(

def recommend_book(genre: str) -> str | None:
completion = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": f"Recommend a {genre} book"}],
)
return completion.choices[0].message.content
if completion and (choices := completion.choices):
return cast(str, choices[0].message.content)


output = recommend_book("fantasy")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import os

from mirascope.core import BaseMessageParam, mistral
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["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=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
)
async def recommend_book_async(genre: str) -> list[BaseMessageParam]:
return [BaseMessageParam(role="user", content=f"Recommend a {genre} book")]
17 changes: 15 additions & 2 deletions examples/learn/calls/custom_client/decorator/mistral/messages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import os

from mirascope.core import Messages, mistral
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["MISTRAL_API_KEY"]),
)
def recommend_book(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book")


@mistral.call(
"mistral-large-latest",
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
)
async def recommend_book_async(genre: str) -> Messages.Type:
return Messages.User(f"Recommend a {genre} book")
17 changes: 15 additions & 2 deletions examples/learn/calls/custom_client/decorator/mistral/shorthand.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import os

from mirascope.core import mistral
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["MISTRAL_API_KEY"]),
)
def recommend_book(genre: str) -> str:
return f"Recommend a {genre} book"


@mistral.call(
"mistral-large-latest",
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
)
async def recommend_book_async(genre: str) -> str:
return f"Recommend a {genre} book"
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
import os

from mirascope.core import mistral, prompt_template
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["MISTRAL_API_KEY"]),
)
@prompt_template("Recommend a {genre} book")
def recommend_book(genre: str): ...


@mistral.call(
"mistral-large-latest",
client=Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
)
@prompt_template("Recommend a {genre} book")
async def recommend_book_async(genre: str): ...
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from mirascope.core import BaseMessageParam, mistral
from mistralai.client import MistralClient
from mistralai import Mistral


@mistral.call("mistral-large-latest")
Expand All @@ -8,5 +10,5 @@ def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
"messages": [
BaseMessageParam(role="user", content=f"Recommend a {genre} book")
],
"client": MistralClient(),
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import os

from mirascope.core import Messages, mistral
from mistralai.client import MistralClient
from mistralai import Mistral


@mistral.call("mistral-large-latest")
def recommend_book(genre: str) -> mistral.MistralDynamicConfig:
return {
"messages": [Messages.User(f"Recommend a {genre} book")],
"client": MistralClient(),
"client": Mistral(api_key=os.environ["MISTRAL_API_KEY"]),
}
Loading
Loading