File size: 18,473 Bytes
5e3277c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | """
Instalira sve funkcije (filters, tools, actions) i kreira Custom Model Preset.
Poziva se automatski iz setup_endpoints.sh pri startu Space-a.
Koristi: python3 install_functions.py <base_url> <token>
"""
import json
import urllib.request
import urllib.error
import sys
import os
BASE_URL = sys.argv[1] if len(sys.argv) > 1 else 'http://localhost:8080'
TOKEN = sys.argv[2] if len(sys.argv) > 2 else ''
if not TOKEN:
print("β No token provided.")
sys.exit(1)
HEADERS = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {TOKEN}'
}
APP_DIR = os.path.dirname(os.path.abspath(__file__))
# βββββββββββββββββββββββββββββββββββββββββββββ
# Helpers
# βββββββββββββββββββββββββββββββββββββββββββββ
def api(method, path, data=None):
url = BASE_URL + path
body = json.dumps(data).encode() if data is not None else None
req = urllib.request.Request(url, data=body, headers=HEADERS, method=method)
try:
with urllib.request.urlopen(req) as r:
return r.status, json.loads(r.read().decode())
except urllib.error.HTTPError as e:
return e.code, e.read().decode()
def install_function(func_id, name, func_type, content):
"""Instaliraj ili aΕΎuriraj funkciju."""
# Provjeri postoji li
status, _ = api('GET', f'/api/v1/functions/id/{func_id}')
payload = {
'id': func_id,
'name': name,
'type': func_type,
'content': content,
'meta': {'description': name}
}
if status == 200:
s, r = api('POST', f'/api/v1/functions/id/{func_id}/update', payload)
label = "aΕΎuriran" if s == 200 else f"greΕ‘ka {s}"
else:
s, r = api('POST', '/api/v1/functions/create', payload)
label = "instaliran" if s == 200 else f"greΕ‘ka {s}"
# Aktiviraj
api('POST', f'/api/v1/functions/id/{func_id}/toggle')
icon = "β
" if s == 200 else "β"
print(f" {icon} [{func_type}] {name} β {label}")
return s == 200
def load_json_function(filepath):
"""UΔitaj funkciju iz JSON export fajla."""
with open(filepath) as f:
d = json.load(f)
item = d[0] if isinstance(d, list) else d
# Detektuj tip iz sadrΕΎaja
content = item.get('content', '')
if 'class Filter' in content:
ftype = 'filter'
elif 'class Pipe' in content:
ftype = 'pipe'
elif 'class Tools' in content or 'class Action' in content:
ftype = 'action'
else:
ftype = item.get('meta', {}).get('type', 'filter')
return item['id'], item['name'], ftype, content
# βββββββββββββββββββββββββββββββββββββββββββββ
# 1. Instaliraj sve JSON funkcije
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nπ¦ Instaliram funkcije iz JSON fajlova...")
JSON_FILES = [
'global_system_prompt_filter.json',
'__easysearch_v0_4_3__high-performance_web_search_filter.json',
'token_saver.json',
'context_clip_filter.json',
'auto_disable_native_tools.json',
'auto_memory.json',
'__mermaid_doctor_-_heals_broken_mermaid_diagrams_generated_by_small_or_hallucinating_models.json',
'github_simple.json',
'pdf_tools_-_rich_ui_for_in_context_basic_editing_.json',
]
installed_filter_ids = []
for fname in JSON_FILES:
fpath = os.path.join(APP_DIR, fname)
if not os.path.exists(fpath):
print(f" β οΈ {fname} nije pronaΔen, preskaΔem")
continue
func_id, name, ftype, content = load_json_function(fpath)
ok = install_function(func_id, name, ftype, content)
if ok and ftype == 'filter':
installed_filter_ids.append(func_id)
# βββββββββββββββββββββββββββββββββββββββββββββ
# 2. Instaliraj naΕ‘e custom Python funkcije
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nπ οΈ Instaliram custom funkcije...")
CUSTOM_FUNCTIONS = [
('context_detector', 'Context Detector', 'filter', 'context_detector.py'),
('token_compressor', 'Token Compressor', 'filter', 'token_compressor.py'),
('coding_fallback', 'π Smart Coding Router', 'pipe', 'coding_priority_pipe.py'),
('smart_matcher', 'Smart Matcher', 'tool', 'smart_matcher.py'),
]
for func_id, name, ftype, pyfile in CUSTOM_FUNCTIONS:
fpath = os.path.join(APP_DIR, pyfile)
if not os.path.exists(fpath):
print(f" β οΈ {pyfile} nije pronaΔen")
continue
content = open(fpath).read()
ok = install_function(func_id, name, ftype, content)
if ok and ftype == 'filter':
installed_filter_ids.append(func_id)
# βββββββββββββββββββββββββββββββββββββββββββββ
# 3. Postavi Global System Prompt
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nπ Postavljam Global System Prompt...")
SYSTEM_PROMPT_FILE = os.path.join(APP_DIR, 'system_prompt.txt')
if os.path.exists(SYSTEM_PROMPT_FILE):
system_prompt = open(SYSTEM_PROMPT_FILE).read()
# Update valve za global_system_prompt_filter
valve_payload = {
'system_message': system_prompt,
'timezone': 'Europe/Sarajevo',
'skip_tags': []
}
s, r = api('POST', '/api/v1/functions/id/global_system_prompt_filter/valves/update', valve_payload)
if s == 200:
print(" β
System prompt postavljen")
else:
print(f" β οΈ GreΕ‘ka pri postavljanju system prompta: {s}")
else:
print(" β οΈ system_prompt.txt nije pronaΔen")
# βββββββββββββββββββββββββββββββββββββββββββββ
# 4. Kreiraj Custom Model Preset
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nπ€ Kreiram Custom Model Preset...")
# Sve filter ID-ove koji treba biti aktivni na modelu
ALL_FILTER_IDS = list(dict.fromkeys([
'global_system_prompt_filter',
'easysearch',
'token_saver',
'context_clip_filter',
'auto_disable_native_tools',
'auto_memory',
'context_detector',
'token_compressor',
'mermaid_doctor',
] + installed_filter_ids))
model_payload = {
'id': 'nerdur_assistant',
'name': 'π§ Nerdur Assistant (Full)',
'base_model_id': 'coding_fallback.coding_fallback',
'meta': {
'description': 'Smart Coding Router sa svim filterima: web search, memory, token saver, context detector i viΕ‘e.',
'profile_image_url': '/static/favicon.png',
'tags': [{'name': 'custom'}, {'name': 'coding'}],
'capabilities': {
'vision': False,
'citations': True,
'usage': True,
}
},
'params': {
'system': open(SYSTEM_PROMPT_FILE).read() if os.path.exists(SYSTEM_PROMPT_FILE) else '',
'temperature': 0.2,
'max_tokens': 4096,
},
'filter_ids': ALL_FILTER_IDS,
'tool_ids': ['smart_matcher'],
'action_ids': ['pdf_tools_rich_ui_editor'],
}
# Provjeri postoji li model
status, _ = api('GET', '/api/v1/models/model?id=nerdur_assistant')
if status == 200:
s, r = api('POST', '/api/v1/models/model/update?id=nerdur_assistant', model_payload)
label = "aΕΎuriran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
else:
s, r = api('POST', '/api/v1/models/create', model_payload)
label = "kreiran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
icon = "β
" if s == 200 else "β"
print(f" {icon} Model 'π§ Nerdur Assistant (Full)' β {label}")
print("\nβ
Instalacija zavrΕ‘ena!")
# βββββββββββββββββββββββββββββββββββββββββββββ
# 5. Kreiraj Gemini 2.5 Flash Preset
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nβ‘ Kreiram Gemini 2.5 Flash Preset...")
gemini_payload = {
'id': 'nerdur_gemini_flash',
'name': 'β‘ Gemini 2.5 Flash (Coding)',
'base_model_id': 'models/gemini-2.5-flash',
'meta': {
'description': 'Gemini 2.5 Flash sa svim filterima β web search, memory, token saver i viΕ‘e.',
'profile_image_url': '/static/favicon.png',
'tags': [{'name': 'custom'}, {'name': 'coding'}, {'name': 'gemini'}],
'capabilities': {
'vision': True,
'citations': True,
'usage': True,
}
},
'params': {
'system': open(SYSTEM_PROMPT_FILE).read() if os.path.exists(SYSTEM_PROMPT_FILE) else '',
'temperature': 0.2,
'max_tokens': 8192,
},
'filter_ids': ALL_FILTER_IDS,
'tool_ids': ['smart_matcher'],
'action_ids': ['pdf_tools_rich_ui_editor'],
}
status, _ = api('GET', '/api/v1/models/model?id=nerdur_gemini_flash')
if status == 200:
s, r = api('POST', '/api/v1/models/model/update?id=nerdur_gemini_flash', gemini_payload)
label = "aΕΎuriran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
else:
s, r = api('POST', '/api/v1/models/create', gemini_payload)
label = "kreiran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
icon = "β
" if s == 200 else "β"
print(f" {icon} Model 'β‘ Gemini 2.5 Flash (Coding)' β {label}")
print("\nβ
Svi modeli kreirani!")
# βββββββββββββββββββββββββββββββββββββββββββββ
# 6. Groq preset
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nπ Kreiram Groq preset...")
groq_payload = {
'id': 'nerdur_groq_coding',
'name': 'π Groq Llama 3.3 70B (Coding)',
'base_model_id': 'groq/llama-3.3-70b-versatile',
'meta': {
'description': 'Kimi K2 na Groq β izuzetno brz, odliΔan za kodiranje, besplatan.',
'profile_image_url': '/static/favicon.png',
'tags': [{'name': 'custom'}, {'name': 'coding'}, {'name': 'groq'}],
'capabilities': {'vision': False, 'citations': True, 'usage': True}
},
'params': {
'system': open(SYSTEM_PROMPT_FILE).read() if os.path.exists(SYSTEM_PROMPT_FILE) else '',
'temperature': 0.2,
'max_tokens': 8192,
},
'filter_ids': ALL_FILTER_IDS,
'tool_ids': ['smart_matcher'],
'action_ids': ['pdf_tools_rich_ui_editor'],
}
status, _ = api('GET', '/api/v1/models/model?id=nerdur_groq_coding')
if status == 200:
s, r = api('POST', '/api/v1/models/model/update?id=nerdur_groq_coding', groq_payload)
label = "aΕΎuriran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
else:
s, r = api('POST', '/api/v1/models/create', groq_payload)
label = "kreiran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
print(f" {'β
' if s == 200 else 'β'} 'π Groq Kimi K2 (Coding)' β {label}")
# βββββββββββββββββββββββββββββββββββββββββββββ
# 7. Cerebras preset
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nπ§ Kreiram Cerebras preset...")
cerebras_payload = {
'id': 'nerdur_cerebras_coding',
'name': 'π§ Cerebras Llama 4 Scout (Coding)',
'base_model_id': 'cerebras/llama-4-scout-17b-16e-instruct',
'meta': {
'description': 'Llama 3.3 70B na Cerebras β jedan od najbrΕΎih inference engine-a, besplatan.',
'profile_image_url': '/static/favicon.png',
'tags': [{'name': 'custom'}, {'name': 'coding'}, {'name': 'cerebras'}],
'capabilities': {'vision': False, 'citations': True, 'usage': True}
},
'params': {
'system': open(SYSTEM_PROMPT_FILE).read() if os.path.exists(SYSTEM_PROMPT_FILE) else '',
'temperature': 0.2,
'max_tokens': 8192,
},
'filter_ids': ALL_FILTER_IDS,
'tool_ids': ['smart_matcher'],
'action_ids': ['pdf_tools_rich_ui_editor'],
}
status, _ = api('GET', '/api/v1/models/model?id=nerdur_cerebras_coding')
if status == 200:
s, r = api('POST', '/api/v1/models/model/update?id=nerdur_cerebras_coding', cerebras_payload)
label = "aΕΎuriran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
else:
s, r = api('POST', '/api/v1/models/create', cerebras_payload)
label = "kreiran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
print(f" {'β
' if s == 200 else 'β'} 'π§ Cerebras Llama 3.3 (Coding)' β {label}")
# βββββββββββββββββββββββββββββββββββββββββββββ
# 8. SambaNova preset
# βββββββββββββββββββββββββββββββββββββββββββββ
print("\nβ‘ Kreiram SambaNova preset...")
sambanova_payload = {
'id': 'nerdur_sambanova_coding',
'name': 'β‘ SambaNova Llama 3.3 (Coding)',
'base_model_id': 'Meta-Llama-3.3-70B-Instruct',
'meta': {
'description': 'Llama 3.3 70B na SambaNova β brz inference, dobar za kodiranje, besplatan.',
'profile_image_url': '/static/favicon.png',
'tags': [{'name': 'custom'}, {'name': 'coding'}, {'name': 'sambanova'}],
'capabilities': {'vision': False, 'citations': True, 'usage': True}
},
'params': {
'system': open(SYSTEM_PROMPT_FILE).read() if os.path.exists(SYSTEM_PROMPT_FILE) else '',
'temperature': 0.2,
'max_tokens': 8192,
},
'filter_ids': ALL_FILTER_IDS,
'tool_ids': ['smart_matcher'],
'action_ids': ['pdf_tools_rich_ui_editor'],
}
status, _ = api('GET', '/api/v1/models/model?id=nerdur_sambanova_coding')
if status == 200:
s, r = api('POST', '/api/v1/models/model/update?id=nerdur_sambanova_coding', sambanova_payload)
label = "aΕΎuriran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
else:
s, r = api('POST', '/api/v1/models/create', sambanova_payload)
label = "kreiran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:100]}"
print(f" {'β
' if s == 200 else 'β'} 'β‘ SambaNova Llama 3.3 (Coding)' β {label}")
print("\nπ Svih 5 preseta kreirano!")
# βββββββββββββββββββββββββββββββββββββββββββββ
# 9. Dodatni presets za sve aktivne provajdere
# βββββββββββββββββββββββββββββββββββββββββββββ
EXTRA_MODELS = [
{
'id': 'nerdur_claude',
'name': 'π£ Claude Sonnet 4.5 (Coding)',
'base_model_id': 'anthropic/claude-sonnet-4-5',
'desc': 'Claude Sonnet 4.5 via Anthropic β odliΔan za kodiranje i analizu.',
'max_tokens': 8192,
'vision': True,
},
{
'id': 'nerdur_gpt4o',
'name': 'π’ GPT-4o (Coding)',
'base_model_id': 'openai/gpt-4o',
'desc': 'OpenAI GPT-4o β multimodalan, odliΔan za kodiranje.',
'max_tokens': 4096,
'vision': True,
},
{
'id': 'nerdur_mistral',
'name': 'π΅ Mistral Large (Coding)',
'base_model_id': 'mistral-large-latest',
'desc': 'Mistral Large β odliΔan europski model za kodiranje.',
'max_tokens': 8192,
'vision': False,
},
{
'id': 'nerdur_deepseek',
'name': 'π΄ DeepSeek V3 (Coding)',
'base_model_id': 'deepseek/deepseek-chat',
'desc': 'DeepSeek V3 β izvrstan za kodiranje, vrlo jeftin.',
'max_tokens': 8192,
'vision': False,
},
{
'id': 'nerdur_xai',
'name': 'β‘ Grok 3 (Coding)',
'base_model_id': 'xai/grok-3',
'desc': 'xAI Grok 3 β jak model sa web pristupom.',
'max_tokens': 8192,
'vision': True,
},
{
'id': 'nerdur_openrouter_free',
'name': 'π OpenRouter Free (Coding)',
'base_model_id': 'openrouter/meta-llama/llama-4-maverick:free',
'desc': 'Llama 4 Maverick besplatno via OpenRouter.',
'max_tokens': 8192,
'vision': True,
},
{
'id': 'nerdur_fireworks',
'name': 'π₯ Fireworks Llama 4 Scout (Coding)',
'base_model_id': 'fireworks/accounts/fireworks/models/llama4-scout-instruct-basic',
'desc': 'Llama 4 Scout na Fireworks β brz i jeftin.',
'max_tokens': 8192,
'vision': True,
},
]
system_prompt_text = open(SYSTEM_PROMPT_FILE).read() if os.path.exists(SYSTEM_PROMPT_FILE) else ''
print("\nπ Kreiram dodatne provider presete...")
for m in EXTRA_MODELS:
payload = {
'id': m['id'],
'name': m['name'],
'base_model_id': m['base_model_id'],
'meta': {
'description': m['desc'],
'profile_image_url': '/static/favicon.png',
'tags': [{'name': 'custom'}, {'name': 'coding'}],
'capabilities': {
'vision': m['vision'],
'citations': True,
'usage': True,
}
},
'params': {
'system': system_prompt_text,
'temperature': 0.2,
'max_tokens': m['max_tokens'],
},
'filter_ids': ALL_FILTER_IDS,
'tool_ids': ['smart_matcher'],
'action_ids': ['pdf_tools_rich_ui_editor'],
}
status, _ = api('GET', f'/api/v1/models/model?id={m["id"]}')
if status == 200:
s, r = api('POST', f'/api/v1/models/model/update?id={m["id"]}', payload)
label = "aΕΎuriran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:80]}"
else:
s, r = api('POST', '/api/v1/models/create', payload)
label = "kreiran" if s == 200 else f"greΕ‘ka {s}: {str(r)[:80]}"
print(f" {'β
' if s == 200 else 'β'} {m['name']} β {label}")
print("\nπ Instalacija kompletna!")
|