Skip to content

Commit 263e5f5

Browse files
authored
[CI] Fix the CI for Python 3.8 (#198)
* [CI] Fix the CI for Python 3.8 * Fix the non async example as well
1 parent c9592d6 commit 263e5f5

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

examples/async_structured_outputs.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
from pydantic import BaseModel
66

77
from mistralai import Mistral
8+
from typing import List
89

9-
async def main():
1010

11+
async def main():
1112
api_key = os.environ["MISTRAL_API_KEY"]
1213
client = Mistral(api_key=api_key)
1314

@@ -16,18 +17,22 @@ class Explanation(BaseModel):
1617
output: str
1718

1819
class MathDemonstration(BaseModel):
19-
steps: list[Explanation]
20+
steps: List[Explanation]
2021
final_answer: str
2122

2223
chat_response = await client.chat.parse_async(
2324
model="mistral-large-2411",
2425
messages=[
25-
{"role": "system", "content": "You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning."},
26+
{
27+
"role": "system",
28+
"content": "You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning.",
29+
},
2630
{"role": "user", "content": "How can I solve 8x + 7 = -23"},
2731
],
28-
response_format = MathDemonstration
32+
response_format=MathDemonstration,
2933
)
3034
print(chat_response.choices[0].message.parsed)
3135

36+
3237
if __name__ == "__main__":
3338
asyncio.run(main())

examples/structured_outputs.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
from mistralai import Mistral
77

8+
from typing import List
9+
10+
811
def main():
912
api_key = os.environ["MISTRAL_API_KEY"]
1013
client = Mistral(api_key=api_key)
@@ -14,32 +17,41 @@ class Explanation(BaseModel):
1417
output: str
1518

1619
class MathDemonstration(BaseModel):
17-
steps: list[Explanation]
20+
steps: List[Explanation]
1821
final_answer: str
1922

2023
print("Using the .parse method to parse the response into a Pydantic model:\n")
2124
chat_response = client.chat.parse(
2225
model="mistral-large-latest",
2326
messages=[
24-
{"role": "system", "content": "You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning."},
27+
{
28+
"role": "system",
29+
"content": "You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning.",
30+
},
2531
{"role": "user", "content": "How can I solve 8x + 7 = -23"},
2632
],
27-
response_format = MathDemonstration
33+
response_format=MathDemonstration,
2834
)
2935
print(chat_response.choices[0].message.parsed)
3036

3137
# Or with the streaming API
32-
print("\nUsing the .parse_stream method to stream back the response into a JSON Schema:\n")
38+
print(
39+
"\nUsing the .parse_stream method to stream back the response into a JSON Schema:\n"
40+
)
3341
with client.chat.parse_stream(
3442
model="mistral-large-latest",
3543
messages=[
36-
{"role": "system", "content": "You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning."},
44+
{
45+
"role": "system",
46+
"content": "You are a helpful math tutor. You will be provided with a math problem, and your goal will be to output a step by step solution, along with a final answer. For each step, just provide the output as an equation use the explanation field to detail the reasoning.",
47+
},
3748
{"role": "user", "content": "How can I solve 8x + 7 = -23"},
3849
],
39-
response_format=MathDemonstration
50+
response_format=MathDemonstration,
4051
) as stream:
4152
for chunk in stream:
4253
print(chunk.data.choices[0].delta.content, end="")
4354

55+
4456
if __name__ == "__main__":
45-
main()
57+
main()

0 commit comments

Comments
 (0)