Restore env and CLI model configuration

This commit is contained in:
Alvin-Zilverstand committed 2026-11-13 10:25:43 +01:00
1 parent 7c80500280
commit fd8e0ddea5
5 files changed
+77 -384

No files matched your search

+3 -4
View File
@@ -6,19 +6,18 @@
| --- | --- |
| `run_example.py` | Entry point that calls `ai_chat.main()` |
| `ai_chat.py` | CLI, Textual UI, conversation loop, API requests, exports, and statistics |
| `settings.py` | Load and save `sloppy.json` connections and selections |
| `test_ai_chat.py` | Unit and Textual integration tests with mock HTTP responses |
| `.env.example` | Example runtime configuration |
## Conversation and request flow
`main()` loads `.env`, parses CLI overrides, validates the prompt and turn count, and creates `AIChatApp`. The app optionally opens the connection picker, then starts the conversation. AI 1 and AI 2 alternate for at most `max_turns` replies.
`main()` loads `.env`, parses CLI overrides, validates the connections, prompt, and turn count, and creates `AIChatApp`. AI 1 and AI 2 alternate for at most `max_turns` replies.
For each reply, `history_for()` presents the current speaker's earlier replies as `assistant` messages and the other speaker's replies as `user` messages. It keeps the original topic and recent messages within a 12,000-character request-history budget. The full conversation remains in the UI and exports.
Requests go to `{base_url}/chat/completions` with the speaker's system prompt, model ID, temperature `0.7`, and `max_tokens` of `2000`. Streaming reads server-sent `data:` events, requests usage reporting, and requires a final `[DONE]` event. If a stream fails, is incomplete, or is empty, the app attempts a regular JSON completion. Transport and empty-response failures receive up to two retries. The same message bubble is reused during fallback; partial stream content is cleared before the fallback request and cannot enter later conversation history.
`settings.py` validates the shape and field types of loaded settings. It writes JSON through an exclusively created temporary file and atomic replace, and removes its own temporary file if the write fails. On Unix, newly written settings are private to the current user (`0600`). Use an `env:VARIABLE` API-key reference for hosted-provider secrets. `.env`, `sloppy.json`, screenshots, and transcripts are ignored by Git.
`.env`, screenshots, and transcripts are ignored by Git.
## Tests
@@ -28,4 +27,4 @@ After installing `requirements.txt`, run:
python -m unittest discover -v
```
The suite covers CLI and settings behavior, streaming and fallback, speaker roles and bounded history, UI controls, statistics, and transcript export. It uses `httpx.MockTransport` and Textual's test pilot, so no live model server is needed.
The suite covers CLI behavior, streaming and fallback, speaker roles and bounded history, UI controls, statistics, and transcript export. It uses `httpx.MockTransport` and Textual's test pilot, so no live model server is needed.