Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ You can setup some parameters in runtime configuration file `~/.config/shell_gpt
OPENAI_API_KEY=your_api_key
# Base URL of the backend server. If "default" URL will be resolved based on --model.
API_BASE_URL=default
# User-Agent header for API requests. If "default" the OpenAI SDK User-Agent is used.
# Useful for proxies or API gateways that filter requests based on User-Agent.
OPENAI_USER_AGENT=default
# Max amount of cached message per chat session.
CHAT_CACHE_LENGTH=100
# Chat cache folder.
Expand Down
1 change: 1 addition & 0 deletions sgpt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"OPENAI_USE_FUNCTIONS": os.getenv("OPENAI_USE_FUNCTIONS", "true"),
"SHOW_FUNCTIONS_OUTPUT": os.getenv("SHOW_FUNCTIONS_OUTPUT", "false"),
"API_BASE_URL": os.getenv("API_BASE_URL", "default"),
"OPENAI_USER_AGENT": os.getenv("OPENAI_USER_AGENT", "default"),
"PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"),
"USE_LITELLM": os.getenv("USE_LITELLM", "false"),
"SHELL_INTERACTION": os.getenv("SHELL_INTERACTION ", "true"),
Expand Down
3 changes: 3 additions & 0 deletions sgpt/handlers/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
else:
from openai import OpenAI

user_agent = cfg.get("OPENAI_USER_AGENT")
if user_agent != "default":
additional_kwargs["default_headers"] = {"User-Agent": user_agent}
client = OpenAI(**additional_kwargs) # type: ignore
completion = client.chat.completions.create
additional_kwargs = {}
Expand Down