-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: AI dialogue context removes form data #2257
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
@date:2024/6/4 14:30 | ||
@desc: | ||
""" | ||
import re | ||
import time | ||
from functools import reduce | ||
from typing import List, Dict | ||
|
@@ -114,6 +115,9 @@ def get_history_message(history_chat_record, dialogue_number): | |
[history_chat_record[index].get_human_message(), history_chat_record[index].get_ai_message()] | ||
for index in | ||
range(start_index if start_index > 0 else 0, len(history_chat_record))], []) | ||
for message in history_message: | ||
if isinstance(message.content, str): | ||
message.content = re.sub('<form_rander>[\d\D]*?<\/form_rander>', '', message.content) | ||
return history_message | ||
|
||
def generate_prompt_question(self, prompt): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's a review of your provided code: Overall Review
Suggestions
Overall, your code is mostly sound, but adding proper documentation, refining error handling, and optimizing performance would make it more robust and maintainable. |
||
|
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.
The provided code has a few minor issues that can be addressed:
Re-importing Modules: There is an unnecessary import of
re
at the beginning of the file, which could cause confusion or potential conflicts since it appears to already be imported in line 14.Redundancy in Function Calls: The
get_message
function is called twice withinget_history_messages
, but with different parameters (start_index
) and without using its result elsewhere. This redundant call might not serve any purpose and should potentially be removed or fixed if needed.Regex Pattern for Removing Form Renderer Content: In the last two lines of
generate_prompt_question
, removing the form renderer content using a regular expression may not work correctly if<form_renderer>
tags only appear around specific parts of the text. Using a more precise pattern would ensure cleaner results.Here are the corrections made based on these observations:
These changes eliminate redundancy, clean up the logic slightly, and handle the removal of HTML-like tags in a more robust manner. Additionally, the
generate_prompt_question
function now includes handling for newline characters, ensuring that each part of the prompt (split into multiple lines) undergoes the same transformation before being combined back together.