quickthink 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quickthink/__init__.py +6 -0
- quickthink/cli.py +187 -0
- quickthink/config.py +108 -0
- quickthink/engine.py +174 -0
- quickthink/inline_protocol.py +18 -0
- quickthink/ollama_client.py +38 -0
- quickthink/plan_grammar.py +24 -0
- quickthink/prompts.py +73 -0
- quickthink/routing.py +65 -0
- quickthink/ui_server.py +1465 -0
- quickthink-0.2.1.dist-info/METADATA +387 -0
- quickthink-0.2.1.dist-info/RECORD +16 -0
- quickthink-0.2.1.dist-info/WHEEL +5 -0
- quickthink-0.2.1.dist-info/entry_points.txt +2 -0
- quickthink-0.2.1.dist-info/licenses/LICENSE +176 -0
- quickthink-0.2.1.dist-info/top_level.txt +1 -0
quickthink/routing.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from .config import QuickThinkConfig
|
|
6
|
+
|
|
7
|
+
_MULTI_STEP_RE = re.compile(r"\b(plan|design|debug|strategy|step[- ]by[- ]step|architecture)\b", re.IGNORECASE)
|
|
8
|
+
_COMPARISON_RE = re.compile(r"\b(compare|versus|vs\.?|tradeoff|pros and cons)\b", re.IGNORECASE)
|
|
9
|
+
_STRUCTURED_RE = re.compile(r"\b(json|table|schema|bullet|list|format)\b", re.IGNORECASE)
|
|
10
|
+
_AMBIGUITY_RE = re.compile(r"\b(best|optimize|could|should|maybe|might)\b", re.IGNORECASE)
|
|
11
|
+
_STRICT_FORMAT_RE = re.compile(
|
|
12
|
+
r"\b(json only|yaml only|csv only|xml|exactly|lowercase only|yes or no only|no punctuation|line 1:|line 2:)\b",
|
|
13
|
+
re.IGNORECASE,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def complexity_score(prompt: str) -> int:
|
|
18
|
+
score = 0
|
|
19
|
+
stripped = prompt.strip()
|
|
20
|
+
|
|
21
|
+
if len(stripped) > 140:
|
|
22
|
+
score += 1
|
|
23
|
+
if _COMPARISON_RE.search(stripped):
|
|
24
|
+
score += 1
|
|
25
|
+
if _MULTI_STEP_RE.search(stripped):
|
|
26
|
+
score += 1
|
|
27
|
+
if _STRUCTURED_RE.search(stripped):
|
|
28
|
+
score += 1
|
|
29
|
+
if _AMBIGUITY_RE.search(stripped):
|
|
30
|
+
score += 1
|
|
31
|
+
|
|
32
|
+
return score
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def choose_plan_budget(score: int, config: QuickThinkConfig) -> int:
|
|
36
|
+
if score <= 1:
|
|
37
|
+
return config.min_plan_budget_tokens
|
|
38
|
+
if score <= 3:
|
|
39
|
+
return min(max(12, config.min_plan_budget_tokens), config.max_plan_budget_tokens)
|
|
40
|
+
return config.max_plan_budget_tokens
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def should_bypass(prompt: str, config: QuickThinkConfig) -> tuple[bool, int, int]:
|
|
44
|
+
stripped = prompt.strip()
|
|
45
|
+
score = complexity_score(stripped)
|
|
46
|
+
|
|
47
|
+
if config.bypass_short_prompts and len(stripped) <= config.bypass_char_threshold:
|
|
48
|
+
return True, score, config.min_plan_budget_tokens
|
|
49
|
+
|
|
50
|
+
if config.adaptive_routing and score <= config.route_skip_score_threshold:
|
|
51
|
+
return True, score, config.min_plan_budget_tokens
|
|
52
|
+
|
|
53
|
+
if config.adaptive_routing:
|
|
54
|
+
return False, score, choose_plan_budget(score, config)
|
|
55
|
+
|
|
56
|
+
return False, score, config.plan_budget_tokens
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def infer_task_class(prompt: str) -> str:
|
|
60
|
+
stripped = prompt.strip()
|
|
61
|
+
if _STRICT_FORMAT_RE.search(stripped):
|
|
62
|
+
return "strict_format"
|
|
63
|
+
if _MULTI_STEP_RE.search(stripped) or _COMPARISON_RE.search(stripped):
|
|
64
|
+
return "reasoning"
|
|
65
|
+
return "general"
|