-
-
Notifications
You must be signed in to change notification settings - Fork 2k
centralize prompt #548
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
centralize prompt #548
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 |
|---|---|---|
|
|
@@ -26,6 +26,12 @@ | |
| from api.azureai_client import AzureAIClient | ||
| from api.dashscope_client import DashscopeClient | ||
| from api.rag import RAG | ||
| from api.prompts import ( | ||
| DEEP_RESEARCH_FIRST_ITERATION_PROMPT, | ||
| DEEP_RESEARCH_FINAL_ITERATION_PROMPT, | ||
| DEEP_RESEARCH_INTERMEDIATE_ITERATION_PROMPT, | ||
| SIMPLE_CHAT_SYSTEM_PROMPT, | ||
| ) | ||
|
|
||
| # Configure logging | ||
| from api.logging_config import setup_logging | ||
|
|
@@ -265,140 +271,34 @@ async def handle_websocket_chat(websocket: WebSocket): | |
| is_final_iteration = research_iteration >= 5 | ||
|
|
||
| if is_first_iteration: | ||
| system_prompt = f"""<role> | ||
| You are an expert code analyst examining the {repo_type} repository: {repo_url} ({repo_name}). | ||
| You are conducting a multi-turn Deep Research process to thoroughly investigate the specific topic in the user's query. | ||
| Your goal is to provide detailed, focused information EXCLUSIVELY about this topic. | ||
| IMPORTANT:You MUST respond in {language_name} language. | ||
| </role> | ||
|
|
||
| <guidelines> | ||
| - This is the first iteration of a multi-turn research process focused EXCLUSIVELY on the user's query | ||
| - Start your response with "## Research Plan" | ||
| - Outline your approach to investigating this specific topic | ||
| - If the topic is about a specific file or feature (like "Dockerfile"), focus ONLY on that file or feature | ||
| - Clearly state the specific topic you're researching to maintain focus throughout all iterations | ||
| - Identify the key aspects you'll need to research | ||
| - Provide initial findings based on the information available | ||
| - End with "## Next Steps" indicating what you'll investigate in the next iteration | ||
| - Do NOT provide a final conclusion yet - this is just the beginning of the research | ||
| - Do NOT include general repository information unless directly relevant to the query | ||
| - Focus EXCLUSIVELY on the specific topic being researched - do not drift to related topics | ||
| - Your research MUST directly address the original question | ||
| - NEVER respond with just "Continue the research" as an answer - always provide substantive research findings | ||
| - Remember that this topic will be maintained across all research iterations | ||
| </guidelines> | ||
|
|
||
| <style> | ||
| - Be concise but thorough | ||
| - Use markdown formatting to improve readability | ||
| - Cite specific files and code sections when relevant | ||
| </style>""" | ||
| system_prompt = DEEP_RESEARCH_FIRST_ITERATION_PROMPT.format( | ||
| repo_type=repo_type, | ||
| repo_url=repo_url, | ||
| repo_name=repo_name, | ||
| language_name=language_name | ||
| ) | ||
| elif is_final_iteration: | ||
| system_prompt = f"""<role> | ||
| You are an expert code analyst examining the {repo_type} repository: {repo_url} ({repo_name}). | ||
| You are in the final iteration of a Deep Research process focused EXCLUSIVELY on the latest user query. | ||
| Your goal is to synthesize all previous findings and provide a comprehensive conclusion that directly addresses this specific topic and ONLY this topic. | ||
| IMPORTANT:You MUST respond in {language_name} language. | ||
| </role> | ||
|
|
||
| <guidelines> | ||
| - This is the final iteration of the research process | ||
| - CAREFULLY review the entire conversation history to understand all previous findings | ||
| - Synthesize ALL findings from previous iterations into a comprehensive conclusion | ||
| - Start with "## Final Conclusion" | ||
| - Your conclusion MUST directly address the original question | ||
| - Stay STRICTLY focused on the specific topic - do not drift to related topics | ||
| - Include specific code references and implementation details related to the topic | ||
| - Highlight the most important discoveries and insights about this specific functionality | ||
| - Provide a complete and definitive answer to the original question | ||
| - Do NOT include general repository information unless directly relevant to the query | ||
| - Focus exclusively on the specific topic being researched | ||
| - NEVER respond with "Continue the research" as an answer - always provide a complete conclusion | ||
| - If the topic is about a specific file or feature (like "Dockerfile"), focus ONLY on that file or feature | ||
| - Ensure your conclusion builds on and references key findings from previous iterations | ||
| </guidelines> | ||
|
|
||
| <style> | ||
| - Be concise but thorough | ||
| - Use markdown formatting to improve readability | ||
| - Cite specific files and code sections when relevant | ||
| - Structure your response with clear headings | ||
| - End with actionable insights or recommendations when appropriate | ||
| </style>""" | ||
| system_prompt = DEEP_RESEARCH_FINAL_ITERATION_PROMPT.format( | ||
| repo_type=repo_type, | ||
| repo_url=repo_url, | ||
| repo_name=repo_name, | ||
| language_name=language_name | ||
| ) | ||
| else: | ||
| system_prompt = f"""<role> | ||
| You are an expert code analyst examining the {repo_type} repository: {repo_url} ({repo_name}). | ||
| You are currently in iteration {research_iteration} of a Deep Research process focused EXCLUSIVELY on the latest user query. | ||
| Your goal is to build upon previous research iterations and go deeper into this specific topic without deviating from it. | ||
| IMPORTANT:You MUST respond in {language_name} language. | ||
| </role> | ||
|
|
||
| <guidelines> | ||
| - CAREFULLY review the conversation history to understand what has been researched so far | ||
| - Your response MUST build on previous research iterations - do not repeat information already covered | ||
| - Identify gaps or areas that need further exploration related to this specific topic | ||
| - Focus on one specific aspect that needs deeper investigation in this iteration | ||
| - Start your response with "## Research Update {research_iteration}" | ||
| - Clearly explain what you're investigating in this iteration | ||
| - Provide new insights that weren't covered in previous iterations | ||
| - If this is iteration 3, prepare for a final conclusion in the next iteration | ||
| - Do NOT include general repository information unless directly relevant to the query | ||
| - Focus EXCLUSIVELY on the specific topic being researched - do not drift to related topics | ||
| - If the topic is about a specific file or feature (like "Dockerfile"), focus ONLY on that file or feature | ||
| - NEVER respond with just "Continue the research" as an answer - always provide substantive research findings | ||
| - Your research MUST directly address the original question | ||
| - Maintain continuity with previous research iterations - this is a continuous investigation | ||
| </guidelines> | ||
|
|
||
| <style> | ||
| - Be concise but thorough | ||
| - Focus on providing new information, not repeating what's already been covered | ||
| - Use markdown formatting to improve readability | ||
| - Cite specific files and code sections when relevant | ||
| </style>""" | ||
| system_prompt = DEEP_RESEARCH_INTERMEDIATE_ITERATION_PROMPT.format( | ||
| repo_type=repo_type, | ||
| repo_url=repo_url, | ||
| repo_name=repo_name, | ||
| research_iteration=research_iteration, | ||
| language_name=language_name | ||
| ) | ||
|
Comment on lines
+288
to
+294
Contributor
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. There is an issue with how
Contributor
Author
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. fixed in 075fbd5 |
||
| else: | ||
| system_prompt = f"""<role> | ||
| You are an expert code analyst examining the {repo_type} repository: {repo_url} ({repo_name}). | ||
| You provide direct, concise, and accurate information about code repositories. | ||
| You NEVER start responses with markdown headers or code fences. | ||
| IMPORTANT:You MUST respond in {language_name} language. | ||
| </role> | ||
|
|
||
| <guidelines> | ||
| - Answer the user's question directly without ANY preamble or filler phrases | ||
| - DO NOT include any rationale, explanation, or extra comments. | ||
| - Strictly base answers ONLY on existing code or documents | ||
| - DO NOT speculate or invent citations. | ||
| - DO NOT start with preambles like "Okay, here's a breakdown" or "Here's an explanation" | ||
| - DO NOT start with markdown headers like "## Analysis of..." or any file path references | ||
| - DO NOT start with ```markdown code fences | ||
| - DO NOT end your response with ``` closing fences | ||
| - DO NOT start by repeating or acknowledging the question | ||
| - JUST START with the direct answer to the question | ||
|
|
||
| <example_of_what_not_to_do> | ||
| ```markdown | ||
| ## Analysis of `adalflow/adalflow/datasets/gsm8k.py` | ||
|
|
||
| This file contains... | ||
| ``` | ||
| </example_of_what_not_to_do> | ||
|
|
||
| - Format your response with proper markdown including headings, lists, and code blocks WITHIN your answer | ||
| - For code analysis, organize your response with clear sections | ||
| - Think step by step and structure your answer logically | ||
| - Start with the most relevant information that directly addresses the user's query | ||
| - Be precise and technical when discussing code | ||
| - Your response language should be in the same language as the user's query | ||
| </guidelines> | ||
|
|
||
| <style> | ||
| - Use concise, direct language | ||
| - Prioritize accuracy over verbosity | ||
| - When showing code, include line numbers and file paths when relevant | ||
| - Use markdown formatting to improve readability | ||
| </style>""" | ||
| system_prompt = SIMPLE_CHAT_SYSTEM_PROMPT.format( | ||
| repo_type=repo_type, | ||
| repo_url=repo_url, | ||
| repo_name=repo_name, | ||
| language_name=language_name | ||
| ) | ||
|
|
||
| # Fetch file content if provided | ||
| file_content = "" | ||
|
|
||
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
DEEP_RESEARCH_FINAL_ITERATION_PROMPTtemplate inapi/prompts.pydoes not contain a{research_iteration}placeholder. Passingresearch_iterationto.format()here is redundant and can be removed to keep the code clean.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.
fixed in 075fbd5