gn() - Code Generation
- Silent Generation – Translates prompts into valid Python code, returning a custom
AIResultstring wrapper that overrides__repr__to suppress automatic prints in Jupyter notebooks or Python REPLs. - File Auto-Detection – Scans local files (CSV, Excel, JSON) using
magikaandpandasto extract column schemas and preview rows automatically into the AI context.
Signature
ranno.gn(prompt: str, data: Optional[str] = None, config: Optional[dict] = None) -> AIResult| Parameter | Type | Required | Description |
|---|---|---|---|
| prompt | str | Yes | The natural language instruction. |
| data | str | No | File path to target CSV, Excel, or JSON dataset. Reads columns and preview rows automatically. |
| config | dict | No | Optional Gemini request configurations. |
| Returns | Description |
|---|---|
| AIResult | Subclass of string containing the generated code block. |
gn() - API
from ranno import gn
# Generate code silently
code = gn("Create a list of 10 dinosaurs")
print(code)
# Generate code with dataset context
dataset_code = gn("Find the average salary", data="employees.csv")
print(dataset_code)