Spaces:
Sleeping
Sleeping
File size: 1,042 Bytes
b946ba0 5cb6ded |
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 |
# 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)
|