nananie143 commited on
Commit
189fe15
·
1 Parent(s): c9a9197

Fixed token length issues and optimized prompts

Browse files
Files changed (1) hide show
  1. app.py +50 -107
app.py CHANGED
@@ -59,10 +59,15 @@ def get_llm():
59
  "text-generation",
60
  model=model,
61
  tokenizer=tokenizer,
62
- max_length=500,
 
63
  temperature=0.7,
 
 
 
 
 
64
  )
65
- llm = HuggingFacePipeline(pipeline=hf_pipeline)
66
  return llm
67
  except Exception as e:
68
  logger.error(f"Failed to get LLM: {str(e)}")
@@ -809,130 +814,68 @@ class EnhancedAIFlow(AIFlow):
809
  context = self.contexts[role]
810
  dependencies_output = []
811
 
812
- # Gather outputs from dependencies
813
  for dep_role in context.dependencies:
814
  dep_context = self.contexts[dep_role]
815
  if dep_context.state == FlowState.COMPLETED and "output" in dep_context.artifacts:
816
- dependencies_output.append(f"## {dep_role.value} Output:\n{dep_context.artifacts['output']}")
 
 
 
817
 
818
- # Build role-specific prompts
819
  role_prompts = {
820
- AgentRole.ARCHITECT: """You are a Software Architect. Design the high-level architecture for:
821
- Requirements:
822
- {requirements}
823
-
824
- Focus on:
825
- 1. Overall system design
826
- 2. Component interactions
827
- 3. Technology stack
828
- 4. Data flow
829
- 5. Scalability considerations""",
830
 
831
- AgentRole.UI_DESIGNER: """You are a UI/UX Designer. Design the user interface for:
832
- Requirements:
833
- {requirements}
834
-
835
- Previous Designs:
836
- {dependencies}
837
-
838
- Focus on:
839
- 1. User experience
840
- 2. Component layout
841
- 3. Responsive design
842
- 4. Visual hierarchy
843
- 5. Accessibility""",
844
 
845
- AgentRole.BACKEND_DEVELOPER: """You are a Backend Developer. Implement the server-side logic for:
846
- Requirements:
847
- {requirements}
848
-
849
- Architecture:
850
- {dependencies}
851
-
852
- Focus on:
853
- 1. API design
854
- 2. Business logic
855
- 3. Data validation
856
- 4. Error handling
857
- 5. Performance""",
858
 
859
- AgentRole.DATABASE_ENGINEER: """You are a Database Engineer. Design the data layer for:
860
- Requirements:
861
- {requirements}
862
-
863
- System Context:
864
- {dependencies}
865
-
866
- Focus on:
867
- 1. Schema design
868
- 2. Data relationships
869
- 3. Indexing strategy
870
- 4. Query optimization
871
- 5. Data integrity""",
872
 
873
- AgentRole.SECURITY_EXPERT: """You are a Security Expert. Review and enhance security for:
874
- Requirements:
875
- {requirements}
876
-
877
- System Context:
878
- {dependencies}
879
-
880
- Focus on:
881
- 1. Authentication
882
- 2. Authorization
883
- 3. Data protection
884
- 4. Security best practices
885
- 5. Compliance requirements""",
886
 
887
- AgentRole.QA_ENGINEER: """You are a QA Engineer. Design the testing strategy for:
888
- Requirements:
889
- {requirements}
890
-
891
- Implementation Details:
892
- {dependencies}
893
-
894
- Focus on:
895
- 1. Test coverage
896
- 2. Test automation
897
- 3. Edge cases
898
- 4. Performance testing
899
- 5. Security testing""",
900
 
901
- AgentRole.DEVOPS_ENGINEER: """You are a DevOps Engineer. Set up the deployment pipeline for:
902
- Requirements:
903
- {requirements}
904
-
905
- System Context:
906
- {dependencies}
907
-
908
- Focus on:
909
- 1. CI/CD pipeline
910
- 2. Infrastructure as code
911
- 3. Monitoring
912
- 4. Scaling
913
- 5. Disaster recovery""",
914
 
915
- AgentRole.DOCUMENTATION_WRITER: """You are a Technical Writer. Create comprehensive documentation for:
916
- Requirements:
917
- {requirements}
918
-
919
- System Details:
920
- {dependencies}
921
-
922
- Focus on:
923
- 1. Setup instructions
924
- 2. API documentation
925
- 3. User guides
926
- 4. Architecture overview
927
- 5. Troubleshooting guides"""
928
  }
