From 03481dadae281c95bc4bf164051245d37d037cab Mon Sep 17 00:00:00 2001 From: thug0bin Date: Sun, 8 Mar 2026 15:34:06 +0900 Subject: [PATCH] =?UTF-8?q?feat(animal-chat):=20max=5Ftokens=20=EB=8F=99?= =?UTF-8?q?=EC=A0=81=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 상세 질문 시: max_tokens=1500 (~2000자) - 기본 질문 시: max_tokens=500 (~750자) - is_detail_request 변수 스코프 수정 --- backend/app.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/app.py b/backend/app.py index 5bbd80e..b25b083 100644 --- a/backend/app.py +++ b/backend/app.py @@ -3215,15 +3215,16 @@ def api_animal_chat(): {chr(10).join(product_lines)} """ + # 상세 질문 감지 (전역으로 사용) + detail_keywords = ['자세히', '상세히', '더 알려', '설명해', '왜', '어떻게', '원리', '기전', '성분'] + is_detail_request = any(kw in last_user_msg for kw in detail_keywords) + # 벡터 DB 검색 (LanceDB RAG) vector_context = "" vector_start = time.time() try: from utils.animal_rag import get_animal_rag if last_user_msg: - # 상세 질문 감지: 더 많은 컨텍스트 제공 - detail_keywords = ['자세히', '상세히', '더 알려', '설명해', '왜', '어떻게', '원리', '기전', '성분'] - is_detail_request = any(kw in last_user_msg for kw in detail_keywords) n_results = 5 if is_detail_request else 3 rag = get_animal_rag() @@ -3257,10 +3258,13 @@ def api_animal_chat(): "content": msg.get("content", "") }) + # max_tokens 동적 설정 (상세 질문 시 증가) + max_tokens = 1500 if is_detail_request else 500 + response = client.chat.completions.create( model=OPENAI_MODEL, messages=api_messages, - max_tokens=500, + max_tokens=max_tokens, temperature=0.7 )