This commit is contained in:
Alvin-Zilverstand committed 2026-11-13 10:02:13 +01:00
1 parent e6db824792
commit ed76261303
5 files changed
+170 -9

No files matched your search

+52 -5
View File
@@ -1,8 +1,32 @@
# Sloppy
Run `python run_example.py --prompt "Your topic"`. With the original `.env` configuration and no `sloppy.json`, the conversation starts directly as before. Use **Ctrl+M** to add, edit, or delete connections. Once `sloppy.json` exists, the launch picker lets you choose saved models or the current `.env` connections for AI 1 and AI 2. **Ctrl+P** opens the command palette. A selection made during a conversation applies to the next run.
Sloppy is a terminal app where two AI models discuss an initial prompt. AI 1 replies first, then AI 2, alternating for a chosen number of replies. It supports OpenAI-compatible chat-completions APIs, including local servers.
Settings are saved in `sloppy.json` in the current working directory. Example:
## Setup
Use Python 3.10 or newer and configure two reachable models. The same endpoint can serve both.
```powershell
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install -r requirements.txt
Copy-Item .env.example .env
```
Edit `.env` for your endpoints, keys, model IDs, and topic, then run `python run_example.py`. On macOS or Linux, activate with `source .venv/bin/activate` and copy the example with `cp .env.example .env`. `python ai_chat.py` is an equivalent entry point.
```powershell
python run_example.py --prompt "Can AI be creative?" --turns 6
python run_example.py --help
```
## Configuration
`.env` accepts `AI1_NAME`, `AI1_BASE_URL`, `AI1_API_KEY`, `AI1_MODEL`, and `AI1_SYSTEM_PROMPT`, plus matching `AI2_*` variables. `INITIAL_PROMPT` is required. `MAX_TURNS` defaults to 20 and must be positive. Set each base URL to an API root such as `http://localhost:11434/v1`; Sloppy appends `/chat/completions`.
Command-line options `--ai1-name`, `--ai1-url`, `--ai1-key`, `--ai1-model`, `--ai1-prompt` and matching `--ai2-*` options override `.env` values for a run. When any connection option is supplied, both connections need a base URL and API key after applying defaults. Prefer environment variables over command-line arguments for hosted-provider secrets, since command-line values can enter shell history.
Press **Ctrl+M** to add, edit, delete, and select saved connections. They are stored in `sloppy.json` in the current working directory:
```json
{
@@ -10,7 +34,7 @@ Settings are saved in `sloppy.json` in the current working directory. Example:
"local": {
"name": "Local Llama",
"base_url": "http://localhost:11434/v1",
"api_key": "ollama",
"api_key": "env:LOCAL_API_KEY",
"model": "llama3",
"system_prompt": "You are a helpful assistant."
}
@@ -19,6 +43,29 @@ Settings are saved in `sloppy.json` in the current working directory. Example:
}
```
For a hosted provider, set `api_key` to `env:YOUR_API_KEY_VARIABLE` to keep the secret out of JSON. `.env` values are read fresh on every launch; they are never copied into `sloppy.json`. Existing `--ai1-*` and `--ai2-*` arguments still start directly with the supplied connections.
Set `LOCAL_API_KEY` in the process environment when using `env:LOCAL_API_KEY`. The app resolves it when selecting the connection. You can select the current `.env` connection for either speaker. `.env` values are reread on launch and are never copied into `sloppy.json`. With complete `.env` connections and no `sloppy.json`, the conversation starts directly; otherwise a picker opens. Changes to speaker selection during a conversation apply on the next run.
Press **S** or **F2** during a chat to open the sharing menu. Choose **T** to save a text-only Markdown transcript in `transcripts/`, with the initial prompt and each speaker's replies in order. The SVG screenshot options remain available.
## Controls and exports
| Key | Action |
| --- | --- |
| Ctrl+M | Connections and speaker selection |
| Ctrl+P | Command palette |
| F1 | Reading controls |
| S or F2 | Sharing menu |
| Mouse wheel, Up / Down, Page Up / Page Down | Scroll |
| Home / End | Oldest / latest message |
| Ctrl+C | Quit |
Scrolling up pauses automatic following; **End** resumes it. The UI shows elapsed time, reply count, word counts, and token usage when the provider reports it. Token and speed figures may be estimates when usage is unavailable.
The sharing menu saves the full conversation or visible screen as SVG in `screenshots/`, or a Markdown transcript in `transcripts/`. The transcript includes the initial prompt and replies in order. Both directories are created in the current working directory and ignored by Git.
## Troubleshooting
- **No connection in the picker:** Complete the base URL and key in `.env`, or add a saved connection with **Ctrl+M**.
- **Missing API key:** Set the environment variable named by a saved `env:NAME` reference before launch.
- **API error:** Check the API root, model ID, server availability, and credentials. A failed stream falls back to a non-streaming request; transport and empty-response failures receive up to two retries.
- **Invalid settings:** Fix malformed `sloppy.json` in the current working directory. Its top-level `models` value must be an object.
See [CONTRIBUTING.md](CONTRIBUTING.md) for code structure and tests.