Skip to content

Commit 1cfd45e

Browse files
committed
feat: add new example
1 parent 6efb794 commit 1cfd45e

File tree

3 files changed

+64
-20
lines changed

3 files changed

+64
-20
lines changed

.github/workflows/run_example_scripts.yaml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ jobs:
2828
- name: Install Poetry
2929
uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1.4.1
3030

31-
- name: Build and install client
32-
run: |
33-
touch README-PYPI.md # Create this file since the client is not built from Speakeasy
34-
poetry build
35-
python3 -m pip install dist/mistralai-*.whl
36-
3731
- name: Set VERSION
3832
run: |
3933
VERSION=$(echo ${{ matrix.python-version }} | tr -d .)
@@ -43,20 +37,24 @@ jobs:
4337
run: |
4438
echo "MISTRAL_API_KEY=${{ secrets[format('CI_MISTRAL_API_KEY_PYTHON_{0}', env.VERSION)] }}" >> $GITHUB_ENV
4539
46-
- name: Run the example scripts
40+
- name: For python 3.9, build and install client. Run examples without extra dependencies.
41+
if: matrix.python-version == '3.9'
4742
run: |
48-
failed=0
49-
for file in examples/*.py; do
50-
if [ -f "$file" ] && [ "$file" != "examples/chatbot_with_streaming.py" ]; then
51-
echo "Running $file"
52-
# Do not fail if the script fails, but save it in the failed variable
53-
python3 "$file" > /dev/null || failed=1
54-
fi
55-
done
56-
# If one of the example script failed then exit
57-
if [ $failed -ne 0 ]; then
58-
exit 1
59-
fi
43+
poetry build
44+
PACKAGE="dist/$(ls dist | grep whl | head -n 1)"
45+
python3 -m pip install "$PACKAGE"
46+
./examples/run_all.sh --no-extra-dep
47+
env:
48+
MISTRAL_AGENT_ID: ${{ vars.CI_AGENT_ID }}
49+
MISTRAL_API_KEY: ${{ env.MISTRAL_API_KEY }}
50+
51+
- name: For python 3.10+, build and install client with extras. Run all examples.
52+
if: matrix.python-version != '3.9'
53+
run: |
54+
poetry build
55+
PACKAGE="dist/$(ls dist | grep whl | head -n 1)[agents]"
56+
python3 -m pip install "$PACKAGE"
57+
./examples/run_all.sh
6058
env:
61-
MISTRAL_AGENT_ID: ${{ secrets.CI_AGENT_ID }}
59+
MISTRAL_AGENT_ID: ${{ vars.CI_AGENT_ID }}
6260
MISTRAL_API_KEY: ${{ env.MISTRAL_API_KEY }}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ installing the package:
117117
pip install "mistralai-private[agents]"
118118
```
119119

120+
> Note: Because of some of our dependencies, these features are only available for python version higher or equal to
121+
> 3.10.
122+
120123
<!-- Start SDK Example Usage [usage] -->
121124
## SDK Example Usage
122125

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
import asyncio
3+
import os
4+
5+
from mistralai_private import MistralPrivate
6+
7+
MODEL = "mistral-medium-latest"
8+
9+
10+
async def main():
11+
api_key = os.environ["MISTRAL_API_KEY"]
12+
client = MistralPrivate(api_key=api_key)
13+
14+
agent = client.beta.agents.create(
15+
model=MODEL,
16+
name="WebSearch Agent",
17+
instructions="Use your websearch abilities when answering requests you don't know.",
18+
description="Agent able to fetch new information on the web.",
19+
tools = [{"type": "web_search"}],
20+
)
21+
22+
result = await client.beta.conversations.start_async(
23+
agent_id=agent.id,
24+
inputs="Who won the last Champions League?"
25+
)
26+
27+
print("All result entries:")
28+
for entry in result.outputs:
29+
print(f"{entry}")
30+
31+
result = await client.beta.conversations.append_async(
32+
conversation_id=result.conversation_id,
33+
inputs="And what about the previous year?"
34+
)
35+
36+
print("All result entries:")
37+
for entry in result.outputs:
38+
print(f"{entry}")
39+
40+
41+
42+
if __name__ == "__main__":
43+
asyncio.run(main())

0 commit comments

Comments
 (0)