cortex-llm 1.0.0__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.
- cortex/__init__.py +73 -0
- cortex/__main__.py +83 -0
- cortex/config.py +329 -0
- cortex/conversation_manager.py +468 -0
- cortex/fine_tuning/__init__.py +8 -0
- cortex/fine_tuning/dataset.py +332 -0
- cortex/fine_tuning/mlx_lora_trainer.py +502 -0
- cortex/fine_tuning/trainer.py +957 -0
- cortex/fine_tuning/wizard.py +707 -0
- cortex/gpu_validator.py +467 -0
- cortex/inference_engine.py +727 -0
- cortex/metal/__init__.py +275 -0
- cortex/metal/gpu_validator.py +177 -0
- cortex/metal/memory_pool.py +886 -0
- cortex/metal/mlx_accelerator.py +678 -0
- cortex/metal/mlx_converter.py +638 -0
- cortex/metal/mps_optimizer.py +417 -0
- cortex/metal/optimizer.py +665 -0
- cortex/metal/performance_profiler.py +364 -0
- cortex/model_downloader.py +130 -0
- cortex/model_manager.py +2187 -0
- cortex/quantization/__init__.py +5 -0
- cortex/quantization/dynamic_quantizer.py +736 -0
- cortex/template_registry/__init__.py +15 -0
- cortex/template_registry/auto_detector.py +144 -0
- cortex/template_registry/config_manager.py +234 -0
- cortex/template_registry/interactive.py +260 -0
- cortex/template_registry/registry.py +347 -0
- cortex/template_registry/template_profiles/__init__.py +5 -0
- cortex/template_registry/template_profiles/base.py +142 -0
- cortex/template_registry/template_profiles/complex/__init__.py +5 -0
- cortex/template_registry/template_profiles/complex/reasoning.py +263 -0
- cortex/template_registry/template_profiles/standard/__init__.py +9 -0
- cortex/template_registry/template_profiles/standard/alpaca.py +73 -0
- cortex/template_registry/template_profiles/standard/chatml.py +82 -0
- cortex/template_registry/template_profiles/standard/gemma.py +103 -0
- cortex/template_registry/template_profiles/standard/llama.py +87 -0
- cortex/template_registry/template_profiles/standard/simple.py +65 -0
- cortex/ui/__init__.py +120 -0
- cortex/ui/cli.py +1685 -0
- cortex/ui/markdown_render.py +185 -0
- cortex/ui/terminal_app.py +534 -0
- cortex_llm-1.0.0.dist-info/METADATA +275 -0
- cortex_llm-1.0.0.dist-info/RECORD +48 -0
- cortex_llm-1.0.0.dist-info/WHEEL +5 -0
- cortex_llm-1.0.0.dist-info/entry_points.txt +2 -0
- cortex_llm-1.0.0.dist-info/licenses/LICENSE +21 -0
- cortex_llm-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Simple template profile for basic conversation."""
|
|
2
|
+
|
|
3
|
+
from typing import List, Dict, Any, Tuple
|
|
4
|
+
from cortex.template_registry.template_profiles.base import BaseTemplateProfile, TemplateConfig, TemplateType
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class SimpleProfile(BaseTemplateProfile):
|
|
8
|
+
"""Simple conversation format without special tokens."""
|
|
9
|
+
|
|
10
|
+
def get_default_config(self) -> TemplateConfig:
|
|
11
|
+
"""Return the default simple configuration."""
|
|
12
|
+
return TemplateConfig(
|
|
13
|
+
name="Simple",
|
|
14
|
+
description="Simple conversation format without special tokens",
|
|
15
|
+
template_type=TemplateType.SIMPLE,
|
|
16
|
+
supports_system_prompt=True,
|
|
17
|
+
supports_multi_turn=True,
|
|
18
|
+
strip_special_tokens=True,
|
|
19
|
+
stop_sequences=["Human:", "User:", "Assistant:"]
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
def format_messages(self, messages: List[Dict[str, str]], add_generation_prompt: bool = True) -> str:
|
|
23
|
+
"""Format messages in simple style."""
|
|
24
|
+
formatted = ""
|
|
25
|
+
|
|
26
|
+
for msg in messages:
|
|
27
|
+
role = msg.get('role', 'user')
|
|
28
|
+
content = msg.get('content', '')
|
|
29
|
+
|
|
30
|
+
if role == 'system':
|
|
31
|
+
formatted += f"System: {content}\n\n"
|
|
32
|
+
elif role == 'user':
|
|
33
|
+
formatted += f"Human: {content}\n\n"
|
|
34
|
+
elif role == 'assistant':
|
|
35
|
+
formatted += f"Assistant: {content}\n\n"
|
|
36
|
+
|
|
37
|
+
if add_generation_prompt:
|
|
38
|
+
formatted += "Assistant: "
|
|
39
|
+
|
|
40
|
+
return formatted
|
|
41
|
+
|
|
42
|
+
def process_response(self, raw_output: str) -> str:
|
|
43
|
+
"""Process simple output - minimal processing."""
|
|
44
|
+
output = raw_output
|
|
45
|
+
|
|
46
|
+
# Remove any role markers
|
|
47
|
+
for marker in ["Human:", "User:", "Assistant:", "System:"]:
|
|
48
|
+
if output.startswith(marker):
|
|
49
|
+
output = output[len(marker):].strip()
|
|
50
|
+
|
|
51
|
+
# Remove any common special tokens
|
|
52
|
+
special_tokens = [
|
|
53
|
+
"<|endoftext|>", "<|end|>", "</s>", "<s>",
|
|
54
|
+
"[INST]", "[/INST]", "###"
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
for token in special_tokens:
|
|
58
|
+
output = output.replace(token, "")
|
|
59
|
+
|
|
60
|
+
return output.strip()
|
|
61
|
+
|
|
62
|
+
def can_handle(self, model_name: str, tokenizer: Any = None) -> Tuple[bool, float]:
|
|
63
|
+
"""Simple profile can handle any model as a fallback."""
|
|
64
|
+
# This is a universal fallback, so always return low confidence
|
|
65
|
+
return True, 0.1
|
cortex/ui/__init__.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Terminal UI components for Cortex."""
|
|
2
|
+
|
|
3
|
+
from typing import Dict, Any, Optional
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"Theme",
|
|
7
|
+
"UIComponents"
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
class Theme:
|
|
11
|
+
"""UI theme configuration."""
|
|
12
|
+
|
|
13
|
+
DEFAULT_THEME = {
|
|
14
|
+
"primary": "#00ff00",
|
|
15
|
+
"secondary": "#0080ff",
|
|
16
|
+
"background": "#000000",
|
|
17
|
+
"text": "#ffffff",
|
|
18
|
+
"error": "#ff0000",
|
|
19
|
+
"warning": "#ffff00",
|
|
20
|
+
"success": "#00ff00",
|
|
21
|
+
"info": "#0080ff",
|
|
22
|
+
"border": "#444444",
|
|
23
|
+
"highlight": "#333333"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
DARK_THEME = DEFAULT_THEME
|
|
27
|
+
|
|
28
|
+
LIGHT_THEME = {
|
|
29
|
+
"primary": "#0080ff",
|
|
30
|
+
"secondary": "#00c853",
|
|
31
|
+
"background": "#ffffff",
|
|
32
|
+
"text": "#000000",
|
|
33
|
+
"error": "#d32f2f",
|
|
34
|
+
"warning": "#f57c00",
|
|
35
|
+
"success": "#388e3c",
|
|
36
|
+
"info": "#1976d2",
|
|
37
|
+
"border": "#cccccc",
|
|
38
|
+
"highlight": "#eeeeee"
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@classmethod
|
|
42
|
+
def get_theme(cls, theme_name: str = "default") -> Dict[str, str]:
|
|
43
|
+
"""Get theme by name."""
|
|
44
|
+
themes = {
|
|
45
|
+
"default": cls.DEFAULT_THEME,
|
|
46
|
+
"dark": cls.DARK_THEME,
|
|
47
|
+
"light": cls.LIGHT_THEME
|
|
48
|
+
}
|
|
49
|
+
return themes.get(theme_name, cls.DEFAULT_THEME)
|
|
50
|
+
|
|
51
|
+
class UIComponents:
|
|
52
|
+
"""Common UI component definitions."""
|
|
53
|
+
|
|
54
|
+
HEADER_HEIGHT = 3
|
|
55
|
+
FOOTER_HEIGHT = 2
|
|
56
|
+
SIDEBAR_WIDTH = 30
|
|
57
|
+
MIN_TERMINAL_WIDTH = 80
|
|
58
|
+
MIN_TERMINAL_HEIGHT = 24
|
|
59
|
+
|
|
60
|
+
SHORTCUTS = {
|
|
61
|
+
"new_conversation": "ctrl+n",
|
|
62
|
+
"switch_conversation": "ctrl+tab",
|
|
63
|
+
"cancel_generation": "ctrl+c",
|
|
64
|
+
"duplicate_message": "ctrl+d",
|
|
65
|
+
"command_palette": "ctrl+/",
|
|
66
|
+
"quit": "ctrl+q",
|
|
67
|
+
"save_conversation": "ctrl+s",
|
|
68
|
+
"load_model": "ctrl+l",
|
|
69
|
+
"settings": "ctrl+,",
|
|
70
|
+
"help": "ctrl+h"
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
COMMANDS = {
|
|
74
|
+
"/help": "Show available commands",
|
|
75
|
+
"/status": "Show current setup and GPU info",
|
|
76
|
+
"/download": "Download models from HuggingFace",
|
|
77
|
+
"/model": "Switch or load a model",
|
|
78
|
+
"/models": "List available models",
|
|
79
|
+
"/clear": "Clear current conversation",
|
|
80
|
+
"/save": "Save conversation",
|
|
81
|
+
"/load": "Load conversation",
|
|
82
|
+
"/export": "Export conversation",
|
|
83
|
+
"/config": "Open settings",
|
|
84
|
+
"/benchmark": "Run benchmark",
|
|
85
|
+
"/gpu": "Show GPU status",
|
|
86
|
+
"/quit": "Exit application"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
STATUS_ICONS = {
|
|
90
|
+
"idle": "⚪",
|
|
91
|
+
"loading": "🔄",
|
|
92
|
+
"generating": "⚡",
|
|
93
|
+
"completed": "✅",
|
|
94
|
+
"error": "❌",
|
|
95
|
+
"cancelled": "⚠️"
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@classmethod
|
|
99
|
+
def format_performance_metrics(
|
|
100
|
+
cls,
|
|
101
|
+
tokens_per_second: float,
|
|
102
|
+
gpu_utilization: float,
|
|
103
|
+
memory_gb: float
|
|
104
|
+
) -> str:
|
|
105
|
+
"""Format performance metrics for display."""
|
|
106
|
+
return f"⚡{tokens_per_second:.1f}t/s | GPU: {gpu_utilization:.0f}% | Mem: {memory_gb:.1f}GB"
|
|
107
|
+
|
|
108
|
+
@classmethod
|
|
109
|
+
def format_model_info(
|
|
110
|
+
cls,
|
|
111
|
+
model_name: str,
|
|
112
|
+
quantization: str,
|
|
113
|
+
context_used: int,
|
|
114
|
+
context_total: int
|
|
115
|
+
) -> str:
|
|
116
|
+
"""Format model information for display."""
|
|
117
|
+
context_percent = (context_used / context_total * 100) if context_total > 0 else 0
|
|
118
|
+
return f"{model_name} [{quantization}] | Context: {context_used}/{context_total} ({context_percent:.0f}%)"
|
|
119
|
+
|
|
120
|
+
# from cortex.ui.terminal_app import TerminalApp # Commented out - only needed for TUI mode
|