Make sure to call agentops.init before calling any openai, cohere, crew, etc models.
from mistralai import Mistralimport agentopsagentops.init(<INSERT YOUR API KEY HERE>)client = Mistral(api_key="your_api_key")# Your code here...agentops.end_session('Success')
Set your API key as an .env variable for easy access.
AGENTOPS_API_KEY=<YOUR API KEY>MISTRAL_API_KEY=<YOUR MISTRAL API KEY>
A notebook demonstrating how to use AgentOps with Mistral can be found here.
from mistralai import Mistralimport agentopsagentops.init(<INSERT YOUR API KEY HERE>)client = Mistral(api_key="your_api_key")response = client.chat.complete( model="mistral-small-latest", messages=[ { "role": "user", "content": "Explain the history of the French Revolution." } ],)print(response.choices[0].message.content)agentops.end_session('Success')
import asynciofrom mistralai import Mistralimport agentopsasync def main(): agentops.init(<INSERT YOUR API KEY HERE>) client = Mistral(api_key="your_api_key") response = await client.chat.complete_async( model="mistral-small-latest", messages=[ { "role": "user", "content": "Write a short summary about the poem La Belle Dame sans Merci.", }, ], ) print(response.choices[0].message.content) agentops.end_session('Success')asyncio.run(main())
from mistralai import Mistralimport agentopsagentops.init(<INSERT YOUR API KEY HERE>)client = Mistral(api_key="your_api_key")complete_response = ""response = client.chat.stream( model="mistral-small-latest", messages=[ { "role": "user", "content": "Who was Joan of Arc?" } ],)for chunk in response: if chunk.data.choices[0].finish_reason == "stop": print(complete_response) else: complete_response += chunk.data.choices[0].delta.contentagentops.end_session('Success')
import asynciofrom mistralai import Mistralimport agentopsasync def main(): agentops.init(<INSERT YOUR API KEY HERE>) client = Mistral(api_key="your_api_key") complete_response = "" response = await client.chat.stream_async( model="mistral-small-latest", messages=[ { "role": "user", "content": "Write a short summary about the poem La Belle Dame sans Merci.", }, ], ) async for chunk in response: if chunk.data.choices[0].finish_reason == "stop": print(complete_response) else: complete_response += chunk.data.choices[0].delta.content agentops.end_session('Success')asyncio.run(main())