Mistral 통합
Mistral 통합 (Mistral)
Mistral AI의 모델을 AgentOps와 함께 사용해서, 모델 호출을 자동으로 모니터링하는 방법을 안내하는 문서예요. AgentOps는 Mistral 모델에 대해 일급(first-class) 지원을 제공해요.
출처: 문서
본문
Mistral은 다양한 작업에 사용할 수 있는 오픈웨이트(open-weight) AI 모델을 배포하는 곳이에요. Mistral로 개발하려면 개발자 문서를 참고하세요.
Mistral과 AgentOps 통합 단계
1. AgentOps SDK 설치하기
pip install agentops
poetry add agentops
2. Mistral SDK 설치하기
pip install mistralai
poetry add mistralai
3. AgentOps 초기화하고 Mistral로 개발하기
어떤
openai,cohere,crew등의 모델을 호출하기 전에agentops.init을 먼저 호출해 주세요.
from mistralai import Mistral
import agentops
agentops.init(<INSERT YOUR API KEY HERE>)
client = Mistral(api_key="your_api_key")
# 코드 작성...
agentops.end_session('Success')
API 키는 .env 변수로 설정해 두면 편하게 쓸 수 있어요.
AGENTOPS_API_KEY=<YOUR API KEY>
MISTRAL_API_KEY=<YOUR MISTRAL API KEY>
4. 에이전트 실행하기
프로그램을 실행하고 app.agentops.ai/drilldown에 접속해서 에이전트를 관찰해 보세요! 🕵️
실행을 마치면 AgentOps가 콘솔에 대시보드의 세션으로 바로 연결되는 클릭 가능한 URL을 출력해 줘요.
전체 예제 (Full Examples)
AgentOps와 Mistral을 함께 사용하는 방법을 보여주는 노트북은 여기에서 찾을 수 있어요.
from mistralai import Mistral
import agentops
agentops.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 asyncio
from mistralai import Mistral
import agentops
async 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())
스트리밍 예제 (Streaming Examples)
from mistralai import Mistral
import agentops
agentops.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.content
agentops.end_session('Success')
import asyncio
from mistralai import Mistral
import agentops
async 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())