Hijack system prompt for OpenAI ChatCompletion and Anthropic API by prepending a configurable prefix with terminal confirmation.
Project description
Jiezhu for Python
jiezhu is a lightweight Python client library for calling OpenAI-style Chat Completions API and Anthropic-style API, with the ability to automatically inject a system prompt prefix to "catch" the user input steadily.
Prerequisites
To use this library, you need to have Python 3.8 or higher installed. This library does not automatically install any ai SDK. You also need to have the OpenAI Python SDK installed for OpenAI API support, and the Anthropic Python SDK installed for Anthropic API support.
Installation
Install from PyPI
pip install jiezhu[openai] # or jiezhu[claude] if you want claude API support
Install from Source
- Clone the universal repository of Jiezhu and navigate to the root directory of python library.
git clone https://github.com/Not-A-DevStudio/libjiezhu.git
cd libjiezhu/jiezhu-py
Under the root directory of this python library, run:
pip install -e ./
Given that this repository contains both C++ and Python libraries, you may also find a packed Python source file of this repository.
Install from Pre-built Binary Package
-
Go to the Release page of this repository, and find the latest release.
-
Download the pre-built binary package for Python (e.g.,
jiezhu-0.1.0-py3-none-any.whl). -
Install the downloaded package using pip:
pip install path/to/downloaded/wheel.whl
Quick Start
OpenAI Support
from jiezhu import install
install(require_confirm=True) # Call this function once at the beginning of your program to enable the library.
from openai import OpenAI
client = OpenAI()
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "how are you?"},
],
)
you will see that the system prompt prefix has been automatically prepended to the messages, which encourages the model to "catch" the user input steadily.
Claude / Anthropic Support
Jiezhu also supports the Anthropic Python SDK. Install the optional dependency:
pip install jiezhu[claude]
Then use it the same way — install() patches both OpenAI and Anthropic SDKs:
from jiezhu import install
install(require_confirm=False)
from anthropic import Anthropic
client = Anthropic()
message = client.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
system="You are a helpful assistant.",
messages=[
{"role": "user", "content": "how are you?"},
],
)
The prefix is prepended to Claude's top-level system parameter (supports both string and content-block list formats). If the anthropic package is not installed, Claude patching is silently skipped.
Customization
You can customize the system prompt prefix by passing a prefix_text argument to the install() function
Attention: if your environment does not support interreactive input (e.g. Jupyter Notebook), please set
require_confirm=Falsewhen callinginstall(), otherwise the library will not work.
Security and Privacy
Security
Although this library does hijack the OpenAI Python SDK, it only modifies the messages field of the chat completion request by prepending a system prompt prefix. It require a confirmation from the user before hijacking, and the user can choose to auto-confirm by setting require_confirm=False.
Anytime this library modifies the request and no matter how require_confirm is set to False or True, it will print the alert message to the console.
Besides, this library requires user to explicitly enable by calling install(), and it will not do anything if install() is not called. And even if install() is called, the user can still choose to disable this library by calling uninstall().
Privacy
The library does not collect or transmit any user data, and it does not have any network communication of its own. It only modifies the request before it is sent to OpenAI's servers.
Something Funny
Here is a auto-completion code that ChatGPT generates when I try to set default system prompt in the code, which is quite funny. I only typed "请遵循以下要求"(please follow the instruction bellow) and GPT completed the rest:
def install(
prefix_text: str = "请遵循以下要求:\n- 稳稳地接住用户的输入,确保不丢失任何信息。\n- 在回复中保持用户输入的完整性,不要删除或修改任何内容。\n- 如果用户输入过长,仍然要尽力接住,并在回复中注明已截断。\n",
require_confirm: bool = True,
max_preview_chars: int = 2000,
input_fn: Optional[Callable[[str], str]] = None,
output=None,
)
That is how GPT stick to "接住" the user input.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jiezhu-0.3.0-py3-none-any.whl.
File metadata
- Download URL: jiezhu-0.3.0-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7cb6f68098a8606bd5501ab4f359f790dd68c7dd3ba6061c66b645e64b95104
|
|
| MD5 |
267d1c6f4a7b8463e0486c899b309f82
|
|
| BLAKE2b-256 |
307d1f9f601527b15a18827147541e6f3a3609402a4d301a7b4c10882d99ff8a
|