인터리브드 씽킹
인터리브드 씽킹 (Interleaved Thinking)
인터리브드 씽킹은 모델이 도구 호출 사이에 추론(reasoning)을 수행하도록 해 주는 기능이에요. 도구 실행 결과를 받은 뒤 더 정교한 의사 결정을 내릴 수 있고, 여러 도구 호출을 추론 단계와 함께 이어 나가며 중간 결과를 바탕으로 세밀한 판단을 하도록 도와줍니다.
주의하세요. 인터리브드 씽킹은 토큰 사용량과 응답 지연 시간을 늘립니다. 이 기능을 켤 때는 예산과 성능 요구 사항을 꼭 고려하세요.
출처: 문서
본문
인터리브드 씽킹의 동작 방식
인터리브드 씽킹을 사용하면 모델은 다음과 같은 일을 할 수 있어요.
- 다음에 무엇을 할지 결정하기 전에 도구 호출의 결과에 대해 추론하기
- 추론 단계를 사이에 두고 여러 도구 호출을 이어 붙이기
- 중간 결과를 바탕으로 더 세밀한 결정 내리기
- 도구 선택 과정에 대한 투명한 추론 제공하기
지원 모델
vLLM은 현재 다음의 인터리브드 씽킹 모델을 지원합니다.
| 모델 시리즈 | 추론 파서 이름 (Reasoning Parser Name) |
|---|---|
moonshotai/Kimi-K2-Thinking |
kimi_k2 |
MiniMaxAI/MiniMax-M2 |
minimax_m2 |
사용 예시
도구 호출과 함께 인터리브드 씽킹을 사용하려면, 이 기능을 지원하는 모델을 지정하고 채팅 완료 요청에서 도구 호출을 활성화해야 해요. 예시는 다음과 같습니다.
"""
vllm serve MiniMaxAI/MiniMax-M2 \
--tensor-parallel-size 4 \
--tool-call-parser minimax_m2 \
--reasoning-parser minimax_m2 \
--enable-auto-tool-choice
"""
import json
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="dummy")
def get_current_weather(location: str, unit: "str"):
"""Get the current weather in a given location"""
if unit == "celsius":
return f"The current temperature in {location} is 22°C."
else:
return f"The current temperature in {location} is 72°F."
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "City and state, e.g., 'San Francisco, CA'",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location", "unit"],
},
},
}
]
messages = [{"role": "user", "content": "What's the weather in Fahrenheit like in San Francisco?"}]
response = client.chat.completions.create(
model=client.models.list().data[0].id,
messages=messages,
tools=tools,
tool_choice="auto",
)
tool_call = response.choices[0].message.tool_calls[0].function
messages.append(
{
"role": "assistant",
"tool_calls": response.choices[0].message.tool_calls,
"reasoning": response.choices[0].message.reasoning, # append reasoning
}
)
# Simulate tool execution
available_tools = {"get_weather": get_current_weather}
completion_tool_calls = response.choices[0].message.tool_calls
for call in completion_tool_calls:
tool_to_call = available_tools[call.function.name]
args = json.loads(call.function.arguments)
result = tool_to_call(**args)
messages.append(
{
"role": "tool",
"content": result,
"tool_call_id": call.id,
"name": call.function.name,
}
)
response_2 = client.chat.completions.create(
model=client.models.list().data[0].id,
messages=messages,
tools=tools,
tool_choice="auto",
)
print(response_2.choices[0].message.content)
이 예시는 날씨 조회 함수를 사용해 도구 호출과 함께 인터리브드 씽킹을 구성하는 방법을 보여줘요. 모델이 최종 응답을 생성하기 전에 도구 결과에 대해 추론하는 과정을 확인할 수 있습니다.