fix(prompt-optimizer): handle escaped quotes in JSON parsing

This commit is contained in:
Eternity
2026-04-15 13:19:02 +08:00
parent 2e1470cb52
commit ed765b7c26
2 changed files with 8 additions and 4 deletions

View File

@@ -236,8 +236,11 @@ class PromptOptimizerService:
logger.error(f"Unsupported content type - {content}")
raise Exception("Unsupported content type")
cache = buffer[:-20]
last_idx = 19
while cache and cache[-1] == '\\' and last_idx > 0:
cache = buffer[:-last_idx]
last_idx -= 1
# 尝试找到 "prompt": " 开始位置
if prompt_finished:
continue
@@ -279,7 +282,7 @@ class PromptOptimizerService:
def parser_prompt_variables(prompt: str):
try:
pattern = r'\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}'
matches = re.findall(pattern, prompt)
matches = re.findall(pattern, str(prompt))
variables = list(set(matches))
return variables
except Exception as e: