Skip to content

Add detection of the current operating system distribution #13

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add system info detection
  • Loading branch information
tatuke committed Jun 23, 2025
commit fa5f34ca2cba3632bb08ff84a59c97cb1b7d4ef0
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ venv/
ENV/
env.bak/
venv.bak/
config.example.yaml


# Spyder project settings
.spyderproject
Expand Down Expand Up @@ -238,3 +240,4 @@ pyrightconfig.json
brew_formula/
.pypi_token

comm.py
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies = [
"prompt_toolkit",
"pyinstaller>=6.13.0",
"pyperclip>=1.9.0",
"distro=1.9.0",
]

[project.scripts]
Expand Down
10 changes: 5 additions & 5 deletions src/open_codex/agent_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def get_system_prompt() -> str:
.joinpath("prompt.txt") \
.read_text(encoding="utf-8")

# @staticmethod
# def get_phi_agent() -> LLMAgent:
# from open_codex.agents.phi_4_mini_agent import Phi4MiniAgent
# system_prompt = AgentBuilder.get_system_prompt()
# return Phi4MiniAgent(system_prompt=system_prompt)
@staticmethod
def get_phi_agent() -> LLMAgent:
from open_codex.agents.phi_4_mini_agent import Phi4MiniAgent
system_prompt = AgentBuilder.get_system_prompt()
return Phi4MiniAgent(system_prompt=system_prompt)

@staticmethod
def get_ollama_agent(model: str, host: str) -> LLMAgent:
Expand Down
2 changes: 1 addition & 1 deletion src/open_codex/interfaces/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class LLMAgent(ABC):
@abstractmethod
def one_shot_mode(self, user_input: str) -> str:
def one_shot_mode(self, user_input: str, system_info: str) -> str:
pass

25 changes: 20 additions & 5 deletions src/open_codex/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
import argparse
import subprocess
import platform

from open_codex.agent_builder import AgentBuilder
from open_codex.interfaces.llm_agent import LLMAgent
Expand Down Expand Up @@ -30,6 +31,20 @@ def get_keypress():
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return key
# sys details
def get_system_info():
system = platform.system()
release = platform.release()
version = platform.version()
info = f"OSsystem: {system} {release} {version}"
if system == "Linux":
try:
import distro
info += f"\nDistribution: {distro.name(pretty=True)}"
except ImportError:
pass
return info


def get_user_action():
print(f"{BLUE}What do you want to do with this command?{RESET}")
Expand Down Expand Up @@ -65,9 +80,10 @@ def get_agent(args: argparse.Namespace) -> LLMAgent:
print(f"{BLUE}Using model: phi-4-mini-instruct{RESET}")
return AgentBuilder.get_phi_agent()

def run_one_shot(agent: LLMAgent, user_prompt: str) -> str:
def run_one_shot(agent: LLMAgent, user_prompt: str, system_info: str) -> str:
full_prompt = f"{user_prompt}\n\nSystem info: {system_info}"
try:
return agent.one_shot_mode(user_prompt)
return agent.one_shot_mode(full_prompt)
except ConnectionError:
print(f"{RED}Could not connect to Model.{RESET}", file=sys.stderr)
sys.exit(1)
Expand Down Expand Up @@ -105,10 +121,9 @@ def parse_args() -> argparse.Namespace:
def main():
args = parse_args()
agent = get_agent(args)

# join the prompt arguments into a single string
system_info = get_system_info()
prompt = " ".join(args.prompt).strip()
response = run_one_shot(agent, prompt)
response = run_one_shot(agent, prompt, system_info)
print_response(response)
action = get_user_action()
run_user_action(action, response)
Expand Down