-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhancement of AI Response Parsing Mechanism #537
Enhancement of AI Response Parsing Mechanism #537
Conversation
PR Description updated to latest commit (4854007) |
/describe |
PR Analysis(review updated until commit 16b61eb)
PR Feedback
How to useInstructions
|
PR Description updated to latest commit (4854007) |
f36d77f
to
16b61eb
Compare
I apologize; I found a typo, so I re-pushed it. |
/describe |
PR Description updated to latest commit (16b61eb) |
/review |
Persistent review updated to latest commit 16b61eb |
/ask explain to me what the following code does. Be specific, and give examples. Be critical, and think of edge cases. # remove everything before the first ```yaml
snipet_pattern = r'```(yaml)?[\s\S]*?```'
snipet = re.search(snipet_pattern, response_text)
if snipet:
response_text = snipet.group() |
Question: explain to me what the following code does. Be specific, and give examples. Be critical, and think of edge cases. Answer: Here's a breakdown of the code:
For example, if the AI's response is:
name: John Smith
age: 35
|
Hi @koid My request is to move the condition to the fallback:
Why:
Once you will move it to the fallback section, we can merge |
Thank you for the review. |
ce1c4f8
to
e2797ad
Compare
data = {} | ||
for i in range(1, len(response_text_lines)): | ||
response_text_lines_tmp = '\n'.join(response_text_lines[:-i]) | ||
try: | ||
data = yaml.safe_load(response_text_lines_tmp,) | ||
get_logger().info(f"Successfully parsed AI prediction after removing {i} lines") | ||
break | ||
return data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a 'return' statement because even when it could be loaded as YAML, it was not returning a value.
Although I considered creating a separate PR for this, I decided to include the fix together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Hi @mrT23 I've completed the corrections, so please review it again. The changes are as follows:
|
Thanks @koid |
…ription-in-ai-response Enhancement of AI Response Parsing Mechanism
Type
Enhancement
Description
This PR introduces an enhancement to the AI response parsing mechanism. The main changes include:
load_yaml
function inpr_agent/algo/utils.py
has been modified to use this pattern and extract the YAML snippet.tests/unittest/test_load_yaml.py
to verify the correct parsing of AI responses that include a description before the YAML snippet.PR changes walkthrough
1 files
utils.py
pr_agent/algo/utils.py
The `load_yaml` function has been enhanced with a regular
expression pattern to extract the YAML snippet from the AI
response, ignoring any explanatory text before the snippet.
1 files
test_load_yaml.py
tests/unittest/test_load_yaml.py
A new test case has been added to verify the correct parsing
of AI responses that include a description before the YAML
snippet.
User description
As with added test cases during PR, AI responses are not only encapsulated in quotes as snippets but may also include explanatory text at the beginning.
While we already handle cases where existing code becomes a snippet, adding a step to extract the snippet portion from AI responses in advance is desired to prevent parsing errors when explanatory text is included.