Skip to content

Commit

Permalink
Add installation script and claude command
Browse files Browse the repository at this point in the history
- Add installation script to add environment's bin directory to the PATH
- Update README.md with installation instructions and usage for `claude` command
- Add `claude` command to automatically set relevant environment variables for using the CLI with `claude-3-5-sonnet-latest` model
- Update version to 0.5.3 in `version.py`
- Include `claude` command in `setup.py` entry points
- Update `CHANGELOG.md` with changes for version 0.5.3
  • Loading branch information
nihilok committed Jan 30, 2025
1 parent e476005 commit c8690d3
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 10 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Changelog
---

### 31/01/2025 v0.5.3

- add install command to add environment's bin directory to the PATH
- update README.md

---

### 30/01/2025 v0.5.2

- add `claude` command to automatically set relevant environment variables to use CLI with `claude-3-5-sonnet-latest` model.

---

### 29/01/2025 v0.5.1

- fix typo in setup.py preventing installation
- convert TerminalSelector to use label/value pairs instead of just strings of its values
- alters thread labels when selecting so that the thread id is not shown, just the initial prompt

---

### 12/01/2025 v0.5.0

- add support for image generation via OpenAI API
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,24 @@ $ ai-cli

NOTE: if your virtual environment is not activated, you may need to use /path/to/venv/bin/ai-cli instead of just ai-cli. Consider adding the virtual environment's bin directory to your PATH or otherwise linking the executable to a location in your PATH or creating an alias.

There is an installation script that can be used to add the `ai-cli`, `ai-tg-bot` & `claude` commands to your PATH. You can run this script with the following command:

```bash
$ ai-cli install
```

If you wish to use the Telegram bot interface, you can install the additional dependencies:

```bash
pip install assistants-framework[telegram]
```

To run the telegram bot polling loop, you can just use the following command:

```bash
$ ai-tg-bot
```

## Usage

### Command Line Interface
Expand Down Expand Up @@ -119,18 +131,16 @@ Anything else you type will be sent to the assistant for processing.

Note: prompt (& command) history is saved in `$ASSISTANTS_CONFIG_DIR/history` (default `~/.config/assistants/history`); responses are not saved here, just user input; this history file is used to provide a prompt history which can be accessed via up and down arrows as with your bash prompt. Bear this file in mind when auditing security as you would with shell history.

### Telegram Bot
You can customize the behavior of the assistant by modifying the `ASSISTANT_INSTRUCTIONS` environment variable, which defaults to `"You are a helpful assistant."`

To run the telegram bot polling loop, you can just use the following command:
To use with Claude.ai (Anthropic) models, you can set the `CODE_MODEL` environment variable to `claude-3.5-sonnet-latest` or another model of your choice and run the program with the `-C` option. You must have an API key for Anthropic models set in the `ANTHROPIC_API_KEY` environment variable (or another variable that you have specified; see below).

There is also a `claude` command that can be used to automatically set the relevant environment variables to use the CLI with the `claude-3.5-sonnet-latest` model.

```bash
$ ai-tg-bot
$ claude -e # open the editor to compose a prompt for Claude
```

You can customize the behavior of the assistant by modifying the `ASSISTANT_INSTRUCTIONS` environment variable, which defaults to `"You are a helpful assistant."`

To use with Claude.ai (Anthropic) models, you can set the `CODE_MODEL` environment variable to `claude-3.5-sonnet-latest` or another model of your choice and run the program with the `-C` option. You must have an API key for Anthropic models set in the `ANTHROPIC_API_KEY` environment variable (or another variable that you have specified; see below).

## Environment Variables

In addition to `ASSISTANT_INSTRUCTIONS`, other environment variables that can be configured include:
Expand Down Expand Up @@ -158,9 +168,9 @@ See the dev dependencies in the dev_requirements.txt file for formatting and lin

#### TODOS:

- optional local threads API built on top of langchain
- add postgresql support for data layer
- add support for more models/APIs
- improve local thread/conversation handling to better consider max tokens and truncation of conversation history

## License

Expand Down
23 changes: 23 additions & 0 deletions assistants/claude.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import asyncio
import sys

from assistants.cli import cli
from assistants.config import environment
from assistants.user_data.sqlite_backend import init_db

CLAUDE_MODEL = "claude-3-5-sonnet-latest"


def main():
if not environment.ANTHROPIC_API_KEY:
print("ANTHROPIC_API_KEY not set in environment variables.", file=sys.stderr)
sys.exit(1)
environment.DEFAULT_MODEL = CLAUDE_MODEL
environment.CODE_MODEL = CLAUDE_MODEL
environment.ASSISTANT_INSTRUCTIONS = ""
asyncio.run(init_db())
cli()


if __name__ == "__main__":
main()
34 changes: 34 additions & 0 deletions assistants/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import asyncio
import os
import sys
from pathlib import Path

from assistants.cli import cli
from assistants.user_data.sqlite_backend import init_db


def install():
# Get the path to the current environment's bin directory
bin_dir = Path(sys.prefix) / "bin"
path_update = f"export PATH=$PATH:{bin_dir}\n"

# Check that the bin directory is not in the PATH environment variable already
# and has not already been added to the path by this script
path = os.environ.get("PATH", "")
if str(bin_dir) in path:
print(f"{bin_dir} is already in PATH")
return

with open(Path.home() / ".profile", "r") as f:
if path_update in f.read():
print(f"{bin_dir} is already in PATH")
return

# Add the bin directory to the PATH environment variable in .profile
print(f"Adding {bin_dir} to PATH in .profile")
with open(Path.home() / ".profile", "a") as f:
f.write(f"export PATH=$PATH:{bin_dir}\n")

os.system("source ~/.profile")
print("Done!")


def main():

if len(sys.argv) > 1 and sys.argv[1] == "install":
install()
return

asyncio.run(init_db())
cli()

Expand Down
2 changes: 1 addition & 1 deletion assistants/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__VERSION__ = "0.5.1"
__VERSION__ = "0.5.3"
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
author="Michael Jarvis",
author_email="[email protected]",
description="OpenAI Assistants Wrapper, with CLI and Telegram Bot",
long_description=open("README.md").read(),
long_description=open("README.md").read() + "\n\n" + open("CHANGELOG.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/nihilok/assistants",
packages=find_packages(exclude=["assistants.tests*"]),
Expand Down Expand Up @@ -38,6 +38,7 @@
"console_scripts": [
"ai-cli=assistants.main:main",
"ai-tg-bot=assistants.main_tg:main",
"claude=assistants.claude:main",
],
},
python_requires=">=3.10",
Expand Down

0 comments on commit c8690d3

Please sign in to comment.