# Use unified LLM router to prefer Groq when available from ai.llm_router import run_llama from ai.profile_manager import load_profile def suggest_refactor(code: str, max_tokens: int = 500) -> str: profile = load_profile() style = profile.get("coding_style", {}) # produce a concise style summary style_summary = ", ".join(f"{k}: {v}" for k, v in style.items()) or "no explicit style" prompt = f""" System: You are CodeMate, a precise, concise code refactoring assistant. Constraint: Preserve the user's style where possible ({style_summary}). Goal: Improve clarity, maintainability, and reduce complexity. Keep behavior identical. Input code: {code} Instructions: - Show only the refactored code. - If you make interface changes, explain briefly after the code in a short comment. - Preserve comments and idioms that match the user's style. Refactored code: """ # prefer deterministic low-temperature output for accuracy return run_llama(prompt, max_tokens=max_tokens, temperature=0.05, top_p=0.9, seed=42)