Contextual Instruction API
Contextual Instruction API
The Contextual Instruction API is the first stage in the Udility Diffuser pipeline. It leverages the Meta Llama-3.5 architecture (specifically the Hermes-3 Llama-3.1-405B model via OpenRouter) to transform a simple user prompt into a structured technical blueprint. This blueprint serves as the "logical skeleton" that guides the subsequent SVG generation.
By decoupling the conceptualization from the rendering, users can inspect the textual logic of an illustration before it is converted into code.
get_detailed_instructions
This function takes a high-level text description and returns a detailed set of instructions that describe the layout, labels, and visual components required for an SVG illustration.
Parameters:
| Name | Type | Description |
| :--- | :--- | :--- |
| text_description | str | A natural language description of the image you wish to generate (e.g., "The water cycle"). |
Returns:
| Type | Description |
| :--- | :--- |
| str | A comprehensive textual guide/blueprint used for SVG scripting. |
Exceptions:
RuntimeError: Raised if the OpenRouter API is unreachable or if the request fails.
Usage Example
While generate_image_from_text handles the full pipeline automatically, you can use get_detailed_instructions independently to view the "logic" behind a generated image.
from Udility import diffuser
# Define your prompt
prompt = "A diagram showing the structure of a plant cell."
# Generate the technical blueprint
blueprint = diffuser.get_detailed_instructions(prompt)
print("Generated Blueprint:")
print(blueprint)
The Instruction Workflow
- Prompt Entry: The user provides a conceptual prompt (e.g., "Mathematical Integration").
- Contextualization: The
get_detailed_instructionsfunction sends this prompt to the LLM with specific system context to define spatial relationships and labeling requirements. - Blueprint Output: The result is a text-based instruction set (the "Contextual Instruction") that defines exactly what elements should appear in the SVG.
- Scripting: This output is then passed to the
generate_svg_from_instructionsfunction to produce the final XML code.
Advanced Configuration
The Contextual Instruction API relies on the OPENROUTER_API_KEY environment variable. Ensure your environment is configured correctly before calling this function:
import os
os.environ['OPENROUTER_API_KEY'] = 'your_api_key_here'