Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FORCE_USER_ROLE option to force api calls to use role:user instead of role:system #567

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions sgpt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def main(
callback=inst_funcs,
hidden=True, # Hiding since should be used only once.
),
force_user_role: bool = typer.Option(
cfg.get("FORCE_USER_ROLE") == "true",
help="Force role: user in API calls",
rich_help_panel="Chat Options",
),
) -> None:
stdin_passed = not sys.stdin.isatty()

Expand Down
1 change: 1 addition & 0 deletions sgpt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"API_BASE_URL": os.getenv("API_BASE_URL", "default"),
"PRETTIFY_MARKDOWN": os.getenv("PRETTIFY_MARKDOWN", "true"),
"USE_LITELLM": os.getenv("USE_LITELLM", "false"),
"FORCE_USER_ROLE": os.getenv("FORCE_USER_ROLE", "false"),
# New features might add their own config variables here.
}

Expand Down
5 changes: 3 additions & 2 deletions sgpt/handlers/chat_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

CHAT_CACHE_LENGTH = int(cfg.get("CHAT_CACHE_LENGTH"))
CHAT_CACHE_PATH = Path(cfg.get("CHAT_CACHE_PATH"))

FORCE_USER_ROLE = cfg.get("FORCE_USER_ROLE") == "true"

class ChatSession:
"""
Expand Down Expand Up @@ -168,7 +168,8 @@ def validate(self) -> None:
def make_messages(self, prompt: str) -> List[Dict[str, str]]:
messages = []
if not self.initiated:
messages.append({"role": "system", "content": self.role.role})
role = "system" if FORCE_USER_ROLE == False else "user"
messages.append({"role": role, "content": self.role.role})
messages.append({"role": "user", "content": prompt})
return messages

Expand Down
5 changes: 3 additions & 2 deletions sgpt/handlers/default_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

CHAT_CACHE_LENGTH = int(cfg.get("CHAT_CACHE_LENGTH"))
CHAT_CACHE_PATH = Path(cfg.get("CHAT_CACHE_PATH"))

FORCE_USER_ROLE = cfg.get("FORCE_USER_ROLE") == "true"

class DefaultHandler(Handler):
def __init__(self, role: SystemRole, markdown: bool) -> None:
super().__init__(role, markdown)
self.role = role

def make_messages(self, prompt: str) -> List[Dict[str, str]]:
role = "system" if FORCE_USER_ROLE == False else "user"
messages = [
{"role": "system", "content": self.role.role},
{"role": role, "content": self.role.role},
{"role": "user", "content": prompt},
]
return messages