Spaces:
Sleeping
Sleeping
Commit
·
f3a5a1f
1
Parent(s):
ef1ba2b
Upd Deepseek agent task assignment
Browse files- AGENT_ASNM.md +143 -0
- README.md +4 -1
- memo/consolidation.py +3 -8
- memo/plan/__pycache__/execution.cpython-311.pyc +0 -0
- memo/plan/__pycache__/intent.cpython-311.pyc +0 -0
- memo/plan/__pycache__/strategy.cpython-311.pyc +0 -0
- memo/plan/execution.py +3 -8
- memo/plan/intent.py +3 -8
- memo/retrieval.py +9 -24
- routes/chats.py +3 -3
- utils/api/router.py +38 -11
AGENT_ASNM.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Task Assignment Review - Corrected Model Hierarchy
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
This document summarizes the corrected task assignments to ensure proper model hierarchy:
|
| 5 |
+
- **Easy tasks** (immediate execution, simple) → **Llama** (NVIDIA small)
|
| 6 |
+
- **Medium tasks** (accurate, reasoning, not too time-consuming) → **DeepSeek**
|
| 7 |
+
- **Hard tasks** (complex analysis, synthesis, long-form) → **Gemini Pro**
|
| 8 |
+
|
| 9 |
+
## Corrected Task Assignments
|
| 10 |
+
|
| 11 |
+
### ✅ **Easy Tasks - Llama (NVIDIA Small)**
|
| 12 |
+
**Purpose**: Immediate execution, simple operations
|
| 13 |
+
**Current Assignments**:
|
| 14 |
+
- `llama_chat()` - Basic chat completion
|
| 15 |
+
- `llama_summarize()` - Simple text summarization
|
| 16 |
+
- `summarize_qa()` - Basic Q&A summarization
|
| 17 |
+
- `naive_fallback()` - Simple text processing fallback
|
| 18 |
+
|
| 19 |
+
### ✅ **Medium Tasks - DeepSeek**
|
| 20 |
+
**Purpose**: Accurate reasoning, not too time-consuming
|
| 21 |
+
**Corrected Assignments**:
|
| 22 |
+
|
| 23 |
+
#### **Search Operations** (`routes/search.py`)
|
| 24 |
+
- `extract_search_keywords()` - Keyword extraction with reasoning
|
| 25 |
+
- `generate_search_strategies()` - Search strategy generation
|
| 26 |
+
- `extract_relevant_content()` - Content relevance filtering
|
| 27 |
+
- `assess_content_quality()` - Quality assessment with reasoning
|
| 28 |
+
- `cross_validate_information()` - Fact-checking and validation
|
| 29 |
+
- `generate_content_summary()` - Content summarization
|
| 30 |
+
|
| 31 |
+
#### **Memory Operations** (`memo/`)
|
| 32 |
+
- `files_relevance()` - File relevance classification
|
| 33 |
+
- `related_recent_context()` - Context selection with reasoning
|
| 34 |
+
- `_ai_intent_detection()` - User intent detection (CORRECTED)
|
| 35 |
+
- `_ai_select_qa_memories()` - Memory selection with reasoning (CORRECTED)
|
| 36 |
+
- `_should_enhance_with_context()` - Context enhancement decision (CORRECTED)
|
| 37 |
+
- `_enhance_question_with_context()` - Question enhancement (CORRECTED)
|
| 38 |
+
- `_enhance_instructions_with_context()` - Instruction enhancement (CORRECTED)
|
| 39 |
+
- `consolidate_similar_memories()` - Memory consolidation (CORRECTED)
|
| 40 |
+
|
| 41 |
+
#### **Content Processing** (`utils/service/summarizer.py`)
|
| 42 |
+
- `clean_chunk_text()` - Content cleaning with reasoning
|
| 43 |
+
- `deepseek_summarize()` - Medium complexity summarization
|
| 44 |
+
|
| 45 |
+
#### **Chat Operations** (`routes/chats.py`)
|
| 46 |
+
- `generate_query_variations()` - Query variation generation (CORRECTED)
|
| 47 |
+
|
| 48 |
+
### ✅ **Hard Tasks - Gemini Pro**
|
| 49 |
+
**Purpose**: Complex analysis, synthesis, long-form content
|
| 50 |
+
**Current Assignments**:
|
| 51 |
+
- `generate_cot_plan()` - Chain of Thought report planning
|
| 52 |
+
- `analyze_subtask_comprehensive()` - Comprehensive analysis
|
| 53 |
+
- `synthesize_section_analysis()` - Complex synthesis
|
| 54 |
+
- `generate_final_report()` - Long-form report generation
|
| 55 |
+
- All complex report generation tasks
|
| 56 |
+
|
| 57 |
+
## Key Corrections Made
|
| 58 |
+
|
| 59 |
+
### 1. **Intent Detection** (`memo/plan/intent.py`)
|
| 60 |
+
- **Before**: Used Llama for simple classification
|
| 61 |
+
- **After**: Uses DeepSeek for better reasoning about user intent
|
| 62 |
+
- **Reason**: Requires understanding context and nuance
|
| 63 |
+
|
| 64 |
+
### 2. **Memory Selection** (`memo/plan/execution.py`)
|
| 65 |
+
- **Before**: Used Llama for memory selection
|
| 66 |
+
- **After**: Uses DeepSeek for better reasoning about relevance
|
| 67 |
+
- **Reason**: Requires understanding context relationships
|
| 68 |
+
|
| 69 |
+
### 3. **Context Enhancement** (`memo/retrieval.py`)
|
| 70 |
+
- **Before**: Used Llama for enhancement decisions
|
| 71 |
+
- **After**: Uses DeepSeek for better reasoning about context value
|
| 72 |
+
- **Reason**: Requires understanding question-context relationships
|
| 73 |
+
|
| 74 |
+
### 4. **Question Enhancement** (`memo/retrieval.py`)
|
| 75 |
+
- **Before**: Used Llama for question enhancement
|
| 76 |
+
- **After**: Uses DeepSeek for better reasoning about enhancement
|
| 77 |
+
- **Reason**: Requires understanding conversation flow and context
|
| 78 |
+
|
| 79 |
+
### 5. **Memory Consolidation** (`memo/consolidation.py`)
|
| 80 |
+
- **Before**: Used Llama for memory consolidation
|
| 81 |
+
- **After**: Uses DeepSeek for better reasoning about similarity
|
| 82 |
+
- **Reason**: Requires understanding content relationships
|
| 83 |
+
|
| 84 |
+
### 6. **Query Variation Generation** (`routes/chats.py`)
|
| 85 |
+
- **Before**: Used Llama for query variations
|
| 86 |
+
- **After**: Uses DeepSeek for better reasoning about variations
|
| 87 |
+
- **Reason**: Requires understanding question intent and context
|
| 88 |
+
|
| 89 |
+
## Enhanced Model Selection Logic
|
| 90 |
+
|
| 91 |
+
### **Complexity Heuristics**
|
| 92 |
+
```python
|
| 93 |
+
# Hard tasks (Gemini Pro)
|
| 94 |
+
- Keywords: "prove", "derivation", "complexity", "algorithm", "optimize", "theorem", "rigorous", "step-by-step", "policy critique", "ambiguity", "counterfactual", "comprehensive", "detailed analysis", "synthesis", "evaluation"
|
| 95 |
+
- Length: > 100 words or > 3000 context words
|
| 96 |
+
- Content: "comprehensive" or "detailed" in question
|
| 97 |
+
|
| 98 |
+
# Medium tasks (DeepSeek)
|
| 99 |
+
- Keywords: "analyze", "explain", "compare", "evaluate", "summarize", "extract", "classify", "identify", "describe", "discuss", "reasoning", "context", "enhance", "select", "consolidate"
|
| 100 |
+
- Length: 10-100 words or 200-3000 context words
|
| 101 |
+
- Content: "reasoning" or "context" in question
|
| 102 |
+
|
| 103 |
+
# Simple tasks (Llama)
|
| 104 |
+
- Keywords: "what", "how", "when", "where", "who", "yes", "no", "count", "list", "find"
|
| 105 |
+
- Length: ≤ 10 words or ≤ 200 context words
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
## Benefits of Corrected Assignments
|
| 109 |
+
|
| 110 |
+
### **Performance Improvements**
|
| 111 |
+
- **Better reasoning** for medium complexity tasks with DeepSeek
|
| 112 |
+
- **Faster execution** for simple tasks with Llama
|
| 113 |
+
- **Higher quality** for complex tasks with Gemini Pro
|
| 114 |
+
|
| 115 |
+
### **Cost Optimization**
|
| 116 |
+
- **Reduced Gemini usage** for tasks that don't need its full capabilities
|
| 117 |
+
- **Better task distribution** across model capabilities
|
| 118 |
+
- **Maintained efficiency** for simple tasks
|
| 119 |
+
|
| 120 |
+
### **Quality Improvements**
|
| 121 |
+
- **Better intent detection** with DeepSeek's reasoning
|
| 122 |
+
- **Improved memory operations** with better context understanding
|
| 123 |
+
- **Enhanced search operations** with better relevance filtering
|
| 124 |
+
- **More accurate content processing** with reasoning capabilities
|
| 125 |
+
|
| 126 |
+
## Verification Checklist
|
| 127 |
+
|
| 128 |
+
- ✅ All easy tasks use Llama (NVIDIA small)
|
| 129 |
+
- ✅ All medium tasks use DeepSeek
|
| 130 |
+
- ✅ All hard tasks use Gemini Pro
|
| 131 |
+
- ✅ Model selection logic properly categorizes tasks
|
| 132 |
+
- ✅ No linting errors in modified files
|
| 133 |
+
- ✅ All functions have proper fallback mechanisms
|
| 134 |
+
- ✅ Error handling is maintained for all changes
|
| 135 |
+
|
| 136 |
+
## Configuration
|
| 137 |
+
|
| 138 |
+
The system is ready to use with the environment variable:
|
| 139 |
+
```bash
|
| 140 |
+
NVIDIA_MEDIUM=deepseek-ai/deepseek-v3.1
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
All changes maintain backward compatibility and include proper error handling.
|
README.md
CHANGED
|
@@ -82,7 +82,7 @@ Open: `http://localhost:8000/static/` • Health: `GET /healthz`
|
|
| 82 |
- PDF export renders code blocks with a dark IDE-like theme and lightweight syntax highlighting; control characters are stripped to avoid square artifacts.
|
| 83 |
- CORS is open for the demo UI; restrict for production.
|
| 84 |
|
| 85 |
-
###
|
| 86 |
|
| 87 |
[Report Generation](https://huggingface.co/spaces/BinKhoaLe1812/EdSummariser/blob/main/report.pdf)
|
| 88 |
|
|
@@ -90,6 +90,9 @@ Open: `http://localhost:8000/static/` • Health: `GET /healthz`
|
|
| 90 |
|
| 91 |
[Utils Dir](https://huggingface.co/spaces/BinKhoaLe1812/EdSummariser/blob/main/utils/README.md)
|
| 92 |
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
### License
|
| 95 |
|
|
|
|
| 82 |
- PDF export renders code blocks with a dark IDE-like theme and lightweight syntax highlighting; control characters are stripped to avoid square artifacts.
|
| 83 |
- CORS is open for the demo UI; restrict for production.
|
| 84 |
|
| 85 |
+
### Docs
|
| 86 |
|
| 87 |
[Report Generation](https://huggingface.co/spaces/BinKhoaLe1812/EdSummariser/blob/main/report.pdf)
|
| 88 |
|
|
|
|
| 90 |
|
| 91 |
[Utils Dir](https://huggingface.co/spaces/BinKhoaLe1812/EdSummariser/blob/main/utils/README.md)
|
| 92 |
|
| 93 |
+
[Routes Dir](https://huggingface.co/spaces/BinKhoaLe1812/EdSummariser/blob/main/routes/README.md)
|
| 94 |
+
|
| 95 |
+
[Agent Assignment](https://huggingface.co/spaces/BinKhoaLe1812/EdSummariser/blob/main/AGENT_ASNM.md)
|
| 96 |
|
| 97 |
### License
|
| 98 |
|
memo/consolidation.py
CHANGED
|
@@ -179,14 +179,9 @@ Return the consolidated content in the same format as the original memories."""
|
|
| 179 |
|
| 180 |
Create a single consolidated memory:"""
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
system_prompt=sys_prompt,
|
| 186 |
-
user_prompt=user_prompt,
|
| 187 |
-
gemini_rotator=None,
|
| 188 |
-
nvidia_rotator=nvidia_rotator
|
| 189 |
-
)
|
| 190 |
|
| 191 |
return {
|
| 192 |
"content": consolidated_content.strip(),
|
|
|
|
| 179 |
|
| 180 |
Create a single consolidated memory:"""
|
| 181 |
|
| 182 |
+
# Use DeepSeek for better memory consolidation reasoning
|
| 183 |
+
from utils.api.router import deepseek_chat_completion
|
| 184 |
+
consolidated_content = await deepseek_chat_completion(sys_prompt, user_prompt, nvidia_rotator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
return {
|
| 187 |
"content": consolidated_content.strip(),
|
memo/plan/__pycache__/execution.cpython-311.pyc
DELETED
|
Binary file (20.8 kB)
|
|
|
memo/plan/__pycache__/intent.cpython-311.pyc
DELETED
|
Binary file (7.57 kB)
|
|
|
memo/plan/__pycache__/strategy.cpython-311.pyc
DELETED
|
Binary file (6.17 kB)
|
|
|
memo/plan/execution.py
CHANGED
|
@@ -349,14 +349,9 @@ Available Q&A Memories:
|
|
| 349 |
|
| 350 |
Select the most relevant Q&A memories:"""
|
| 351 |
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
system_prompt=sys_prompt,
|
| 356 |
-
user_prompt=user_prompt,
|
| 357 |
-
gemini_rotator=None,
|
| 358 |
-
nvidia_rotator=nvidia_rotator
|
| 359 |
-
)
|
| 360 |
|
| 361 |
return response.strip()
|
| 362 |
|
|
|
|
| 349 |
|
| 350 |
Select the most relevant Q&A memories:"""
|
| 351 |
|
| 352 |
+
# Use DeepSeek for better memory selection reasoning
|
| 353 |
+
from utils.api.router import deepseek_chat_completion
|
| 354 |
+
response = await deepseek_chat_completion(sys_prompt, user_prompt, nvidia_rotator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
|
| 356 |
return response.strip()
|
| 357 |
|
memo/plan/intent.py
CHANGED
|
@@ -110,14 +110,9 @@ Respond with only the intent name (e.g., "ENHANCEMENT")."""
|
|
| 110 |
|
| 111 |
user_prompt = f"Question: {question}\n\nWhat is the user's intent?"
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
system_prompt=sys_prompt,
|
| 117 |
-
user_prompt=user_prompt,
|
| 118 |
-
gemini_rotator=None,
|
| 119 |
-
nvidia_rotator=nvidia_rotator
|
| 120 |
-
)
|
| 121 |
|
| 122 |
# Parse response
|
| 123 |
response_upper = response.strip().upper()
|
|
|
|
| 110 |
|
| 111 |
user_prompt = f"Question: {question}\n\nWhat is the user's intent?"
|
| 112 |
|
| 113 |
+
# Use DeepSeek for better intent detection reasoning
|
| 114 |
+
from utils.api.router import deepseek_chat_completion
|
| 115 |
+
response = await deepseek_chat_completion(sys_prompt, user_prompt, nvidia_rotator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
# Parse response
|
| 118 |
response_upper = response.strip().upper()
|
memo/retrieval.py
CHANGED
|
@@ -221,14 +221,9 @@ Semantic: {semantic_context[:200]}...
|
|
| 221 |
|
| 222 |
Should this question be enhanced with context?"""
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
system_prompt=sys_prompt,
|
| 228 |
-
user_prompt=user_prompt,
|
| 229 |
-
gemini_rotator=None,
|
| 230 |
-
nvidia_rotator=nvidia_rotator
|
| 231 |
-
)
|
| 232 |
|
| 233 |
return "YES" in response.upper()
|
| 234 |
|
|
@@ -272,14 +267,9 @@ RELEVANT CONTEXT:
|
|
| 272 |
|
| 273 |
Create an enhanced version that incorporates this context naturally."""
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
system_prompt=sys_prompt,
|
| 279 |
-
user_prompt=user_prompt,
|
| 280 |
-
gemini_rotator=None,
|
| 281 |
-
nvidia_rotator=nvidia_rotator
|
| 282 |
-
)
|
| 283 |
|
| 284 |
return enhanced_question.strip(), True
|
| 285 |
|
|
@@ -316,14 +306,9 @@ RELEVANT CONTEXT:
|
|
| 316 |
|
| 317 |
Create an enhanced version that incorporates this context naturally."""
|
| 318 |
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
system_prompt=sys_prompt,
|
| 323 |
-
user_prompt=user_prompt,
|
| 324 |
-
gemini_rotator=None,
|
| 325 |
-
nvidia_rotator=nvidia_rotator
|
| 326 |
-
)
|
| 327 |
|
| 328 |
return enhanced_instructions.strip(), True
|
| 329 |
|
|
|
|
| 221 |
|
| 222 |
Should this question be enhanced with context?"""
|
| 223 |
|
| 224 |
+
# Use DeepSeek for better context enhancement reasoning
|
| 225 |
+
from utils.api.router import deepseek_chat_completion
|
| 226 |
+
response = await deepseek_chat_completion(sys_prompt, user_prompt, nvidia_rotator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
return "YES" in response.upper()
|
| 229 |
|
|
|
|
| 267 |
|
| 268 |
Create an enhanced version that incorporates this context naturally."""
|
| 269 |
|
| 270 |
+
# Use DeepSeek for better question enhancement reasoning
|
| 271 |
+
from utils.api.router import deepseek_chat_completion
|
| 272 |
+
enhanced_question = await deepseek_chat_completion(sys_prompt, user_prompt, nvidia_rotator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
return enhanced_question.strip(), True
|
| 275 |
|
|
|
|
| 306 |
|
| 307 |
Create an enhanced version that incorporates this context naturally."""
|
| 308 |
|
| 309 |
+
# Use DeepSeek for better instruction enhancement reasoning
|
| 310 |
+
from utils.api.router import deepseek_chat_completion
|
| 311 |
+
enhanced_instructions = await deepseek_chat_completion(sys_prompt, user_prompt, nvidia_rotator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
return enhanced_instructions.strip(), True
|
| 314 |
|
routes/chats.py
CHANGED
|
@@ -201,9 +201,9 @@ Return only the variations, one per line, no numbering or extra text."""
|
|
| 201 |
|
| 202 |
user_prompt = f"Original question: {question}\n\nGenerate query variations:"
|
| 203 |
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
response = await
|
| 207 |
|
| 208 |
# Parse variations
|
| 209 |
variations = [line.strip() for line in response.split('\n') if line.strip()]
|
|
|
|
| 201 |
|
| 202 |
user_prompt = f"Original question: {question}\n\nGenerate query variations:"
|
| 203 |
|
| 204 |
+
# Use DeepSeek for better query variation generation reasoning
|
| 205 |
+
from utils.api.router import deepseek_chat_completion
|
| 206 |
+
response = await deepseek_chat_completion(sys_prompt, user_prompt, nvidia_rotator)
|
| 207 |
|
| 208 |
# Parse variations
|
| 209 |
variations = [line.strip() for line in response.split('\n') if line.strip()]
|
utils/api/router.py
CHANGED
|
@@ -17,27 +17,54 @@ NVIDIA_MEDIUM = os.getenv("NVIDIA_MEDIUM", "deepseek-ai/deepseek-v3.1") # DeepS
|
|
| 17 |
|
| 18 |
def select_model(question: str, context: str) -> Dict[str, Any]:
|
| 19 |
"""
|
| 20 |
-
Enhanced complexity heuristic with
|
| 21 |
-
-
|
| 22 |
-
-
|
| 23 |
-
-
|
| 24 |
"""
|
| 25 |
qlen = len(question.split())
|
| 26 |
clen = len(context.split())
|
| 27 |
-
hard_keywords = ("prove", "derivation", "complexity", "algorithm", "optimize", "theorem", "rigorous", "step-by-step", "policy critique", "ambiguity", "counterfactual")
|
| 28 |
-
medium_keywords = ("analyze", "explain", "compare", "evaluate", "summarize", "extract", "classify", "identify", "describe", "discuss")
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
if is_very_hard:
|
| 34 |
-
# Use Gemini Pro for very complex tasks
|
| 35 |
return {"provider": "gemini", "model": GEMINI_PRO}
|
| 36 |
elif is_medium:
|
| 37 |
-
# Use DeepSeek for medium complexity tasks
|
| 38 |
return {"provider": "deepseek", "model": NVIDIA_MEDIUM}
|
| 39 |
else:
|
| 40 |
-
# Use NVIDIA small for simple tasks
|
| 41 |
return {"provider": "nvidia", "model": NVIDIA_SMALL}
|
| 42 |
|
| 43 |
|
|
|
|
| 17 |
|
| 18 |
def select_model(question: str, context: str) -> Dict[str, Any]:
|
| 19 |
"""
|
| 20 |
+
Enhanced complexity heuristic with proper model hierarchy:
|
| 21 |
+
- Easy tasks (immediate execution, simple) -> Llama (NVIDIA small)
|
| 22 |
+
- Medium tasks (accurate, reasoning, not too time-consuming) -> DeepSeek
|
| 23 |
+
- Hard tasks (complex analysis, synthesis, long-form) -> Gemini Pro
|
| 24 |
"""
|
| 25 |
qlen = len(question.split())
|
| 26 |
clen = len(context.split())
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
# Hard task keywords - require complex reasoning and analysis
|
| 29 |
+
hard_keywords = ("prove", "derivation", "complexity", "algorithm", "optimize", "theorem", "rigorous", "step-by-step", "policy critique", "ambiguity", "counterfactual", "comprehensive", "detailed analysis", "synthesis", "evaluation")
|
| 30 |
+
|
| 31 |
+
# Medium task keywords - require reasoning but not too complex
|
| 32 |
+
medium_keywords = ("analyze", "explain", "compare", "evaluate", "summarize", "extract", "classify", "identify", "describe", "discuss", "reasoning", "context", "enhance", "select", "consolidate")
|
| 33 |
+
|
| 34 |
+
# Simple task keywords - immediate execution
|
| 35 |
+
simple_keywords = ("what", "how", "when", "where", "who", "yes", "no", "count", "list", "find")
|
| 36 |
+
|
| 37 |
+
# Determine complexity level
|
| 38 |
+
is_very_hard = (
|
| 39 |
+
any(k in question.lower() for k in hard_keywords) or
|
| 40 |
+
qlen > 100 or
|
| 41 |
+
clen > 3000 or
|
| 42 |
+
"comprehensive" in question.lower() or
|
| 43 |
+
"detailed" in question.lower()
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
is_medium = (
|
| 47 |
+
any(k in question.lower() for k in medium_keywords) or
|
| 48 |
+
(qlen > 10 and qlen <= 100) or
|
| 49 |
+
(clen > 200 and clen <= 3000) or
|
| 50 |
+
"reasoning" in question.lower() or
|
| 51 |
+
"context" in question.lower()
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
is_simple = (
|
| 55 |
+
any(k in question.lower() for k in simple_keywords) or
|
| 56 |
+
qlen <= 10 or
|
| 57 |
+
clen <= 200
|
| 58 |
+
)
|
| 59 |
|
| 60 |
if is_very_hard:
|
| 61 |
+
# Use Gemini Pro for very complex tasks requiring advanced reasoning
|
| 62 |
return {"provider": "gemini", "model": GEMINI_PRO}
|
| 63 |
elif is_medium:
|
| 64 |
+
# Use DeepSeek for medium complexity tasks requiring reasoning but not too time-consuming
|
| 65 |
return {"provider": "deepseek", "model": NVIDIA_MEDIUM}
|
| 66 |
else:
|
| 67 |
+
# Use NVIDIA small (Llama) for simple tasks requiring immediate execution
|
| 68 |
return {"provider": "nvidia", "model": NVIDIA_SMALL}
|
| 69 |
|
| 70 |
|