How to Customize the System Prompt in config.py for GPT‑Academic
You can customize the system prompt in gpt_academic by setting the GPT_ACADEMIC_INIT_SYS_PROMPT environment variable, overriding it in a config_private.py file, or directly modifying the INIT_SYS_PROMPT constant in config.py.
The gpt_academic repository (binary-husky/gpt_academic) manages its default system prompt through a hierarchical configuration system that prioritizes environment variables over file-based settings. When you need to customize the system prompt in config.py, understanding this priority chain ensures your changes persist across deployments without conflicting with runtime overrides.
Configuration Hierarchy and Priority
The framework resolves the INIT_SYS_PROMPT value through a strict three-tier priority system implemented in shared_utils/config_loader.py. The loader uses an LRU-cached function get_conf to retrieve values, checking sources in descending order of precedence.
Method 1: Environment Variables (Highest Priority)
The configuration loader first checks for environment variables via read_env_variable in shared_utils/config_loader.py. Set either GPT_ACADEMIC_INIT_SYS_PROMPT or INIT_SYS_PROMPT to override all file-based configurations:
export GPT_ACADEMIC_INIT_SYS_PROMPT="You are an expert academic editor specializing in LaTeX formatting."
python main.py
For Docker deployments, add this to your docker-compose.yml:
environment:
- GPT_ACADEMIC_INIT_SYS_PROMPT=You are a concise code reviewer focused on Python best practices.
Method 2: Private Configuration File
If no environment variable exists, the loader attempts to import config_private.py (lines 64‑77 in shared_utils/config_loader.py). Create this file in your project root to override config.py without modifying version-controlled files:
# config_private.py
INIT_SYS_PROMPT = "You are a helpful research assistant specializing in statistical analysis."
Method 3: Direct Editing of config.py
As the fallback default, you can directly edit line 122 in config.py where INIT_SYS_PROMPT is defined. This method is suitable for local development but requires caution during version updates:
# config.py (line 122)
INIT_SYS_PROMPT = "You are a helpful AI assistant specialized in academic writing."
Runtime Configuration Updates
Because get_conf caches results using @lru_cache, static file changes require a restart. However, the framework provides set_conf and set_multi_conf in shared_utils/config_loader.py (lines 20‑27) to update configuration dynamically without restarting the application.
To programmatically change the system prompt from a plugin or external script:
from shared_utils.config_loader import set_conf
# Update the system prompt for the current session
set_conf('INIT_SYS_PROMPT', "You are an enthusiastic mentor for data science questions.")
This function clears the LRU cache, updates os.environ, and re-evaluates the configuration immediately.
Step-by-Step Implementation Examples
Static Configuration via config.py
For permanent, repository-level changes suitable for forked deployments:
- Open
config.pyin your project root - Locate line 122 where
INIT_SYS_PROMPTis defined - Replace the default string with your custom prompt
- Save and restart the application via
python main.py
The new value appears in the Gradio UI toolbar as the default textbox content.
Docker and CI/CD Deployment
For production containers where editing source files is impractical:
# Dockerfile
ENV GPT_ACADEMIC_INIT_SYS_PROMPT="You are a security-focused code auditor."
Or pass it at runtime:
docker run -e GPT_ACADEMIC_INIT_SYS_PROMPT="You are a security-focused code auditor." binary-husky/gpt_academic
Programmatic Runtime Updates
For plugins that need to switch personas based on user input:
from shared_utils.config_loader import set_multi_conf
# Batch update multiple configuration values
set_multi_conf({
'INIT_SYS_PROMPT': "You are a translator specializing in academic Chinese-to-English translation.",
'LLM_MODEL': "gpt-4"
})
Gradio UI Modifications
The simplest method requires no code changes. In themes/gui_toolbar.py (line 16), the UI initializes a textbox with the INIT_SYS_PROMPT value retrieved via get_conf in main.py:
- Locate the "System prompt" textbox in the Gradio toolbar
- Delete the default text and enter your custom instructions
- Press Enter to trigger
set_confunder the hood
This updates the configuration for the running session without restarting the server.
Summary
INIT_SYS_PROMPTinconfig.py(line 122) serves as the default system prompt constant- Environment variables (
GPT_ACADEMIC_INIT_SYS_PROMPT) override file-based settings with the highest priority config_private.pyprovides a version-control-friendly override mechanismset_confandset_multi_confinshared_utils/config_loader.pyenable runtime updates by clearing the@lru_cache- The Gradio toolbar in
themes/gui_toolbar.pyconsumes this value and allows live editing via the UI textbox
Frequently Asked Questions
How do I persist custom system prompts across Docker container restarts?
Mount a config_private.py file as a volume or set the GPT_ACADEMIC_INIT_SYS_PROMPT environment variable in your docker-compose.yml file. Direct edits to config.py inside containers are lost when the container restarts unless you commit the image layer.
Why doesn't my change to config.py take effect immediately?
The gpt_academic loader uses @lru_cache to cache configuration values for performance. You must restart the Python process to clear this cache and reload config.py, or use set_conf('INIT_SYS_PROMPT', "new prompt") to update the value at runtime.
Can I switch system prompts dynamically without restarting the server?
Yes. Call set_conf('INIT_SYS_PROMPT', "your new prompt") from any plugin or Python module, or edit the textbox in the Gradio UI toolbar and press Enter. Both methods invoke the configuration setter that clears the cache and updates the global state immediately.
What is the difference between config.py and config_private.py?
config.py contains default settings tracked by version control, while config_private.py is ignored by Git (via .gitignore) and loaded afterward to override specific values. Using config_private.py prevents merge conflicts when pulling updates from the upstream binary-husky/gpt_academic repository.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →