Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions api/app/controllers/prompt_optimizer_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ async def event_generator():
skill=data.skill
):
# chunk 是 prompt 的增量内容
yield f"event:message\ndata: {json.dumps(chunk)}\n\n"
yield f"event:message\ndata: {json.dumps(chunk, ensure_ascii=False)}\n\n"
except Exception as e:
yield f"event:error\ndata: {json.dumps(
{"error": str(e)}
{"error": str(e)},
ensure_ascii=False
)}\n\n"
yield "event:end\ndata: {}\n\n"

Expand Down
7 changes: 5 additions & 2 deletions api/app/services/prompt_optimizer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ async def optimize_prompt(
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
Comment thread
myhMARS marked this conversation as resolved.

# 尝试找到 "prompt": " 开始位置
if prompt_finished:
continue

Expand Down Expand Up @@ -279,7 +282,7 @@ async def optimize_prompt(
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:
Expand Down