Skip to content

Commit ae84989

Browse files
authored
Add support for customizing API Base URL using environment variables (#207)
* Update chatgpt_config.py Add base api environment variables * Update README.md Add guidance for API base changes * Fix the problem that test-connection cannot run * Update test_connection.py Class variable read modification
1 parent 0a557e9 commit ae84989

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
## Quick Start
6262
1. Create a virtual environment if necessary. (`virtualenv -p python3 venv`, `source venv/bin/activate`)
6363
2. Install the project with `pip3 install git+https://github.com/GreyDGL/PentestGPT`
64-
3. **Ensure that you have link a payment method to your OpenAI account.** Export your API key with `export OPENAI_KEY='<your key here>'`
64+
3. **Ensure that you have link a payment method to your OpenAI account.** Export your API key with `export OPENAI_KEY='<your key here>'`,export API base with `export OPENAI_BASEURL='https://api.xxxx.xxx/v1'`if you need.
6565
4. Test the connection with `pentestgpt-connection`
6666
5. For Kali Users: use `tmux` as terminal environment. You can do so by simply run `tmux` in the native terminal.
6767
6. To start: `pentestgpt --logging`
@@ -101,6 +101,7 @@ PentestGPT is tested under `Python 3.10`. Other Python3 versions should work but
101101
2. To use OpenAI API
102102
- **Ensure that you have link a payment method to your OpenAI account.**
103103
- export your API key with `export OPENAI_KEY='<your key here>'`
104+
- export API base with `export OPENAI_BASEURL='https://api.xxxx.xxx/v1'`if you need.
104105
- Test the connection with `pentestgpt-connection`
105106
3. To verify that the connection is configured properly, you may run `pentestgpt-connection`. After a while, you should see some sample conversation with ChatGPT.
106107
- A sample output is below

pentestgpt/config/chatgpt_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class ChatGPTConfig:
1212
# model: str = "text-davinci-002-render-sha"
1313
model: str = "gpt-4-browsing"
1414

15-
api_base: str = "https://api.openai.com/v1"
15+
#api_base: str = "https://api.openai.com/v1"
16+
#set up the openai api base, default:"https://api.openai.com/v1"
17+
api_base: str = os.getenv("OPENAI_BASEURL", "https://api.openai.com/v1")
1618

1719
log_dir: str = "logs"
1820

pentestgpt/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def main():
3030
parser.add_argument(
3131
"--baseUrl",
3232
type=str,
33-
default="https://api.openai.com/v1",
33+
default=ChatGPTConfig().api_base,
3434
help="Base URL for OpenAI API,default: https://api.openai.com/v1",
3535
)
3636

0 commit comments

Comments
 (0)