|
|
5 天之前 | |
|---|---|---|
| Makefile | 5 天之前 | |
| README.md | 5 天之前 | |
| config.json | 5 天之前 | |
| go.mod | 5 天之前 | |
| go.sum | 5 天之前 | |
| prompt-rewriter.go | 5 天之前 |
A Bifrost PreLLMHook plugin that uses a small, fast local model (e.g. Qwen3-4B-Instruct) to rewrite and improve user prompts before they are sent to a larger model (e.g. Qwen3.6-35B or Qwen3-Coder-Next).
This is useful when you want better prompt quality without manually engineering every request.
PreLLMHookIf the small model fails or times out, the plugin fails open and uses the original prompt.
prompt-rewriter/
├── main.go # Plugin source
├── go.mod
├── Makefile
└── README.md
# Download dependencies
make deps
# Build the shared object
make
# Or rebuild everything
make rebuild
This produces prompt-rewriter.so.
Important: Build the plugin on the same OS + architecture as the Bifrost binary (Linux/macOS, amd64 or arm64). Cross-compilation is not supported for Go plugins.
Add the plugin to your Bifrost config.json:
{
"plugins": [
{
"name": "prompt-rewriter",
"enabled": true,
"path": "/absolute/path/to/prompt-rewriter/prompt-rewriter.so",
"config": {
"small_model_endpoint": "http://localhost:8081/v1/chat/completions",
"small_model_name": "qwen3-4b-instruct",
"enable_logging": true,
"timeout_seconds": 12
}
}
]
}
| Key | Type | Default | Description |
|---|---|---|---|
small_model_endpoint |
string | http://localhost:8081/v1/chat/completions |
OpenAI-compatible endpoint for the small model |
small_model_name |
string | qwen3-4b-instruct |
Model name sent to the small model server |
rewrite_system_prompt |
string | (see source) | System prompt that instructs the small model how to rewrite |
enable_logging |
bool | true |
Log original + rewritten prompts |
timeout_seconds |
int | 15 |
Timeout for the small model call |
Original user message:
make a function that reverses a linked list
After rewrite (example):
Write a clean, well-documented function that reverses a singly linked list.
Include the node definition if needed, handle edge cases (empty list, single node),
and provide both iterative and recursive versions if practical. Use clear variable names.
The improved prompt is then sent to your larger model.
req.ChatRequest.Model inside PreLLMHook.Use and modify freely.