Code generation
Mira is a powerful tool for developers. All models in the family are trained on large volumes of high-quality code and support generation, explanation, debugging, refactoring, and testing across many programming languages.
Supported programming languages
Code generation
Mira can generate code from natural language descriptions. For best results, be specific about requirements and desired style.
{
"model": "mira",
"messages": [{
"role": "user",
"content": "Write a Python function that takes a list of strings and returns the most frequently occurring string. If multiple strings have the same frequency, return the first alphabetically. Add type hints and a docstring."
}]
}Result:
from collections import Counter
def most_frequent(strings: list[str]) -> str:
"""Return the most frequently occurring string.
If multiple strings share the highest frequency,
return the first one alphabetically.
Args:
strings: A list of strings to analyze.
Returns:
The most frequent string.
Raises:
ValueError: If the input list is empty.
"""
if not strings:
raise ValueError("Input list cannot be empty")
counts = Counter(strings)
max_count = max(counts.values())
candidates = [s for s, c in counts.items() if c == max_count]
return sorted(candidates)[0]Code explanation
Pass existing code and ask Mira to explain what it does. Especially useful when working with unfamiliar codebases.
{
"model": "mira",
"messages": [{
"role": "user",
"content": "Explain what this code does and where issues might be:\n\nconst debounce = (fn, ms) => {\n let id;\n return (...args) => {\n clearTimeout(id);\n id = setTimeout(() => fn(...args), ms);\n };\n};"
}]
}Debugging
For debugging complex code, we recommend using mira-pro — the model with thinking mode that systematically analyzes code for bugs.
{
"model": "mira-pro",
"messages": [{
"role": "user",
"content": "This Rust code panics on certain inputs. Find the bug:\n\nfn binary_search(arr: &[i32], target: i32) -> Option<usize> {\n let mut low = 0;\n let mut high = arr.len();\n while low < high {\n let mid = (low + high) / 2;\n if arr[mid] == target { return Some(mid); }\n if arr[mid] < target { low = mid + 1; }\n else { high = mid - 1; } // Bug: underflow when mid = 0\n }\n None\n}"
}]
}Refactoring
Mira can suggest improvements for existing code: improving structure, performance, readability, and adherence to best practices.
{
"model": "mira-pro",
"messages": [
{
"role": "system",
"content": "You are a senior developer conducting a code review. Suggest refactoring with explanation for each change."
},
{
"role": "user",
"content": "Refactor this Express route:\n\napp.post('/users', (req, res) => {\n if (!req.body.email) return res.status(400).send('email required');\n if (!req.body.name) return res.status(400).send('name required');\n db.query('INSERT INTO users (email, name) VALUES ($1, $2)', [req.body.email, req.body.name])\n .then(r => res.json(r.rows[0]))\n .catch(e => { console.log(e); res.status(500).send('error'); });\n});"
}
]
}Test generation
Mira generates comprehensive tests covering main scenarios, edge cases, and error handling.
{
"model": "mira-pro",
"messages": [{
"role": "user",
"content": "Write tests for this TypeScript function using Vitest. Cover all edge cases.\n\nexport function parseEmail(email: string): { user: string; domain: string } | null {\n const parts = email.split('@');\n if (parts.length !== 2 || !parts[0] || !parts[1]) return null;\n if (!parts[1].includes('.')) return null;\n return { user: parts[0], domain: parts[1] };\n}"
}]
}Documentation generation
Mira helps generate code documentation: JSDoc/TSDoc comments, READMEs, API documentation, and guides.
{
"model": "mira",
"messages": [{
"role": "user",
"content": "Add detailed JSDoc comments to every function and type in this file:\n\ninterface Config {\n baseUrl: string;\n timeout: number;\n retries: number;\n}\n\nfunction createClient(config: Config) {\n // ...\n}\n\nfunction fetchWithRetry(url: string, options?: RequestInit) {\n // ...\n}"
}]
}Mira Code CLI
For interactive AI-powered coding, use Mira Code — a CLI tool that integrates with your editor and terminal.
# Install npm install -g mira-code # Start interactive session mira-code # Generate code from description mira-code generate "REST API with Express and TypeScript" # Debug a file mira-code debug src/server.ts # Explain a file mira-code explain src/algorithm.rs
Best practices
- Be specific — specify language, framework, code style, and version — 'Python 3.12, asyncio, type hints'
- Provide context — include existing types, interfaces, and dependencies — the model generates more compatible code
- Review code — always review generated code before using in production
- Iterate — if the result isn't perfect, refine requirements or ask to improve a specific aspect
- For complex tasks — use mira-pro for debugging with thinking mode and mira-max for large codebase work