Skip to content

Commit 494860e

Browse files
authored
Merge pull request #226 from Project-Guideon/develop
Develop
2 parents 38adf86 + a8c5ef5 commit 494860e

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

app/graph/nodes/tool/navigation_node.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import os
5+
import re
56
from difflib import SequenceMatcher
67
from typing import Any, Dict, List, Optional
78
from urllib.parse import quote
@@ -238,10 +239,10 @@ def navigation_node(state: GraphState) -> dict:
238239
" - If '위치설명' is provided, include that location detail in your answer\n"
239240
" - Do not invent location details not in the provided info\n"
240241
" - No emoji, no special characters\n"
241-
" - If the persona has a slogan or catchphrase, put it in sign_off, not in answer\n\n"
242+
f" - If the persona has a slogan or catchphrase, translate it into {lang_name} and put it in sign_off (NOT in Korean).\n\n"
242243
f"Place: {place_name} (category: {place.get('category')}){dist_str}{desc_part}\n\n"
243244
"Return ONLY valid JSON (no markdown):\n"
244-
'{"answer": "...", "sign_off": "slogan/catchphrase or empty string", "emotion": "GUIDING"}'
245+
'{"answer": "...", "sign_off": "slogan/catchphrase in target language or empty string", "emotion": "GUIDING"}'
245246
)
246247

247248
messages = build_messages(state, system_msg, text)
@@ -280,8 +281,8 @@ def navigation_node(state: GraphState) -> dict:
280281
error_msg = str(e)
281282

282283
if answer_text:
283-
if sign_off and answer_text.endswith(sign_off):
284-
answer_text = answer_text[:-len(sign_off)].rstrip()
284+
if sign_off and sign_off in answer_text:
285+
answer_text = re.sub(r'\s+', ' ', re.sub(r'(?<!\S)' + re.escape(sign_off) + r'(?!\S)', '', answer_text)).strip()
285286
if map_url:
286287
guide = _MAP_GUIDE.get(user_language, _MAP_GUIDE["en"])
287288
answer_text = f"{answer_text} {guide}"
@@ -355,10 +356,10 @@ def navigation_node(state: GraphState) -> dict:
355356
" - Prioritize same-zone (✓ 같은 구역) places and shorter distances\n"
356357
" - Mention the place name and distance\n"
357358
" - No emoji, no special characters\n"
358-
" - If the persona has a slogan or catchphrase, put it in sign_off, not in answer\n\n"
359+
f" - If the persona has a slogan or catchphrase, translate it into {lang_name} and put it in sign_off (NOT in Korean).\n\n"
359360
f"Nearby places:\n{places_text}\n\n"
360361
"Return ONLY valid JSON (no markdown):\n"
361-
'{"answer": "...", "sign_off": "slogan/catchphrase or empty string", '
362+
'{"answer": "...", "sign_off": "slogan/catchphrase in target language or empty string", '
362363
'"place_id": <placeId or null>, "emotion": "GUIDING", "category": "DIRECTION"}'
363364
)
364365

@@ -444,8 +445,8 @@ def navigation_node(state: GraphState) -> dict:
444445
if error_msg:
445446
trace["navigation"]["error"] = error_msg
446447

447-
if sign_off and answer_text.endswith(sign_off):
448-
answer_text = answer_text[:-len(sign_off)].rstrip()
448+
if sign_off and sign_off in answer_text:
449+
answer_text = re.sub(r'\s+', ' ', re.sub(r'(?<!\S)' + re.escape(sign_off) + r'(?!\S)', '', answer_text)).strip()
449450
if map_url:
450451
guide = _MAP_GUIDE.get(user_language, _MAP_GUIDE["en"])
451452
answer_text = f"{answer_text} {guide}"

0 commit comments

Comments
 (0)