069. Mistral AI 채팅 완성 (Mistral AI chat completion)
- 원문: English
- 위치: References/Advanced › Advanced inference topics › Inference parameters › Mistral AI models › Mistral AI chat completion
한 줄 요약
Mistral Large용 채팅 완성 API는 OpenAI와 비슷한 messages·tools·tool_choice 구조를 쓰며 함수 호출(도구 사용) 을 지원합니다. 다만 AWS는 Converse API 사용을 권장합니다.
쉽게 말하면
system/user/assistant 역할로 대화를 넣고, 도구 정의를 주면 모델이 tool_calls로 “이 함수 실행해 줘"라고 답합니다. 실행 결과는 role: "tool" 메시지로 돌려줍니다.
핵심 내용
지원 모델
- Mistral Large (Apache 2.0 라이선스)
요청 구조 (요약)
{
"messages": [
{ "role": "system"|"user"|"assistant", "content": str },
{ "role": "assistant", "content": "", "tool_calls": [ { "id": str, "function": { "name": str, "arguments": str } } ] },
{ "role": "tool", "tool_call_id": str, "content": str }
],
"tools": [ { "type": "function", "function": { "name": str, "description": str, "parameters": dict } } ],
"tool_choice": "auto"|"any"|"none",
"max_tokens": int,
"top_p": float,
"temperature": float
}
파라미터
| 파라미터 | 필수 | 설명 / 값 |
|---|---|---|
messages | ✅ | role(system/user/assistant/tool) + content. 도구 결과는 role: tool + tool_call_id |
tools | 함수 정의 목록(JSON Schema parameters) | |
tool_choice | none: 함수 호출 안 함 / auto: 모델이 선택 / any: 반드시 함수 호출 | |
max_tokens | 기본 8,192, 범위 1~8,192 | |
temperature | 기본 0.7, 0~1 | |
top_p | 기본 1, 0~1 |
응답 구조
{
"choices": [
{ "index": 0,
"message": { "role": "assistant", "content": str, "tool_calls": [...] },
"stop_reason": "stop"|"length"|"tool_calls" }
]
}
stop_reason이tool_calls면message.tool_calls에 실행할 함수name과arguments(JSON 문자열)가 들어 있습니다.
📝 원문 확인 필요: 요청 파라미터에는
stop이 없는데, 응답의stop_reason: stop설명은 “stop요청 파라미터에 정의한 정지 시퀀스"를 언급합니다. 또tools설명에서 결과를 “tool_result콘텐츠 블록"으로 돌려준다고 하지만, 요청 구조 예시는role: "tool"메시지를 사용합니다.
SA 관점
- 💡 원문 팁처럼 신규 구현은 Converse API로 작성하면 다른 모델로 바꿀 때 코드 수정이 적습니다. 도구 사용 일반론은 030-tool-use 참고.
tool_choice: any는 “항상 함수 호출"이므로, 라우터/분류기 패턴처럼 구조화된 출력을 강제할 때 유용합니다.