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

feat: add platform info to the system prompt #171

Merged
merged 7 commits into from
Oct 29, 2024
Merged
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
41 changes: 40 additions & 1 deletion 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 All @@ -81,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 <thinking> tags.
Expand Down Expand Up @@ -209,7 +212,43 @@ def prompt_tools(examples: bool = True) -> Generator[Message, None, None]:
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 = ""

prompt = f"## System Information\n\n**OS:** {os_info} {os_version}".strip()

yield Message(
"system",
prompt,
)


def get_system_distro() -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using the distro package to get the system distribution name for better accuracy and maintainability.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellipsis-dev compile this regex

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brayo-pip, I have addressed your comments in pull request #229


You can configure Ellipsis to address comments with a direct commit or a side PR, see docs.

"""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)]
return "Linux"
Comment on lines +238 to +247
Copy link
Owner

@ErikBjare ErikBjare Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get the distro version here (BUILD_ID=rolling on Arch, VERSION_ID="22.04" on Ubuntu) instead of using platform.uname().release

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check into this. Also getting the same on my laptop, capturing the kernel version instead of the distro version.



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)
1 change: 0 additions & 1 deletion gptme/tools/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading