fix: 도구 결과 포맷팅에 평문 프롬프트 사용 — JSON 출력 방지
분류기 system prompt가 JSON 강제라서 결과 포맷도 JSON으로 나옴. 도구 결과 정리 시 별도 평문 프롬프트를 messages로 직접 전달. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -265,22 +265,27 @@ async def run(job: Job) -> None:
|
||||
collected.append(response)
|
||||
await state_stream.push(job.id, "result", {"content": response})
|
||||
else:
|
||||
# 결과를 EXAONE에 전달하여 자연어로 정리
|
||||
# 결과를 EXAONE에 전달하여 자연어로 정리 (평문 프롬프트 사용)
|
||||
tool_json = json.dumps(result["data"], ensure_ascii=False)
|
||||
if len(tool_json) > MAX_TOOL_PAYLOAD:
|
||||
tool_json = tool_json[:MAX_TOOL_PAYLOAD] + "...(truncated)"
|
||||
format_input = f"[도구 결과]\n{tool_json}\n\n위 데이터를 바탕으로 사용자에게 자연스럽고 간결하게 답해."
|
||||
format_messages = [
|
||||
{"role": "system", "content": "너는 이드, 상냥한 AI 어시스턴트야. 도구 결과를 사용자에게 자연스럽고 간결하게 전달해. JSON이나 코드블록 없이 순수 텍스트로만 답해. 날짜와 시간을 명확히 포함해."},
|
||||
{"role": "user", "content": f"아래 도구 결과를 사용자에게 자연스럽게 전달해줘:\n\n{tool_json}"},
|
||||
]
|
||||
try:
|
||||
response = await _complete_with_heartbeat(
|
||||
backend_registry.classifier, format_input, job.id,
|
||||
backend_registry.classifier, "", job.id,
|
||||
messages=format_messages,
|
||||
beat_msg="결과를 정리하고 있습니다..."
|
||||
)
|
||||
# 포맷팅 응답이 JSON으로 올 수도 있으니 파싱 시도
|
||||
try:
|
||||
parsed = json.loads(response)
|
||||
response = parsed.get("response", response)
|
||||
except (json.JSONDecodeError, AttributeError):
|
||||
pass
|
||||
# 혹시 JSON 잔재가 있으면 추출
|
||||
if response.strip().startswith("{"):
|
||||
try:
|
||||
parsed = json.loads(response)
|
||||
response = parsed.get("response", response)
|
||||
except (json.JSONDecodeError, AttributeError):
|
||||
pass
|
||||
except Exception:
|
||||
response = result.get("summary", "결과를 조회했습니다.")
|
||||
collected.append(response)
|
||||
|
||||
Reference in New Issue
Block a user