Skip to content

Commit

Permalink
feat: add system info to the about_user prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbrayo committed Oct 8, 2024
1 parent 945b5ce commit 397c091
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gptme/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"""

import logging
import re
import os
import platform
import subprocess
from collections.abc import Generator, Iterable
from typing import Literal
Expand Down Expand Up @@ -56,6 +58,7 @@ def prompt_full(interactive: bool) -> Generator[Message, None, None]:
if interactive:
yield from prompt_user()
yield from prompt_project()
yield from prompt_systeminfo()


def prompt_short(interactive: bool) -> Generator[Message, None, None]:
Expand Down Expand Up @@ -208,8 +211,39 @@ def prompt_tools(examples: bool = True) -> Generator[Message, None, None]:
prompt += "\n\n*End of Tools List.*"
yield Message("system", prompt.strip() + "\n\n")

def prompt_systeminfo() -> Generator[Message, None, None]:
"""Generate the system information prompt."""
if os.name == "posix":
os_info = get_system_distro()
os_version = platform.uname().release
elif os.name == "nt":
os_info = "Windows"
os_version = platform.version()
elif os.name == "darwin":
os_info = "macOS"
os_version = platform.mac_ver()[0]
else:
os_info = "unknown"
os_version = "unknown"

prompt = f"## System Information\n\n**OS:** {os_info}\n**Version:** {os_version}"

yield Message( "system", prompt,)

def get_system_distro() -> str:
"""Get the system distribution name."""
regex = r"^NAME=\"([^\"]+)\""

if os.path.exists("/etc/os-release"):
with open("/etc/os-release") as f:
for line in f:
match = re.match(regex, line)
if match:
return match.group(1)
return "unknown"

document_prompt_function(interactive=True)(prompt_gptme)
document_prompt_function()(prompt_user)
document_prompt_function()(prompt_project)
document_prompt_function()(prompt_tools)
document_prompt_function()(prompt_systeminfo)

0 comments on commit 397c091

Please sign in to comment.