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

[RSPEED-184] Rename upstream project to reflect the RPM naming #12

Merged
merged 1 commit 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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ __pycache__/
# ignore thirdy-party tool caches
.ruff_cache

# ignore shellai_history
shellai_history.json
# ignore command_line_assistant_history
command_line_assistant_history.json

# ignore venv
[.]venv/
Expand Down
18 changes: 9 additions & 9 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
specfile_path: packaging/shellai.spec
upstream_package_name: shellai
downstream_package_name: shellai
upstream_project_url: https://github.com/rhel-lightspeed/shellai
specfile_path: packaging/command-line-assistant.spec
upstream_package_name: command-line-assistant
downstream_package_name: command-line-assistant
upstream_project_url: https://github.com/rhel-lightspeed/command-line-assistant

srpm_build_deps: []

Expand All @@ -10,22 +10,22 @@ jobs:
- job: copr_build
trigger: pull_request
owner: "@rhel-lightspeed"
project: shellai
project: command-line-assistant
targets:
- epel-8-x86_64
- epel-9-x86_64
- epel-10-x86_64
actions:
# do not get the version from a tag (git describe) but from the spec file
get-current-version:
- grep -oP '^Version:\s+\K\S+' packaging/shellai.spec
- grep -oP '^Version:\s+\K\S+' packaging/command-line-assistant.spec

# Build RPMs for main branch
- job: copr_build
trigger: commit
branch: main
owner: "@rhel-lightspeed"
project: shellai
project: command-line-assistant
targets:
- epel-8-x86_64
- epel-9-x86_64
Expand All @@ -34,7 +34,7 @@ jobs:
# bump spec so we get release starting with 2 and hence all the default branch builds will
# have higher NVR than all the PR builds
post-upstream-clone:
- rpmdev-bumpspec --comment='latest upstream build' ./packaging/shellai.spec
- rpmdev-bumpspec --comment='latest upstream build' ./packaging/command-line-assistant.spec
# do not get the version from a tag (git describe) but from the spec file
get-current-version:
- grep -oP '^Version:\s+\K\S+' packaging/shellai.spec
- grep -oP '^Version:\s+\K\S+' packaging/command-line-assistant.spec
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
hooks:
- id: check-rebase
args:
- https://github.com/rhel-lightspeed/shellai.git
- https://github.com/rhel-lightspeed/command-line-assistant.git
stages: [manual, pre-push]
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.1
Expand Down
38 changes: 19 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to ShellAI
# Contributing to Command Line Assistant

