Spaces:
Running
Running
update yaml parser to regex
Browse files
main.py
CHANGED
@@ -406,6 +406,8 @@ FOLLOWUP_AGENT_PROMPT = """
|
|
406 |
You are a helpful assistant with the following skills, use them, as necessary. If the user request needs further clarification, analyze it and generate clarifying questions with options. Else respond with a helpful answer. <response>response to user request in markdown</response> <clarification> questions: - text: [First clarifying question] options: - [Option 1] - [Option 2] - [Option 3] - [Option 4 (if needed)] - text: [Second clarifying question] options: - [Option 1] - [Option 2] - [Option 3] # Add more questions as needed # make sure this section is in valid YAML format </clarification>
|
407 |
"""
|
408 |
|
|
|
|
|
409 |
def parse_followup_response(response):
|
410 |
response_parts = response.split("<response>")
|
411 |
if len(response_parts) > 1:
|
@@ -415,14 +417,8 @@ def parse_followup_response(response):
|
|
415 |
|
416 |
clarification_parts = response.split("<clarification>")
|
417 |
if len(clarification_parts) > 1:
|
418 |
-
|
419 |
-
|
420 |
-
# Add indentation to make it valid YAML
|
421 |
-
indented_yaml = "\n".join(" " + line for line in clarification_yaml.split("\n"))
|
422 |
-
clarification = yaml.load("questions:\n" + indented_yaml, Loader=SafeLoader)
|
423 |
-
except yaml.YAMLError as e:
|
424 |
-
logger.error(f"YAML parsing error: {e}")
|
425 |
-
clarification = None
|
426 |
else:
|
427 |
clarification = None
|
428 |
|
|
|
406 |
You are a helpful assistant with the following skills, use them, as necessary. If the user request needs further clarification, analyze it and generate clarifying questions with options. Else respond with a helpful answer. <response>response to user request in markdown</response> <clarification> questions: - text: [First clarifying question] options: - [Option 1] - [Option 2] - [Option 3] - [Option 4 (if needed)] - text: [Second clarifying question] options: - [Option 1] - [Option 2] - [Option 3] # Add more questions as needed # make sure this section is in valid YAML format </clarification>
|
407 |
"""
|
408 |
|
409 |
+
import re
|
410 |
+
|
411 |
def parse_followup_response(response):
|
412 |
response_parts = response.split("<response>")
|
413 |
if len(response_parts) > 1:
|
|
|
417 |
|
418 |
clarification_parts = response.split("<clarification>")
|
419 |
if len(clarification_parts) > 1:
|
420 |
+
clarification_text = clarification_parts[1].split("</clarification>")[0].strip()
|
421 |
+
clarification = parse_clarification(clarification_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
else:
|
423 |
clarification = None
|
424 |
|