Skip to content

Commit f2dc426

Browse files
committed
Copying code
1 parent 6a32f1f commit f2dc426

17 files changed

Lines changed: 1796 additions & 3 deletions

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
#.idea/

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
1-
# client-python
2-
Python client library for Mistral AI platform
1+
# Mistral Python Client
2+
3+
This client uses poetry as a depedency and virtual environment manager.
4+
5+
you can install poetry with@
6+
7+
```bash
8+
pip install poetry
9+
```
10+
11+
## Installing
12+
13+
poetry will set up a virtual environment and install dependencies with the following command:
14+
15+
```bash
16+
poetry install
17+
```
18+
19+
## Run examples
20+
21+
You can run the examples using `poetry run` or by entering the virtual environment using `poetry shell`.
22+
23+
### Using poetry run
24+
25+
```bash
26+
cd examples
27+
poetry run python async_chat.py
28+
```
29+
30+
### Using poetry shell
31+
32+
```bash
33+
cd examples
34+
poetry shell
35+
36+
>> python async_chat.py
37+
```

examples/async_examples.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import asyncio
2+
import os
3+
4+
from mistral_client.async_client import MistralAsyncClient
5+
from mistral_client.models.chat_completion import ChatMessage
6+
7+
8+
async def main():
9+
10+
api_key = os.environ["MISTRAL_API_KEY"]
11+
12+
client = MistralAsyncClient(api_key=api_key)
13+
14+
### LIST MODELS
15+
list_models_response = await client.list_models()
16+
print(list_models_response)
17+
18+
19+
### CHAT NO STREAMING
20+
chat_response = await client.chat(
21+
model="le-tiny",
22+
messages=[ChatMessage(role="user", content="Hello, how are you?")],
23+
)
24+
25+
print(chat_response)
26+
27+
### CHAT STREAMING
28+
async for chunk in client.chat_stream(
29+
model="le-tiny",
30+
messages=[ChatMessage(role="user", content="Hello, how are you?")],
31+
):
32+
print(chunk)
33+
34+
### EMBEDDINGS
35+
embeddings_response = await client.embeddings(
36+
model="le-embed",
37+
input="Hello, how are you?",
38+
)
39+
40+
print(embeddings_response)
41+
42+
### EMBEDDINGS BATCH
43+
embeddings_batch_response = await client.embeddings(
44+
model="le-embed",
45+
input=["Hello, how are you?"] * 10,
46+
)
47+
48+
print(embeddings_batch_response)
49+
50+
51+
if __name__ == "__main__":
52+
asyncio.run(main())

examples/examples.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
3+
from mistral_client.client import MistralClient
4+
from mistral_client.models.chat_completion import ChatMessage
5+
6+
7+
def main():
8+
api_key = os.environ["MISTRAL_API_KEY"]
9+
10+
client = MistralClient(api_key=api_key)
11+
12+
### LIST MODELS
13+
list_models_response = client.list_models()
14+
print(list_models_response)
15+
16+
17+
### CHAT NO STREAMING
18+
chat_response = client.chat(
19+
model="le-tiny",
20+
messages=[ChatMessage(role="user", content="Hello, how are you?")],
21+
)
22+
23+
print(chat_response)
24+
25+
### CHAT STREAMING
26+
for chunk in client.chat_stream(
27+
model="le-tiny",
28+
messages=[ChatMessage(role="user", content="Hello, how are you?")],
29+
):
30+
print(chunk)
31+
32+
### EMBEDDINGS
33+
embeddings_response = client.embeddings(
34+
model="le-embed",
35+
input="Hello, how are you?",
36+
)
37+
38+
print(embeddings_response)
39+
40+
### EMBEDDINGS BATCH
41+
embeddings_batch_response = client.embeddings(
42+
model="le-embed",
43+
input=["Hello, how are you?"] * 10,
44+
)
45+
46+
print(embeddings_batch_response)
47+
48+
49+
50+
if __name__ == "__main__":
51+
main()

poetry.lock

Lines changed: 899 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[tool.poetry]
2+
name = "mistral_client"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Bam4d <bam4d@mistral.ai>"]
6+
readme = "README.md"
7+
8+
[tool.ruff]
9+
select = ["E", "F", "W", "Q", "I"]
10+
ignore = ["E203"]
11+
fixable = ["ALL"]
12+
unfixable = []
13+
line-length = 120
14+
15+
16+
[tool.mypy]
17+
disallow_untyped_defs = true
18+
show_error_codes = true
19+
no_implicit_optional = true
20+
warn_return_any = true
21+
warn_unused_ignores = true
22+
exclude = ["docs", "tests", "examples", "tools", "build"]
23+
24+
25+
[tool.poetry.dependencies]
26+
python = "^3.8"
27+
aiohttp = "^3.9.1"
28+
backoff = "^2.2.1"
29+
orjson = "^3.9.10"
30+
requests = "^2.31.0"
31+
pydantic = "^2.5.2"
32+
33+
34+
[tool.poetry.group.dev.dependencies]
35+
ruff = "^0.1.6"
36+
mypy = "^1.7.1"
37+
types-requests = "^2.31.0.10"
38+
39+
[build-system]
40+
requires = ["poetry-core"]
41+
build-backend = "poetry.core.masonry.api"
42+
43+

src/mistral_client/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)