The following is a set of guidelines for contributing to ShellAI codebase, which are hosted in the [RHEL Lightspeed
The following is a set of guidelines for contributing to Command Line Assistant codebase, which are hosted in the [RHEL Lightspeed
Organization](https://github.com/rhell-lightspeed) on GitHub. These are mostly guidelines, not rules.

* [Road Core Service](https://github.com/road-core/service)
Expand Down Expand Up @@ -28,7 +28,7 @@ Quickstart - Set up Git](https://docs.github.com/en/get-started/quickstart/set-u

### Forking a repository

Forking is necessary if you want to contribute with ShellAI, but if you are unsure on how this work (Or what a fork is),
Forking is necessary if you want to contribute with Command Line Assistant, but if you are unsure on how this work (Or what a fork is),
head out to this quickstart guide from GitHub. [GitHub Quickstart - Fork a
repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo)

Expand Down Expand Up @@ -59,46 +59,46 @@ make install

### Getting a backend to manage your queries

ShellAI depends on a backend service to interact with LLM providers (such as OpenAI, IBM WatsonX, etc...). For that
Command Line Assistant depends on a backend service to interact with LLM providers (such as OpenAI, IBM WatsonX, etc...). For that
purpose, we strongly recommend setting up [Road Core Service](https://github.com/road-core/service). After you have
everything in order, the next steps should work without extra configuration.

### Update config to your needs

The project root contains a [basic configuration](./config.yaml) file that captures a set of options for shellai. You
The project root contains a [basic configuration](./config.yaml) file that captures a set of options for Command Line Assistant. You
can use it the way it is, or, if needed, can update to your needs.

```yml
# Example config.yaml
output_capture: # if '^' is used, last command output will be used for query context
enforce_script: false # otherwise recording via script session will be enforced
output_file: /tmp/shellai_output.txt # file with output(s) of regular commands (e.g. ls, echo, etc.)
output_file: /tmp/command-line-assistant_output.txt # file with output(s) of regular commands (e.g. ls, echo, etc.)
prompt_separator: '$' # Keep non-empty if your file contains only output of commands (not prompt itself)
backend_service:
# proxy: http://todo:8080
query_endpoint: http://0.0.0.0:8080/v1/query/
history:
enabled: true
filepath: shellai_history.json
filepath: command-line-assistant_history.json
max_size: 100 # max number of queries in history (including responses)
```

### Asking questions through ShellAI
### Asking questions through Command Line Assistant

```sh
shellai --record
shellai "How to uninstall RHEL?"
shellai --history-clear "How to uninstall RHEL?"
shellai --config <custom config path> "How to uninstall RHEL?"
c --record
c "How to uninstall RHEL?"
c --history-clear "How to uninstall RHEL?"
c --config <custom config path> "How to uninstall RHEL?"

# OR with stdin

echo "How to uninstall RHEL?" | shellai
echo "How to uninstall RHEL?" | shellai "Text that will be appended to the stdin"
echo "How to uninstall RHEL?" | c
echo "How to uninstall RHEL?" | c "Text that will be appended to the stdin"

# Usage of caret '^'
# Takes last command output as query context (must be available from output_file value in config)
shellai "How to uninstall RHEL? ^"
c "How to uninstall RHEL? ^"
#
# The query then is in following format:
# 2024-09-11 14:27:01,667 - INFO - Query:
Expand All @@ -118,13 +118,13 @@ Please note that this is up to the user to decide if this is the best way to cap
potential sensitive data.

Install `tmux` and put the following code in your `~/.bashrc`. It will invoke `tmux`, capturing the output of the
previous command and store it in a temporary file for `shellai` to use. (Desclaimer: I didn't test it with other shells
previous command and store it in a temporary file for `Command Line Assistant` to use. (Desclaimer: I didn't test it with other shells
other than `bash`.)

``` bash
# Set the PROMPT_COMMAND to capture the output after each command
SHELL_OUTPUT="$/tmp/shellai_output.tmp"
SHELL_OUTPUT_CLEANED="/tmp/shellai/shellai_output_cleaned.tmp"
SHELL_OUTPUT="$/tmp/command-line-assistant_output.tmp"
SHELL_OUTPUT_CLEANED="/tmp/command-line-assistant/command-line-assistant_output_cleaned.tmp"
# Function to capture the pane's output
function capture_pane_output() {
tmux capture-pane -p > "$SHELL_OUTPUT"
Expand All @@ -143,4 +143,4 @@ pip install 'urllib3<2.0'
```

All temporary files created during the usage (context, code blocks, command call output, captured shell output) are
stored in `/tmp/shellai/*`
stored in `/tmp/command-line-assistant/*`
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ install-tools: ## Install required utilities/tools
@command -v pdm > /dev/null || { echo >&2 "pdm is not installed. Installing..."; pip install pdm; }
pdm --version

install: install-tools ## Sync all required dependencies for shellai to work
install: install-tools ## Sync all required dependencies for Command Line Assistant to work
pdm sync

install-dev: install-tools ## Sync all development dependencies
pdm sync --dev

unit-test: install-dev ## Unit test shellai
unit-test: install-dev ## Unit test Command Line Assistant
@echo "Running tests..."
@coverage run -m pytest tests
@coverage report
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ShellAI
# Command Line Assistant

A simple wrapper to interact with RAG

Expand All @@ -10,5 +10,5 @@ Contributions are welcome. Take a look at [CONTRIBUTING.md](CONTRIBUTING.md) for

For questions, troubleshooting, bug reports and feature requests:

* Create [an issue](https://github.com/rhel-lightspeed/shellai/issues/new) here on GitHub.
* Ask a question through [GitHub Discussions](https://github.com/rhel-lightspeed/shellai/discussions).
* Create [an issue](https://github.com/rhel-lightspeed/command-line-assistant/issues/new) here on GitHub.
* Ask a question through [GitHub Discussions](https://github.com/rhel-lightspeed/command-line-assistant/discussions).
File renamed without changes.
10 changes: 6 additions & 4 deletions shellai/__main__.py → command_line_assistant/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import os
import sys

from shellai.handlers import (
from command_line_assistant.handlers import (
handle_history_write,
handle_query,
handle_script_session,
)
from shellai.utils import read_stdin, read_yaml_config
from command_line_assistant.utils import read_stdin, read_yaml_config

logging.basicConfig(
level=logging.INFO,
Expand All @@ -32,7 +32,7 @@ def get_args():
)
parser.add_argument(
"--config",
default=os.getenv("SHELLAI_CONFIG", "config.yaml"),
default=os.getenv("COMMAND_LINE_ASSISTANT_CONFIG", "config.yaml"),
help="Path to the config file.",
)

Expand Down Expand Up @@ -65,7 +65,9 @@ def main():

output_capture_conf = config.get("output_capture", {})
enforce_script_session = output_capture_conf.get("enforce_script", False)
output_file = output_capture_conf.get("output_file", "/tmp/shellai_output.txt")
output_file = output_capture_conf.get(
"output_file", "/tmp/command-line-assistant_output.txt"
)

if enforce_script_session and (not args.record or not os.path.exists(output_file)):
parser.error(
Expand Down
18 changes: 9 additions & 9 deletions shellai/handlers.py → command_line_assistant/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import requests

from shellai.utils import get_payload
from command_line_assistant.utils import get_payload


def _handle_history_read(config: dict) -> dict:
Expand All @@ -14,7 +14,7 @@ def _handle_history_read(config: dict) -> dict:
if not config.get("enabled", False):
return []

filepath = config.get("filepath", "/tmp/shellai_history.json")
filepath = config.get("filepath", "/tmp/command-line-assistant_history.json")
if not filepath or not os.path.exists(filepath):
logging.warning(f"History file {filepath} does not exist.")
logging.warning("File will be created with first response.")
Expand All @@ -39,7 +39,7 @@ def handle_history_write(config: dict, history: list, response: str) -> None:
"""
if not config.get("enabled", False):
return
filepath = config.get("filepath", "/tmp/shellai_history.json")
filepath = config.get("filepath", "/tmp/command-line-assistant_history.json")
if response:
history.append({"role": "assistant", "content": response})
try:
Expand All @@ -49,20 +49,20 @@ def handle_history_write(config: dict, history: list, response: str) -> None:
logging.error(f"Failed to write history file {filepath}: {e}")


def handle_script_session(shellai_tmp_file) -> None:
def handle_script_session(command_line_assistant_tmp_file) -> None:
"""
Starts a 'script' session and writes the PID to a file, but leaves control of the terminal to the user.
"""
# Prepare the script command
script_command = ["script", "-f", shellai_tmp_file]
script_command = ["script", "-f", command_line_assistant_tmp_file]

# Start the script session and leave control to the terminal
os.system(" ".join(script_command))

# Remove the captured output after the script session ends
if os.path.exists(shellai_tmp_file):
logging.info(f"Removing {shellai_tmp_file}")
os.remove(shellai_tmp_file)
if os.path.exists(command_line_assistant_tmp_file):
logging.info(f"Removing {command_line_assistant_tmp_file}")
os.remove(command_line_assistant_tmp_file)


def _handle_caret(query: str, config: dict) -> str:
Expand All @@ -74,7 +74,7 @@ def _handle_caret(query: str, config: dict) -> str:

output_capture_settings = config.get("output_capture_settings", {})
captured_output_file = output_capture_settings.get(
"captured_output_file", "/tmp/shellai_output.txt"
"captured_output_file", "/tmp/command-line-assistant_output.txt"
)

if not os.path.exists(captured_output_file):
Expand Down
50 changes: 50 additions & 0 deletions command_line_assistant/history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import json
import logging

from command_line_assistant.config import Config


def handle_history_read(config: Config) -> dict:
"""
Reads the history from a file and returns it as a list of dictionaries.
"""
if not config.history.enabled:
return []

filepath = config.history.file
if not filepath or not filepath.exists():
logging.warning(f"History file {filepath} does not exist.")
logging.warning("File will be created with first response.")
return []

max_size = config.history.max_size
history = []
try:
data = filepath.read_text()
history = json.loads(data)
except json.JSONDecodeError as e:
logging.error(f"Failed to read history file {filepath}: {e}")
return []

logging.info(f"Taking maximum of {max_size} entries from history.")
return history[:max_size]


def handle_history_write(config: Config, history: list, response: str) -> None:
"""
Writes the history to a file.
"""
if not config.history.enabled:
return

filepath = config.history.file
filepath.makedirs(mode=0o755)

if response:
history.append({"role": "assistant", "content": response})

try:
data = json.dumps(history)
filepath.write_text(data)
except json.JSONDecodeError as e:
logging.error(f"Failed to write history file {filepath}: {e}")
2 changes: 1 addition & 1 deletion shellai/utils.py → command_line_assistant/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def read_yaml_config(config_file: str) -> dict:
if not os.path.exists(config_file):
print(
f"Config file {config_file} does not exist (use env 'SHELLAI_CONFIG' to change destination).",
f"Config file {config_file} does not exist (use env 'COMMAND_LINE_ASSISTANT_CONFIG' to change destination).",
file=sys.stderr,
)
return {}
Expand Down
4 changes: 2 additions & 2 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
output_capture: # if '^' is used, last command output will be used for query context
enforce_script: false # otherwise recording via script session will be enforced
output_file: /tmp/shellai_output.txt # file with output(s) of regular commands (e.g. ls, echo, etc.)
output_file: /tmp/command-line-assistant_output.txt # file with output(s) of regular commands (e.g. ls, echo, etc.)
prompt_separator: '$' # Keep non-empty if your file contains only output of commands (not prompt itself)
backend_service:
query_endpoint: http://0.0.0.0:8080/v1/query/
history:
enabled: true
filepath: shellai_history.json
filepath: command-line-assistant_history.json
max_size: 100 # max number of queries in history (including responses)
Loading