mirror of
https://github.com/thecyberlearn/quantum-ai-v2.git
synced 2026-08-18 13:52:59 +00:00
- Create complete 5 Whys Analysis Agent with chat-based interaction - Implement dual-mode processor (free chat vs paid report generation) - Add typing indicators with animated dots for better user feedback - Enable report generation only after 2+ questions for smart activation - Simplify report form to button-only interface using chat history - Add basic formatting for professional report presentation - Configure conditional wallet deduction (charge only for final reports) - Set up N8N webhook integration for analysis processing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
71 lines
2.7 KiB
Python
71 lines
2.7 KiB
Python
from django.db import models
|
|
from decimal import Decimal
|
|
from agent_base.models import BaseAgentRequest, BaseAgentResponse
|
|
import uuid
|
|
|
|
|
|
class FiveWhysAnalyzerRequest(BaseAgentRequest):
|
|
"""5 Whys Analysis Agent request tracking with chat support"""
|
|
|
|
# Chat session management
|
|
session_id = models.CharField(max_length=100, default=uuid.uuid4, db_index=True)
|
|
|
|
# Chat interaction tracking
|
|
chat_messages = models.JSONField(default=list, help_text="Store chat history as list of messages")
|
|
|
|
# Final report fields (only filled when report is generated)
|
|
problem_statement = models.TextField(blank=True, help_text="Main problem to analyze")
|
|
context_info = models.TextField(blank=True, help_text="Additional context information")
|
|
analysis_depth = models.CharField(
|
|
max_length=20,
|
|
blank=True,
|
|
choices=[
|
|
('standard', 'Standard 5 Whys'),
|
|
('detailed', 'Extended Analysis'),
|
|
('comprehensive', 'Comprehensive Report')
|
|
],
|
|
default='standard'
|
|
)
|
|
|
|
# Chat vs Report tracking
|
|
report_generated = models.BooleanField(default=False, help_text="Has final report been generated and paid for")
|
|
chat_active = models.BooleanField(default=True, help_text="Is chat session still active")
|
|
|
|
# Legacy field for compatibility
|
|
input_text = models.TextField(blank=True)
|
|
|
|
class Meta:
|
|
db_table = 'five_whys_analyzer_requests'
|
|
verbose_name = '5 Whys Analysis Agent Request'
|
|
verbose_name_plural = '5 Whys Analysis Agent Requests'
|
|
indexes = [
|
|
models.Index(fields=['session_id']),
|
|
models.Index(fields=['user', 'chat_active']),
|
|
]
|
|
|
|
|
|
class FiveWhysAnalyzerResponse(BaseAgentResponse):
|
|
"""5 Whys Analysis Agent response storage"""
|
|
|
|
request = models.OneToOneField(
|
|
FiveWhysAnalyzerRequest,
|
|
on_delete=models.CASCADE,
|
|
related_name='response'
|
|
)
|
|
|
|
# Chat responses (free interactions)
|
|
chat_response = models.TextField(blank=True, help_text="Latest chat response")
|
|
chat_history = models.JSONField(default=list, help_text="Full chat response history")
|
|
|
|
# Final report (paid interaction)
|
|
final_report = models.TextField(blank=True, help_text="Generated 5 Whys analysis report")
|
|
report_metadata = models.JSONField(default=dict, help_text="Report generation metadata")
|
|
|
|
# Legacy fields for compatibility
|
|
output_text = models.TextField(blank=True)
|
|
raw_response = models.JSONField(default=dict, blank=True)
|
|
|
|
class Meta:
|
|
db_table = 'five_whys_analyzer_responses'
|
|
verbose_name = '5 Whys Analysis Agent Response'
|
|
verbose_name_plural = '5 Whys Analysis Agent Responses' |