Spaces:
Runtime error
Runtime error
| """Вспомогательные функции""" | |
| import re | |
| from typing import Dict, List, Tuple, Any | |
| from .state import STATE | |
| def build_skill_prompt(new_request: str, file_context: str = "") -> str: | |
| history = STATE.skill_history[-5:] if STATE.skill_history else [] | |
| context = "" | |
| for entry in history: | |
| context += f"\n{entry['role']}: {entry['content'][:500]}" | |
| prompt = f"Previous context:{context}\n\nNew request: {new_request}" | |
| if file_context: | |
| prompt += f"\n\nFile context:\n{file_context}" | |
| return prompt | |
| def parse_build_args(text: str) -> Tuple[Dict[str, Any], str]: | |
| params = {} | |
| # --agents=N | |
| agents_match = re.search(r'--agents=(\d+)', text) | |
| if agents_match: | |
| params["agents"] = int(agents_match.group(1)) | |
| text = text.replace(agents_match.group(0), "") | |
| # --tier=tier1|tier2|... | |
| tier_match = re.search(r'--tier=(\w+)', text) | |
| if tier_match: | |
| params["tier"] = tier_match.group(1) | |
| text = text.replace(tier_match.group(0), "") | |
| # --interpreter=true|false | |
| interp_match = re.search(r'--interpreter=(true|false)', text, re.IGNORECASE) | |
| if interp_match: | |
| params["use_interpreter"] = interp_match.group(1).lower() == "true" | |
| text = text.replace(interp_match.group(0), "") | |
| return params, text.strip() | |
| def parse_skill_args(text: str) -> Tuple[Dict[str, Any], str]: | |
| params = {} | |
| # --agents=role1,role2 | |
| agents_match = re.search(r'--agents=([\w,]+)', text) | |
| if agents_match: | |
| params["agents"] = agents_match.group(1).split(",") | |
| text = text.replace(agents_match.group(0), "") | |
| # --internet | |
| if "--internet" in text: | |
| params["internet"] = True | |
| text = text.replace("--internet", "") | |
| return params, text.strip() | |
| def parse_skill_agents(text: str) -> Tuple[List[str], str]: | |
| params, clean = parse_skill_args(text) | |
| return params.get("agents", []), clean | |
| def get_current_mode_info() -> str: | |
| mode = STATE.current_mode | |
| role = STATE.current_role | |
| model = STATE.current_model | |
| conductor = STATE.current_conductor | |
| return f"🎛️ Режим: {mode} | Роль: {role} | Модель: {model} | Кондуктор: {conductor}" | |