xAI 통합
xAI 통합 (xAI)
xAI의 Grok과 Grok Vision 모델을 AgentOps로 관찰하는 방법을 안내하는 문서예요. xAI 모델은 OpenAI 또는 Anthropic 클라이언트로 접근할 수 있고, AgentOps가 이를 자동으로 추적해요.
출처: 문서
본문
xAI는 Grok과 Grok Vision 모델을 개발해요. 개발자 문서는 여기에서 확인할 수 있어요.
1. AgentOps SDK 설치하기
pip install agentops
poetry add agentops
2. XAI 라이브러리 설치하기
xAI 모델은 OpenAI 또는 Anthropic 클라이언트로 접근할 수 있어요.
OpenAI 클라이언트를 설치하려면:
pip install openai
poetry add openai
Anthropic 클라이언트를 설치하려면:
pip install anthropic
poetry add anthropic
3. 코드에 AgentOps 추가하기
어떤
openai,cohere,crew등의 모델을 호출하기 전에agentops.init을 먼저 호출해 주세요.
import agentops
agentops.init(<INSERT YOUR API KEY HERE>)
# 코드 작성...
agentops.end_session("Success")
API 키는 .env 변수로 설정해 두면 편하게 쓸 수 있어요.
AGENTOPS_API_KEY=<YOUR API KEY>
환경 변수에 대한 더 자세한 내용은 Advanced Configuration 문서를 참고하세요.
4. 분석 실행하기
프로그램을 실행하고 app.agentops.ai/drilldown에 접속해서 XAI 분석을 관찰해 보세요! 🔍
AgentOps가 대시보드에서 XAI 지표와 시각화를 자동으로 추적해 줘요.
전체 예제 (Full Examples)
from openai import OpenAI
XAI_API_KEY = "you xai api key"
client = OpenAI(
api_key=XAI_API_KEY,
base_url="https://api.x.ai/v1",
)
completion = client.chat.completions.create(
model="grok-beta",
messages=[
{"role": "system", "content": "You are Grok, a chatbot inspired by the Hitchhikers Guide to the Galaxy."},
{"role": "user", "content": "What is the meaning of life, the universe, and everything?"},
],
)
print(completion.choices[0].message)
from anthropic import Anthropic
XAI_API_KEY = "you xai api key"
client = Anthropic(
api_key=XAI_API_KEY,
base_url="https://api.x.ai",
)
message = client.messages.create(
model="grok-beta",
max_tokens=128,
system="You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy.",
messages=[
{
"role": "user",
"content": "What is the meaning of life, the universe, and everything?",
},
],
)
print(message.content)