LayerGen is a small desktop app for building chained AI workflows.
Instead of using one large prompt, you create separate layers. Each layer can have its own prompt, model, API key, temperature, language, attachments, and output. A layer can use the project input, the previous layer's output, or the output from any specific layer.
LayerGen was originally designed for code generation, but it can be used for any workflow where one AI step should feed another.
This README was made for the latest version of LayerGen, version 0.0.5. In the newest update the major change added was the ability to download and run local models, which can be accessed via the Models setting.
Open Command Prompt and run:
cd C:\Users\haoqi\Documents\Codex\2026-08-03\thi\outputs
python LayerGen.pyLayerGen is a single Python file and uses Python's standard library. You do not need to install extra packages for the GUI.
The main file is:
LayerGen.py
The folder also contains older compatibility copies:
code_generator_app.py
three_layer_code_generator_gui.py
They are kept synced with LayerGen.py.
LayerGen lets you:
- Create blank layers like browser tabs.
- Give each layer its own prompt and settings.
- Chain layers together with insertable variables.
- Run every layer, or start from one layer and run only that layer plus everything after it.
- Chat with one layer to fine-tune that layer and downstream layers.
- Save and load full projects.
- Attach text, code, images, PDFs, and URLs.
- View a flowchart of how layers depend on each other.
- Save generated code directly to a file.
- Click
New layer. - Choose a provider.
- Add or load an API key if the provider needs one.
- Choose a model.
- Write the layer prompt.
- Add more layers.
- Use
Run allorRun selected + after.
Each layer has a Settings menu and a Models menu.
Each layer stores:
- Layer name
- Provider
- Model
- API key behavior
- Endpoint/base URL
- Temperature
- Max tokens
- Language
- Prompt
- Attachments
- Output
Layers are independent, but they can reference each other through variables.
Use the Insert control in a layer prompt to insert variables without typing braces manually.
Common variables:
{input}
{language}
{layer_name}
{previous_output}
{all_previous_outputs}
{current_output}
{chat_message}
{chat_history}
{layer_1_output}
{layer_2_output}
Example:
Write clean Python code from this plan:
{previous_output}
Example using a specific earlier layer:
Use the architecture from Layer 1:
{layer_1_output}
Now write the final implementation.
Run all starts at the first layer and runs the full workflow.
Run selected + after starts at the selected layer and runs only that layer plus the layers after it.
This is useful when you already like the earlier layers and only want to regenerate the later steps.
The Chat tab is for fine-tuning existing layer outputs.
Use Chat with to choose the layer you want to talk to. The chat will update that layer and every layer after it. Earlier layers are not rerun.
Modes:
Replace outputs
Append outputs
Replace outputs rewrites the selected layer's output.
Append outputs adds the new response to the existing output.
Chat uses the current outputs and chat history as memory, so it should build on existing progress instead of starting over.
LayerGen supports:
Gemini
OpenAI-compatible
Anthropic
Ollama
Hugging Face
Use a Gemini API key.
Typical setup:
Provider: Gemini
Settings > API key > Enter API key...
Models > Load from provider
Use an Anthropic API key.
Typical setup:
Provider: Anthropic
Settings > API key > Enter API key...
Models > Load from provider
Use this for OpenAI-style APIs, local model servers, LM Studio, or any service that exposes:
/v1/models
/v1/chat/completions
Common endpoints:
https://api.openai.com/v1
http://localhost:1234/v1
Set the endpoint with:
Settings > Endpoint...
Use this when Ollama is running locally.
Default endpoint:
http://localhost:11434
Example outside LayerGen:
ollama pull deepseek-r1:7bThen inside LayerGen:
Provider: Ollama
Models > Load from provider
Ollama does not need an API key.
Use this for Hugging Face Inference Providers.
To search for eligible models:
Provider: Hugging Face
Models > Search Hugging Face models...
The search window has three types:
Chat / code / text
Vision / image input
Any compatible
You can search for names like:
qwen
gemma
deepseek
coder
vision
The search list is filtered toward models Hugging Face reports as served by at least one Inference Provider.
To run a Hugging Face layer, add a Hugging Face token:
Settings > API key > Enter API key...
The search can often load public catalog results without a token, but running the model usually requires one.
Each layer can use either:
Shared provider key
Layer-specific key
Use a shared key when several layers use the same provider.
Use a layer-specific key when one layer should use a different account, provider route, or token.
API keys are not saved into session files unless you enable:
Save keys
For safety, leave Save keys off unless you really want the session file to contain your keys.
Use Models inside a layer.
Options include:
Load from provider
Search Hugging Face models...
Import model list from file...
Enter model name...
Clear model list
For Hugging Face, the recommended path is:
Models > Search Hugging Face models...
For Gemini, Anthropic, OpenAI-compatible servers, and Ollama, use:
Models > Load from provider
Project input, layer prompts, and chat messages can include attachments.
Buttons:
Add file
Add URL
Clear files
Text and code files are added as readable context.
Images are sent as image input when the selected provider/model supports image input.
PDFs are sent directly to Gemini and Anthropic when supported. Other providers still receive the filename and any readable text LayerGen can include.
Large local files are not copied into the session file. LayerGen saves their file paths, so keep attached files in place if you want a saved session to keep using them.
Layer outputs and chat transcripts render common model formatting more cleanly.
LayerGen styles:
# headings
**bold**
*italic*
`inline code`
fenced code blocks
[links](https://example.com)
> quotes
- lists
~~strikethrough~~
$math$
The display is only visual. Copying or saving still uses the underlying text the model produced.
Each layer output has:
Copy
Save
Clear
Use Save when you want to write the generated output to a file.
LayerGen chooses a suggested file extension from the layer's language setting.
Open the Flowchart tab to see how layers feed into each other.
The diagram updates based on variables such as:
{previous_output}
{all_previous_outputs}
{layer_1_output}
{layer_2_output}
Click Refresh if you want to force an update.
Use the File menu:
File > Save session
File > Save session as...
File > Load session...
File > New project
Keyboard shortcuts:
Ctrl+S
Ctrl+Shift+S
LayerGen saves:
- Project input
- Project attachments
- Layers
- Prompts
- Model choices
- Settings
- Outputs
- Chat history
- Flow state
API keys are saved only if Save keys is enabled.
Temperature controls how random or creative a model is.
Good coding range:
0.2 to 0.7
Lower temperature:
More predictable
More consistent
Less creative
Higher temperature:
More varied
More creative
More likely to make mistakes
Try running it from Command Prompt:
cd C:\Users\haoqi\Documents\Codex\2026-08-03\thi\outputs
python LayerGen.pyIf python does not work, try:
py LayerGen.pyTry:
Models > Load from provider
For Hugging Face, try:
Models > Search Hugging Face models...
If the provider needs an API key, add it first.
Use the Hugging Face search menu and pick from the eligible results instead of typing a model manually.
For image input, use:
Vision / image input
For Qwen coding models, search:
qwen coder
For Gemma models, search:
gemma
The token is missing, invalid, or does not have the right permission.
Add a Hugging Face token here:
Settings > API key > Enter API key...
Your token or account may not be allowed to use the selected provider route.
Check that:
- Your token has Inference Providers permission.
- Your Hugging Face account can use the selected provider.
- Billing or credits are available if the provider requires them.
Try a short test:
Max tokens: 20
Prompt: hello
If that works, increase max tokens again.
Large models can take much longer than small models.
Use the Chat with dropdown in the Chat tab.
The dropdown controls which layer is fine-tuned. Chat should update that layer and all layers after it, but it should not rerun earlier layers.
LayerGen saves local attachment paths, not full file contents.
Keep attached files in the same location if you want old sessions to keep finding them.
Main app:
LayerGen.py
README:
README_LayerGen.md
Synced compatibility copies:
code_generator_app.py
three_layer_code_generator_gui.py
Backups may also appear in the folder. They are kept so you can return to older versions if a large change does not work the way you wanted.