Add back button to model picker
This commit is contained in:
1 parent
918bc45ee0
commit
7c80500280
3 files changed
+23
-2
No files matched your search
@@ -26,7 +26,7 @@ python run_example.py --help
|
||||
|
||||
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:
|
||||
Press **Ctrl+M** to add, edit, delete, and select saved connections. Use **Back** to leave the picker without saving; if you leave it at launch, press **Ctrl+M** to reopen it. Connections are stored in `sloppy.json` in the current working directory:
|
||||
|
||||
```json
|
||||
{
|
||||
|
||||
@@ -240,6 +240,7 @@ class ModelSettings(ModalScreen[tuple[AIConfig, AIConfig] | None]):
|
||||
def compose(self) -> ComposeResult:
|
||||
with VerticalScroll(id="model-settings"):
|
||||
yield Static("[bold]Models and connections[/bold] • saved in sloppy.json")
|
||||
yield Button("Back (Esc)", id="back-models")
|
||||
yield Label("AI 1")
|
||||
yield Select([], id="ai1-select", allow_blank=True)
|
||||
yield Label("AI 2")
|
||||
@@ -290,6 +291,9 @@ class ModelSettings(ModalScreen[tuple[AIConfig, AIConfig] | None]):
|
||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||
from settings import model_from_settings, save_settings, store_model
|
||||
action = event.button.id
|
||||
if action == 'back-models':
|
||||
self.dismiss(None)
|
||||
return
|
||||
identifier = self.query_one('#connection-id', Input).value.strip()
|
||||
try:
|
||||
if action == 'save-model':
|
||||
@@ -493,6 +497,8 @@ class AIChatApp(App):
|
||||
|
||||
def _models_selected(self, models: tuple[AIConfig, AIConfig] | None) -> None:
|
||||
if models is None:
|
||||
if not self.messages:
|
||||
self.update_status("No conversation started. Press Ctrl+M to choose models.")
|
||||
return
|
||||
if self._is_running:
|
||||
self.notify("Saved selection applies to the next conversation")
|
||||
|
||||
+16
-1
@@ -11,10 +11,11 @@ from unittest.mock import patch
|
||||
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
from textual.widgets import Button
|
||||
|
||||
import httpx
|
||||
|
||||
from ai_chat import AIChatApp, AIConfig, MessageBubble, ChatMessage, ControlsHelp, ScreenshotOptions, main
|
||||
from ai_chat import AIChatApp, AIConfig, MessageBubble, ChatMessage, ControlsHelp, ScreenshotOptions, ModelSettings, main
|
||||
from settings import load_settings, save_settings, store_model, model_from_settings
|
||||
|
||||
|
||||
@@ -211,6 +212,20 @@ class ChatTests(unittest.IsolatedAsyncioTestCase):
|
||||
await self.wait_finished(app, pilot)
|
||||
self.assertEqual(app.messages[-1].content, 'working')
|
||||
|
||||
async def test_back_exits_model_picker_without_saving(self):
|
||||
app = await self.make_app(lambda request: httpx.Response(500))
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
path = Path(directory) / 'sloppy.json'
|
||||
app.settings_path = path
|
||||
app.choose_models = True
|
||||
async with app.run_test() as pilot:
|
||||
self.assertIsInstance(app.screen, ModelSettings)
|
||||
app.screen.query_one('#back-models', Button).press()
|
||||
await pilot.pause()
|
||||
self.assertNotIsInstance(app.screen, ModelSettings)
|
||||
self.assertFalse(path.exists())
|
||||
self.assertIn('Ctrl+M', str(app.status_bar.render()))
|
||||
|
||||
async def test_empty_stream_uses_fallback(self):
|
||||
calls = []
|
||||
def handler(request):
|
||||
|
||||
Reference in new issue
Block a user