Chainlit / literalai-python

https://docs.getliteral.ai/
Apache License 2.0
8 stars 0 forks source link

feat: mistral ai instrumentation #82

Closed desaxce closed 2 months ago

desaxce commented 3 months ago

Mistral AI instrumentation

Instrumentation for Mistral AI's python client: see Mistral API doc for reference.

I validated the change against with Chainlit's use of the instrumentation and adjusted our RAG documentation app to rely on Mistral AI (except embeddings). There were a few changes because Mistral doesn't support [type: text, content: ""] format, but it worked otherwise. In the following video you'll notice that the streaming and the tool calls don't show, I believe it's due to my local setup (I have RAG app -> depends on chainlit -> depends on literalai and I'm not sure about the whole build setup).

You'll notice that prompt playground settings show mistral-tiny, when it should be mistral-large-latest. It's a bug on our Literal platform: image

https://www.loom.com/share/6d139bfbe18a4aaf92dcde27bf466a41

Features:

To test:

import os

from literalai import LiteralClient
from mistralai.client import MistralClient

lai_client = LiteralClient(api_key="my-initial-api-key", url="https://staging.chainlit.io/")
lai_client.instrument_mistralai()

mai_client = MistralClient(api_key="the-secret-api-key")

stream = mai_client.chat_stream(
    model="open-mistral-7b",
    messages=[{"role": "user", "content": "🖖 Qui est Camille Saint-Saëns ? 🎵"}],
)

for part in stream:
    if token := part.choices[0].delta.content or "":
        print(token, end="")

Worth-noting changes:

linear[bot] commented 3 months ago

ENG-1183 Mistral instrumentation