Mistral AI API 시작하기
Mistral AI API 시작하기 (Getting started with Mistral AI API)
Mistral AI API의 기본 사용법을 배우는 퀵스타트 문서예요. 채팅 완성과 임베딩 엔드포인트를 가장 간단하게 호출하는 방법을 보여줍니다.
출처: 문서
본문
먼저 mistralai 패키지를 설치해요.
! pip install mistralai
우리 API는 [Studio]에서 이용할 수 있어요. API 키를 활성화하려면 계정에서 결제(payments)를 활성화해야 해요. 잠시 후 chat 엔드포인트를 사용할 수 있게 됩니다:
from mistralai.client import Mistral
api_key = "TYPE YOUR API KEY"
model = "mistral-large-latest"
client = Mistral(api_key=api_key)
chat_response = client.chat.complete(
model=model,
messages=[{"role":"user", "content":"What is the best French cheese?"}]
)
print(chat_response.choices[0].message.content)
또는 임베딩 엔드포인트를 사용할 수도 있어요:
model = "mistral-embed"
embeddings_response = client.embeddings.create(
model=model,
inputs=["Embed this sentence.", "As well as this one."]
)
print(embeddings_response)
채팅 완성은 client.chat.complete로, 임베딩은 client.embeddings.create로 호출해요. 임베딩은 여러 문장을 리스트로 한 번에 보낼 수 있어요.