mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 12:20:38 +08:00
Improve conversation history handling and prompts for line questions
This commit is contained in:
@ -49,7 +49,12 @@ Previous discussion on this code:
|
|||||||
======
|
======
|
||||||
{{ conversation_history|trim }}
|
{{ conversation_history|trim }}
|
||||||
======
|
======
|
||||||
Use this prior discussion context to provide a consistent and informed answer.
|
|
||||||
|
Consider this conversation history (format: "Username: Message"). When responding:
|
||||||
|
- Maintain consistency with previous technical explanations
|
||||||
|
- Address unresolved issues from earlier discussions
|
||||||
|
- Build upon existing knowledge without contradictions
|
||||||
|
- Incorporate relevant context while focusing on the current question
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
A question about the selected lines:
|
A question about the selected lines:
|
||||||
|
@ -60,7 +60,8 @@ class PR_LineQuestions:
|
|||||||
# set conversation history if enabled
|
# set conversation history if enabled
|
||||||
# currently only supports GitHub provider
|
# currently only supports GitHub provider
|
||||||
if get_settings().pr_questions.use_conversation_history and isinstance(self.git_provider, GithubProvider):
|
if get_settings().pr_questions.use_conversation_history and isinstance(self.git_provider, GithubProvider):
|
||||||
self._load_conversation_history()
|
conversation_history = self._load_conversation_history()
|
||||||
|
self.vars["conversation_history"] = conversation_history
|
||||||
|
|
||||||
self.patch_with_lines = ""
|
self.patch_with_lines = ""
|
||||||
ask_diff = get_settings().get('ask_diff_hunk', "")
|
ask_diff = get_settings().get('ask_diff_hunk', "")
|
||||||
@ -99,18 +100,20 @@ class PR_LineQuestions:
|
|||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _load_conversation_history(self):
|
def _load_conversation_history(self) -> str:
|
||||||
"""generate conversation history from the code review thread"""
|
"""Generate conversation history from the code review thread
|
||||||
# set conversation history to empty string
|
|
||||||
self.vars["conversation_history"] = ""
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The formatted conversation history
|
||||||
|
"""
|
||||||
comment_id = get_settings().get('comment_id', '')
|
comment_id = get_settings().get('comment_id', '')
|
||||||
file_path = get_settings().get('file_name', '')
|
file_path = get_settings().get('file_name', '')
|
||||||
line_number = get_settings().get('line_end', '')
|
line_number = get_settings().get('line_end', '')
|
||||||
|
|
||||||
# early return if any required parameter is missing
|
# early return if any required parameter is missing
|
||||||
if not all([comment_id, file_path, line_number]):
|
if not all([comment_id, file_path, line_number]):
|
||||||
return
|
get_logger().error("Missing required parameters for conversation history")
|
||||||
|
return ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# retrieve thread comments
|
# retrieve thread comments
|
||||||
@ -129,13 +132,16 @@ class PR_LineQuestions:
|
|||||||
author = user.login if hasattr(user, 'login') else 'Unknown'
|
author = user.login if hasattr(user, 'login') else 'Unknown'
|
||||||
conversation_history.append(f"{author}: {body}")
|
conversation_history.append(f"{author}: {body}")
|
||||||
|
|
||||||
# transform and save conversation history
|
# transform conversation history to string
|
||||||
if conversation_history:
|
if conversation_history:
|
||||||
self.vars["conversation_history"] = "\n\n".join(conversation_history)
|
|
||||||
get_logger().info(f"Loaded {len(conversation_history)} comments from the code review thread")
|
get_logger().info(f"Loaded {len(conversation_history)} comments from the code review thread")
|
||||||
|
return "\n\n".join(conversation_history)
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Error processing conversation history, error: {e}")
|
get_logger().error(f"Error processing conversation history, error: {e}")
|
||||||
|
return ""
|
||||||
|
|
||||||
async def _get_prediction(self, model: str):
|
async def _get_prediction(self, model: str):
|
||||||
variables = copy.deepcopy(self.vars)
|
variables = copy.deepcopy(self.vars)
|
||||||
|
Reference in New Issue
Block a user