929
 
930
  # Get the base prompt for the role
931
  base_prompt = role_prompts.get(role, "")
932
 
 
 
 
 
 
933
  # Format the prompt with requirements and dependencies
934
  formatted_prompt = base_prompt.format(
935
- requirements=self.requirements,
936
  dependencies="\n\n".join(dependencies_output) if dependencies_output else "No previous context available."
937
  )
938
 
 
59
  "text-generation",
60
  model=model,
61
  tokenizer=tokenizer,
62
+ max_new_tokens=500,
63
+ pad_token_id=tokenizer.eos_token_id,
64
  temperature=0.7,
65
+ return_full_text=False,
66
+ )
67
+ llm = HuggingFacePipeline(
68
+ pipeline=hf_pipeline,
69
+ model_kwargs={"max_length": 2048}
70
  )
 
71
  return llm
72
  except Exception as e:
73
  logger.error(f"Failed to get LLM: {str(e)}")
 
814
  context = self.contexts[role]
815
  dependencies_output = []
816
 
817
+ # Gather outputs from dependencies (limited to last 1000 chars)
818
  for dep_role in context.dependencies:
819
  dep_context = self.contexts[dep_role]
820
  if dep_context.state == FlowState.COMPLETED and "output" in dep_context.artifacts:
821
+ output = dep_context.artifacts['output']
822
+ if len(output) > 1000:
823
+ output = output[:997] + "..."
824
+ dependencies_output.append(f"## {dep_role.value} Output:\n{output}")
825
 
826
+ # Build role-specific prompts (with size limits)
827
  role_prompts = {
828
+ AgentRole.ARCHITECT: """Design the high-level architecture (brief overview):
829
+ Requirements: {requirements}
830
+ Focus: system design, components, tech stack, data flow, scalability""",
 
 
 
 
 
 
 
831
 
832
+ AgentRole.UI_DESIGNER: """Design the UI (key elements):
833
+ Requirements: {requirements}
834
+ Previous: {dependencies}
835
+ Focus: UX, layout, responsiveness, themes""",
 
 
 
 
 
 
 
 
 
836
 
837
+ AgentRole.BACKEND_DEVELOPER: """Implement core backend logic:
838
+ Requirements: {requirements}
839
+ Architecture: {dependencies}
840
+ Focus: API, business logic, validation""",
 
 
 
 
 
 
 
 
 
841
 
842
+ AgentRole.DATABASE_ENGINEER: """Design data layer:
843
+ Requirements: {requirements}
844
+ Context: {dependencies}
845
+ Focus: schema, relationships, optimization""",
 
 
 
 
 
 
 
 
 
846
 
847
+ AgentRole.SECURITY_EXPERT: """Review security:
848
+ Requirements: {requirements}
849
+ Context: {dependencies}
850
+ Focus: auth, data protection, best practices""",
 
 
 
 
 
 
 
 
 
851
 
852
+ AgentRole.QA_ENGINEER: """Design testing:
853
+ Requirements: {requirements}
854
+ Implementation: {dependencies}
855
+ Focus: coverage, automation, edge cases""",
 
 
 
 
 
 
 
 
 
856
 
857
+ AgentRole.DEVOPS_ENGINEER: """Setup deployment:
858
+ Requirements: {requirements}
859
+ Context: {dependencies}
860
+ Focus: CI/CD, infrastructure, monitoring""",
 
 
 
 
 
 
 
 
 
861
 
862
+ AgentRole.DOCUMENTATION_WRITER: """Create docs:
863
+ Requirements: {requirements}
864
+ System: {dependencies}
865
+ Focus: setup, API docs, guides"""
 
 
 
 
 
 
 
 
 
866
  }
867
 
868
  # Get the base prompt for the role
869
  base_prompt = role_prompts.get(role, "")
870
 
871
+ # Truncate requirements if too long
872
+ requirements = self.requirements
873
+ if len(requirements) > 1000:
874
+ requirements = requirements[:997] + "..."
875
+
876
  # Format the prompt with requirements and dependencies
877
  formatted_prompt = base_prompt.format(
878
+ requirements=requirements,
879
  dependencies="\n\n".join(dependencies_output) if dependencies_output else "No previous context available."
880
  )
881