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 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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ ENV/
env.bak/
venv.bak/

config.example.yaml


# Spyder project settings
.spyderproject
.spyproject
Expand Down Expand Up @@ -238,3 +241,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
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