From d760d2b68b106e1a05a70eb3af56df3c4e5872b8 Mon Sep 17 00:00:00 2001 From: Brayo Date: Tue, 8 Oct 2024 18:12:50 +0300 Subject: [PATCH 1/7] feat: create a system info prompt --- gptme/prompts.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gptme/prompts.py b/gptme/prompts.py index 2ec2ec0d2..1cced8d3d 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -6,7 +6,9 @@ """ import logging +import re import os +import platform import subprocess from collections.abc import Generator, Iterable from typing import Literal @@ -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]: @@ -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 platform.system() == "Linux": + os_info = get_system_distro() + os_version = platform.uname().release + elif platform.system() == "Windows": + os_info = "Windows" + os_version = platform.version() + elif platform.system() == "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) From cf240e1163051bac4bfbd39fe38ec809dc601107 Mon Sep 17 00:00:00 2001 From: Brayo Date: Tue, 8 Oct 2024 23:22:51 +0300 Subject: [PATCH 2/7] fix: update the prompt --- gptme/prompts.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/gptme/prompts.py b/gptme/prompts.py index 1cced8d3d..e08dfb908 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -232,15 +232,15 @@ def prompt_systeminfo() -> Generator[Message, None, None]: def get_system_distro() -> str: """Get the system distribution name.""" - regex = r"^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" + matches = re.search(regex, line) + if matches: + return matches.string[matches.start(1) : matches.end(1)] + return "Linux" document_prompt_function(interactive=True)(prompt_gptme) document_prompt_function()(prompt_user) From 5559c95e9e5aa7fdebafda4596817f675d588c14 Mon Sep 17 00:00:00 2001 From: Brayo Date: Mon, 21 Oct 2024 00:07:12 +0300 Subject: [PATCH 3/7] chore: remove trailing comma in prompt --- gptme/prompts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gptme/prompts.py b/gptme/prompts.py index e08dfb908..684149001 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -84,7 +84,7 @@ def prompt_gptme(interactive: bool) -> Generator[Message, None, None]: base_prompt = f""" You are gptme v{__version__}, a general-purpose AI assistant powered by LLMs. -You are designed to help users with programming tasks, such as writing code, debugging, and learning new concepts. +You are designed to help users with programming tasks, such as writing code, debugging and learning new concepts. You can run code, execute terminal commands, and access the filesystem on the local machine. You will help the user with writing code, either from scratch or in existing projects. You will think step by step when solving a problem, in tags. From 428f4a602067d4dd0d2cdde6e278c3ed5b2603e7 Mon Sep 17 00:00:00 2001 From: Brayo Date: Mon, 21 Oct 2024 00:07:55 +0300 Subject: [PATCH 4/7] feat: remove redundant platform specification --- gptme/tools/shell.py | 1 - 1 file changed, 1 deletion(-) diff --git a/gptme/tools/shell.py b/gptme/tools/shell.py index e2110e5e2..d02a054dc 100644 --- a/gptme/tools/shell.py +++ b/gptme/tools/shell.py @@ -50,7 +50,6 @@ def get_installed_programs() -> set[str]: When you send a message containing bash code, it will be executed in a stateful bash shell. The shell will respond with the output of the execution. Do not use EOF/HereDoc syntax to send multiline commands, as the assistant will not be able to handle it. -{'The platform is macOS.' if is_macos else ''} These programs are available, among others: {shell_programs_str} From c3107c880b97d45cea25c33e0dafbe813a6973e5 Mon Sep 17 00:00:00 2001 From: "ellipsis-dev[bot]" <65095814+ellipsis-dev[bot]@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:14:08 +0000 Subject: [PATCH 5/7] address comments left by @brayo-pip on #171 (feat: add platform info to the system prompt); --- gptme/prompts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gptme/prompts.py b/gptme/prompts.py index 684149001..2484d2bf9 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -232,7 +232,7 @@ def prompt_systeminfo() -> Generator[Message, None, None]: def get_system_distro() -> str: """Get the system distribution name.""" - regex = r"^NAME=\"?([^\"]+)\"?" + regex = re.compile(r"^NAME=\"?([^\"]+)\"?") if os.path.exists("/etc/os-release"): with open("/etc/os-release") as f: From 56bd22f93bab801d8f2d794a72f36db250623fcd Mon Sep 17 00:00:00 2001 From: Brayo Date: Sat, 26 Oct 2024 17:26:31 +0300 Subject: [PATCH 6/7] feat: compile regex and improve readability --- gptme/prompts.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gptme/prompts.py b/gptme/prompts.py index 2484d2bf9..fa81e80d5 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -230,16 +230,16 @@ def prompt_systeminfo() -> Generator[Message, None, None]: yield Message( "system", prompt,) +regex = re.compile(r"^NAME=\"?([^\"]+)\"?") def get_system_distro() -> str: """Get the system distribution name.""" - regex = re.compile(r"^NAME=\"?([^\"]+)\"?") if os.path.exists("/etc/os-release"): with open("/etc/os-release") as f: for line in f: - matches = re.search(regex, line) - if matches: - return matches.string[matches.start(1) : matches.end(1)] + match = regex.match(line) + if match: + return match.group(1) return "Linux" document_prompt_function(interactive=True)(prompt_gptme) From 94355b91f61f4413718b54ec0f56660bf2dfdb6c Mon Sep 17 00:00:00 2001 From: Brayo Date: Sat, 26 Oct 2024 17:33:26 +0300 Subject: [PATCH 7/7] Update gptme/prompts.py Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- gptme/prompts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gptme/prompts.py b/gptme/prompts.py index fa81e80d5..081afcb9b 100644 --- a/gptme/prompts.py +++ b/gptme/prompts.py @@ -230,7 +230,7 @@ def prompt_systeminfo() -> Generator[Message, None, None]: yield Message( "system", prompt,) -regex = re.compile(r"^NAME=\"?([^\"]+)\"?") +regex = re.compile(r'^NAME=["']?([^"']+)["']?') def get_system_distro() -> str: """Get the system distribution name."""