-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: add user requirements analysis feature #31
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e7e5741
feat: add user requirements analysis feature
64a504c
update user requirements analysis functionality: requirement report e…
fa0cb5a
Fixed a vulnerability and a design bug in a button.
a4b5ca7
Merge branch 'main' into feat/user-requirements-analysis
Zongwei9888 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ __pycache__/ | |
| .venv/ | ||
| env/ | ||
| venv/ | ||
| *.env* | ||
| *.env | ||
| .env_example | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| """ | ||
|
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. 建议在模块级别添加详细的文档字符串,说明该模块包含的提示词模板及其用途。 |
||
| User requirement analysis related prompt templates | ||
|
|
||
| Contains prompt templates for requirement analysis Agent, supporting question generation and requirement summarization functions. | ||
| """ | ||
|
|
||
| # ======================================== | ||
| # User requirement analysis related prompt templates | ||
| # ======================================== | ||
|
|
||
| REQUIREMENT_QUESTION_GENERATION_PROMPT = """You are a professional requirement analysis expert, skilled at helping users refine project requirements through precise questions. | ||
|
|
||
| Please generate 1-3 precise guiding questions based on user's initial requirement description to help users provide more detailed information. | ||
|
|
||
| User Initial Requirements: | ||
| {user_input} | ||
|
|
||
| Please generate a JSON format question list, each question contains the following fields: | ||
| - category: Question category (such as "Functional Requirements", "Technology Selection", "Performance Requirements", "User Interface", "Deployment Environment", etc.) | ||
| - question: Specific question content | ||
| - importance: Importance level ("High", "Medium", "Low") | ||
| - hint: Question hint or example (optional) | ||
|
|
||
| Requirements: | ||
| 1. Questions should be highly targeted, based on user's specific requirement scenarios | ||
| 2. Cover key decision points for project implementation | ||
| 3. Avoid overly technical questions, maintain user-friendliness | ||
| 4. Questions should have logical correlation | ||
| 5. Ensure questions help users think about important details they might have missed | ||
|
|
||
| Please return JSON format results directly, without including other text descriptions.""" | ||
|
|
||
| REQUIREMENT_SUMMARY_PROMPT = """You are a professional technical requirement analyst, skilled at converting user requirement descriptions into detailed technical specification documents. | ||
|
|
||
| Please generate a detailed project requirement document based on user's initial requirements and supplementary responses. | ||
|
|
||
| User Initial Requirements: | ||
| {initial_input} | ||
|
|
||
| User Supplementary Responses: | ||
| {answers_text} | ||
|
|
||
| Please generate a concise requirement document focusing on the following core sections: | ||
|
|
||
| ## Project Overview | ||
| Brief description of project's core goals and value proposition | ||
|
|
||
| ## Functional Requirements | ||
| Detailed list of required features and functional modules: | ||
| - Core functionalities | ||
| - User interactions and workflows | ||
| - Data processing requirements | ||
| - Integration needs | ||
|
|
||
| ## Technical Architecture | ||
| Recommended technical design including: | ||
| - Technology stack and frameworks | ||
| - System architecture design | ||
| - Database and data storage solutions | ||
| - API design considerations | ||
| - Security requirements | ||
|
|
||
| ## Performance & Scalability | ||
| - Expected user scale and performance requirements | ||
| - Scalability considerations and constraints | ||
|
|
||
| Requirements: | ||
| 1. Focus on what needs to be built and how to build it technically | ||
| 2. Be concise but comprehensive - avoid unnecessary implementation details | ||
| 3. Provide clear functional specifications and technical architecture guidance | ||
| 4. Consider project feasibility and technical complexity""" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -882,6 +882,199 @@ def background_progress_callback(progress: int, message: str): | |
| } | ||
|
|
||
|
|
||
| async def handle_requirement_analysis_workflow( | ||
|
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. 建议添加更多的日志记录,特别是在异常处理部分,以方便调试和问题追踪。 |
||
| user_input: str, | ||
| analysis_mode: str, | ||
| user_answers: Dict[str, str] = None | ||
| ) -> Dict[str, Any]: | ||
| """ | ||
| Handle requirement analysis workflow | ||
|
|
||
| Args: | ||
| user_input: User initial requirements | ||
| analysis_mode: Analysis mode ("generate_questions" or "summarize_requirements") | ||
| user_answers: User answer dictionary | ||
|
|
||
| Returns: | ||
| Processing result dictionary | ||
| """ | ||
| try: | ||
| # Import required modules | ||
| from workflows.agent_orchestration_engine import execute_requirement_analysis_workflow | ||
|
|
||
| # Create progress callback function | ||
| def update_progress(progress: int, message: str): | ||
| # Display progress in Streamlit | ||
| st.session_state.current_progress = progress | ||
| st.session_state.current_message = message | ||
|
|
||
| # Execute requirement analysis workflow | ||
| result = await execute_requirement_analysis_workflow( | ||
| user_input=user_input, | ||
| analysis_mode=analysis_mode, | ||
| user_answers=user_answers, | ||
| logger=None, # Can pass in logger | ||
| progress_callback=update_progress | ||
| ) | ||
|
|
||
| return result | ||
|
|
||
| except Exception as e: | ||
| return { | ||
| "status": "error", | ||
| "error": str(e), | ||
| "message": f"Requirement analysis workflow execution failed: {str(e)}" | ||
| } | ||
|
|
||
|
|
||
| async def handle_requirement_modification_workflow( | ||
| current_requirements: str, | ||
| modification_feedback: str | ||
| ) -> Dict[str, Any]: | ||
| """ | ||
| Handle requirement modification workflow | ||
|
|
||
| Args: | ||
| current_requirements: Current requirement document content | ||
| modification_feedback: User's modification requests and feedback | ||
|
|
||
| Returns: | ||
| Processing result dictionary | ||
| """ | ||
| try: | ||
| # Import required modules | ||
| from workflows.agents.requirement_analysis_agent import RequirementAnalysisAgent | ||
| from utils.llm_utils import get_preferred_llm_class | ||
|
|
||
| # Create progress callback function | ||
| def update_progress(progress: int, message: str): | ||
| # Display progress in Streamlit | ||
| st.session_state.current_progress = progress | ||
| st.session_state.current_message = message | ||
|
|
||
| update_progress(10, "🔧 Initializing requirement modification agent...") | ||
|
|
||
| # Initialize RequirementAnalysisAgent | ||
| agent = RequirementAnalysisAgent() | ||
|
|
||
| # Initialize agent (LLM is initialized internally) | ||
| await agent.initialize() | ||
|
|
||
| update_progress(50, "✏️ Modifying requirements based on your feedback...") | ||
|
|
||
| # Modify requirements | ||
| result = await agent.modify_requirements( | ||
| current_requirements=current_requirements, | ||
| modification_feedback=modification_feedback | ||
| ) | ||
|
|
||
| # Cleanup | ||
| await agent.cleanup() | ||
|
|
||
| update_progress(100, "✅ Requirements modification completed!") | ||
|
|
||
| return { | ||
| "status": "success", | ||
| "result": result, | ||
| "message": "Requirements modification completed successfully" | ||
| } | ||
|
|
||
| except Exception as e: | ||
| return { | ||
| "status": "error", | ||
| "error": str(e), | ||
| "message": f"Requirements modification workflow execution failed: {str(e)}" | ||
| } | ||
|
|
||
|
|
||
| def handle_guided_mode_processing(): | ||
| """Handle asynchronous processing for guided mode""" | ||
| # Check if questions need to be generated | ||
| if st.session_state.get("questions_generating", False): | ||
| st.session_state.questions_generating = False | ||
|
|
||
| # Asynchronously generate questions | ||
| initial_req = st.session_state.get("initial_requirement", "") | ||
| if initial_req: | ||
| try: | ||
| # Use asynchronous processing to generate questions | ||
| result = run_async_task_simple( | ||
| handle_requirement_analysis_workflow( | ||
| user_input=initial_req, | ||
| analysis_mode="generate_questions" | ||
| ) | ||
| ) | ||
|
|
||
| if result["status"] == "success": | ||
| # Parse JSON result | ||
| import json | ||
| questions = json.loads(result["result"]) | ||
| st.session_state.generated_questions = questions | ||
| else: | ||
| st.error(f"Question generation failed: {result.get('error', 'Unknown error')}") | ||
|
|
||
| except Exception as e: | ||
| st.error(f"Question generation exception: {str(e)}") | ||
|
|
||
| # Check if detailed requirements need to be generated | ||
| if st.session_state.get("requirements_generating", False): | ||
| st.session_state.requirements_generating = False | ||
|
|
||
| # Asynchronously generate detailed requirements | ||
| initial_req = st.session_state.get("initial_requirement", "") | ||
| user_answers = st.session_state.get("user_answers", {}) | ||
|
|
||
| if initial_req: | ||
| try: | ||
| # Use asynchronous processing to generate requirement summary | ||
| result = run_async_task_simple( | ||
| handle_requirement_analysis_workflow( | ||
| user_input=initial_req, | ||
| analysis_mode="summarize_requirements", | ||
| user_answers=user_answers | ||
| ) | ||
| ) | ||
|
|
||
| if result["status"] == "success": | ||
| st.session_state.detailed_requirements = result["result"] | ||
| else: | ||
| st.error(f"Requirement summary generation failed: {result.get('error', 'Unknown error')}") | ||
|
|
||
| except Exception as e: | ||
| st.error(f"Requirement summary generation exception: {str(e)}") | ||
|
|
||
| # Check if requirements need to be edited | ||
| if st.session_state.get("requirements_editing", False): | ||
| st.session_state.requirements_editing = False | ||
| st.info("🔧 Starting requirement modification process...") | ||
|
|
||
| # Asynchronously modify requirements based on user feedback | ||
| current_requirements = st.session_state.get("detailed_requirements", "") | ||
| edit_feedback = st.session_state.get("edit_feedback", "") | ||
|
|
||
| if current_requirements and edit_feedback: | ||
| try: | ||
| # Use asynchronous processing to modify requirements | ||
| result = run_async_task_simple( | ||
| handle_requirement_modification_workflow( | ||
| current_requirements=current_requirements, | ||
| modification_feedback=edit_feedback | ||
| ) | ||
| ) | ||
|
|
||
| if result["status"] == "success": | ||
| st.session_state.detailed_requirements = result["result"] | ||
| st.session_state.requirement_analysis_step = "summary" | ||
| st.session_state.edit_feedback = "" | ||
| st.success("✅ Requirements updated successfully!") | ||
| st.rerun() | ||
| else: | ||
| st.error(f"Requirements modification failed: {result.get('error', 'Unknown error')}") | ||
|
|
||
| except Exception as e: | ||
| st.error(f"Requirements modification exception: {str(e)}") | ||
|
|
||
|
|
||
| def handle_start_processing_button(input_source: str, input_type: str): | ||
| """ | ||
| Handle start processing button click - synchronous execution | ||
|
|
@@ -1034,6 +1227,30 @@ def initialize_session_state(): | |
| st.session_state.enable_indexing = ( | ||
| False # Default enable indexing functionality | ||
| ) | ||
|
|
||
| # Requirement analysis related states | ||
| if "requirement_analysis_mode" not in st.session_state: | ||
| st.session_state.requirement_analysis_mode = "direct" # direct/guided | ||
| if "requirement_analysis_step" not in st.session_state: | ||
| st.session_state.requirement_analysis_step = "input" # input/questions/summary | ||
| if "generated_questions" not in st.session_state: | ||
| st.session_state.generated_questions = [] | ||
| if "user_answers" not in st.session_state: | ||
| st.session_state.user_answers = {} | ||
| if "detailed_requirements" not in st.session_state: | ||
| st.session_state.detailed_requirements = "" | ||
| if "initial_requirement" not in st.session_state: | ||
| st.session_state.initial_requirement = "" | ||
| if "questions_generating" not in st.session_state: | ||
| st.session_state.questions_generating = False | ||
| if "requirements_generating" not in st.session_state: | ||
| st.session_state.requirements_generating = False | ||
| if "requirements_confirmed" not in st.session_state: | ||
| st.session_state.requirements_confirmed = False | ||
| if "edit_feedback" not in st.session_state: | ||
| st.session_state.edit_feedback = "" | ||
| if "requirements_editing" not in st.session_state: | ||
| st.session_state.requirements_editing = False | ||
|
|
||
| # Requirement analysis related states | ||
| if "requirement_analysis_mode" not in st.session_state: | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
建议在注释中添加新提示词的具体用途和使用场景,以方便其他开发者理解和维护。