yaicli 0.0.11__tar.gz → 0.0.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: yaicli
3
- Version: 0.0.11
3
+ Version: 0.0.12
4
4
  Summary: A simple CLI tool to interact with LLM
5
5
  Project-URL: Homepage, https://github.com/belingud/yaicli
6
6
  Project-URL: Repository, https://github.com/belingud/yaicli
@@ -410,33 +410,41 @@ ai --verbose "Explain quantum computing"
410
410
 
411
411
  ### Command Line Options
412
412
 
413
+ Arguments:
413
414
  - `<PROMPT>`: Argument
414
- - `--verbose` or `-V`: Show verbose information
415
- - `--chat` or `-c`: Start in chat mode
416
- - `--shell` or `-s`: Generate and execute shell command
415
+
416
+ Options:
417
417
  - `--install-completion`: Install completion for the current shell
418
418
  - `--show-completion`: Show completion for the current shell, to copy it or customize the installation
419
419
  - `--help` or `-h`: Show this message and exit
420
+ - `--template`: Show the config template.
421
+
422
+ Run Options:
423
+ - `--verbose` or `-V`: Show verbose information
424
+ - `--chat` or `-c`: Start in chat mode
425
+ - `--shell` or `-s`: Generate and execute shell command
420
426
 
421
427
  ```bash
422
428
  ai -h
423
429
 
424
- Usage: ai [OPTIONS] [PROMPT]
425
-
426
- yaicli. Your AI interface in cli.
427
-
428
- ╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
429
- │ prompt [PROMPT] The prompt send to the LLM
430
- ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
431
- ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
432
- │ --verbose -V Show verbose information
433
- │ --chat -c Start in chat mode
434
- │ --shell -s Generate and execute shell command
435
- │ --install-completion Install completion for the current shell.
436
- │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
437
- --help -h Show this message and exit. │
438
- ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
439
-
430
+ Usage: ai [OPTIONS] [PROMPT]
431
+
432
+ yaicli - Your AI interface in cli.
433
+
434
+ ╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
435
+ │ prompt [PROMPT] The prompt send to the LLM
436
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
437
+ ╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
438
+ │ --template Show the config template.
439
+ │ --install-completion Install completion for the current shell.
440
+ │ --show-completion Show completion for the current shell, to copy it or customize the installation.
441
+ │ --help -h Show this message and exit.
442
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
443
+ ╭─ Run Option ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
444
+ │ --chat -c Start in chat mode │
445
+ │ --shell -s Generate and execute shell command │
446
+ │ --verbose -V Show verbose information │
447
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
440
448
 
441
449
  ```
442
450
 
@@ -186,33 +186,41 @@ ai --verbose "Explain quantum computing"
186
186
 
187
187
  ### Command Line Options
188
188
 
189
+ Arguments:
189
190
  - `<PROMPT>`: Argument
190
- - `--verbose` or `-V`: Show verbose information
191
- - `--chat` or `-c`: Start in chat mode
192
- - `--shell` or `-s`: Generate and execute shell command
191
+
192
+ Options:
193
193
  - `--install-completion`: Install completion for the current shell
194
194
  - `--show-completion`: Show completion for the current shell, to copy it or customize the installation
195
195
  - `--help` or `-h`: Show this message and exit
196
+ - `--template`: Show the config template.
197
+
198
+ Run Options:
199
+ - `--verbose` or `-V`: Show verbose information
200
+ - `--chat` or `-c`: Start in chat mode
201
+ - `--shell` or `-s`: Generate and execute shell command
196
202
 
197
203
  ```bash
198
204
  ai -h
199
205
 
200
- Usage: ai [OPTIONS] [PROMPT]
201
-
202
- yaicli. Your AI interface in cli.
203
-
204
- ╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
205
- │ prompt [PROMPT] The prompt send to the LLM
206
- ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
207
- ╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
208
- │ --verbose -V Show verbose information
209
- │ --chat -c Start in chat mode
210
- │ --shell -s Generate and execute shell command
211
- │ --install-completion Install completion for the current shell.
212
- │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
213
- --help -h Show this message and exit. │
214
- ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
215
-
206
+ Usage: ai [OPTIONS] [PROMPT]
207
+
208
+ yaicli - Your AI interface in cli.
209
+
210
+ ╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
211
+ │ prompt [PROMPT] The prompt send to the LLM
212
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
213
+ ╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
214
+ │ --template Show the config template.
215
+ │ --install-completion Install completion for the current shell.
216
+ │ --show-completion Show completion for the current shell, to copy it or customize the installation.
217
+ │ --help -h Show this message and exit.
218
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
219
+ ╭─ Run Option ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
220
+ │ --chat -c Start in chat mode │
221
+ │ --shell -s Generate and execute shell command │
222
+ │ --verbose -V Show verbose information │
223
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
216
224
 
217
225
  ```
218
226
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "yaicli"
3
- version = "0.0.11"
3
+ version = "0.0.12"
4
4
  description = "A simple CLI tool to interact with LLM"
5
5
  authors = [{ name = "belingud", email = "im.victor@qq.com" }]
6
6
  readme = "README.md"
@@ -46,6 +46,10 @@ Documentation = "https://github.com/belingud/yaicli"
46
46
  [project.scripts]
47
47
  ai = "yaicli:app"
48
48
 
49
+ [tool.pdm.scripts]
50
+ bump = "bump2version {args}"
51
+ changelog = "just changelog"
52
+
49
53
  [tool.uv]
50
54
  resolution = "highest"
51
55
 
@@ -12,6 +12,8 @@ import jmespath
12
12
  import typer
13
13
  from distro import name as distro_name
14
14
  from prompt_toolkit import PromptSession
15
+ from prompt_toolkit.completion import WordCompleter
16
+ from prompt_toolkit.history import FileHistory
15
17
  from prompt_toolkit.key_binding import KeyBindings, KeyPressEvent
16
18
  from prompt_toolkit.keys import Keys
17
19
  from rich.console import Console
@@ -37,6 +39,7 @@ DEFAULT_PROMPT = (
37
39
 
38
40
  CMD_CLEAR = "/clear"
39
41
  CMD_EXIT = "/exit"
42
+ CMD_HISTORY = "/his"
40
43
 
41
44
  EXEC_MODE = "exec"
42
45
  CHAT_MODE = "chat"
@@ -103,6 +106,19 @@ class CLI:
103
106
  self.max_history_length = 25
104
107
  self.current_mode = TEMP_MODE
105
108
 
109
+ def prepare_chat_loop(self) -> None:
110
+ """Setup key bindings and history for chat mode"""
111
+ self._setup_key_bindings()
112
+ # Initialize history
113
+ Path("~/.yaicli_history").expanduser().touch(exist_ok=True)
114
+ self.session = PromptSession(
115
+ key_bindings=self.bindings,
116
+ completer=WordCompleter(["/clear", "/exit", "/his"]),
117
+ complete_while_typing=True,
118
+ history=FileHistory(Path("~/.yaicli_history").expanduser()),
119
+ enable_history_search=True,
120
+ )
121
+
106
122
  def _setup_key_bindings(self) -> None:
107
123
  """Setup keyboard shortcuts"""
108
124
 
@@ -243,8 +259,7 @@ class CLI:
243
259
  except httpx.HTTPStatusError as e:
244
260
  self.console.print(f"[red]Error calling API: {e}[/red]")
245
261
  if self.verbose:
246
- self.console.print(f"Reason: {e}")
247
- self.console.print(f"Response: {response.text}")
262
+ self.console.print(f"Reason: {e}\nResponse: {response.text}")
248
263
  raise e
249
264
  return response
250
265
 
@@ -345,12 +360,7 @@ class CLI:
345
360
 
346
361
  def get_prompt_tokens(self) -> list[tuple[str, str]]:
347
362
  """Return prompt tokens for current mode"""
348
- if self.current_mode == CHAT_MODE:
349
- qmark = "💬"
350
- elif self.current_mode == EXEC_MODE:
351
- qmark = "🚀"
352
- else:
353
- qmark = ""
363
+ qmark = "💬" if self.current_mode == CHAT_MODE else "🚀" if self.current_mode == EXEC_MODE else ""
354
364
  return [("class:qmark", qmark), ("class:question", " {} ".format(">"))]
355
365
 
356
366
  def _check_history_len(self) -> None:
@@ -361,7 +371,7 @@ class CLI:
361
371
  def _run_repl(self) -> None:
362
372
  """Run REPL loop, handling user input and generating responses, saving history, and executing commands"""
363
373
  # Show REPL instructions
364
- self._setup_key_bindings()
374
+ self.prepare_chat_loop()
365
375
  self.console.print("""
366
376
  ██ ██ █████ ██ ██████ ██ ██
367
377
  ██ ██ ██ ██ ██ ██ ██ ██
@@ -389,7 +399,7 @@ class CLI:
389
399
  self.history = []
390
400
  self.console.print("[bold yellow]Chat history cleared[/bold yellow]\n")
391
401
  continue
392
- elif user_input.lower() == "/his":
402
+ elif user_input.lower() == CMD_HISTORY:
393
403
  self.console.print(self.history)
394
404
  continue
395
405
  # Create appropriate system prompt based on mode
@@ -409,11 +419,9 @@ class CLI:
409
419
  except ValueError as e:
410
420
  self.console.print(f"[red]Error: {e}[/red]")
411
421
  return
412
- except httpx.ConnectError as e:
422
+ except (httpx.ConnectError, httpx.HTTPStatusError) as e:
413
423
  self.console.print(f"[red]Error: {e}[/red]")
414
424
  continue
415
- except httpx.HTTPStatusError:
416
- continue
417
425
  self.console.print("\n[bold green]Assistant:[/bold green]")
418
426
  try:
419
427
  content = self._print(response, stream=self.config["STREAM"] == "true")
@@ -425,7 +433,6 @@ class CLI:
425
433
  self.history.append({"role": "user", "content": user_input})
426
434
  self.history.append({"role": "assistant", "content": content})
427
435
 
428
- # Trim history if needed
429
436
  self._check_history_len()
430
437
 
431
438
  # Handle command execution in exec mode
@@ -482,9 +489,8 @@ class CLI:
482
489
  """Run the CLI"""
483
490
  self.load_config()
484
491
  if not self.config.get("API_KEY"):
485
- self.console.print("[bold red]API key not set[/bold red]")
486
492
  self.console.print(
487
- "[bold red]Please set API key in ~/.config/yaicli/config.ini or environment variable[/bold red]"
493
+ "[yellow]API key not set. Please set in ~/.config/yaicli/config.ini or AI_API_KEY env[/]"
488
494
  )
489
495
  raise typer.Exit(code=1)
490
496
 
@@ -500,14 +506,24 @@ class CLI:
500
506
  def main(
501
507
  ctx: typer.Context,
502
508
  prompt: Annotated[Optional[str], typer.Argument(show_default=False, help="The prompt send to the LLM")] = None,
503
- verbose: Annotated[bool, typer.Option("--verbose", "-V", help="Show verbose information")] = False,
504
- chat: Annotated[bool, typer.Option("--chat", "-c", help="Start in chat mode")] = False,
505
- shell: Annotated[bool, typer.Option("--shell", "-s", help="Generate and execute shell command")] = False,
509
+ chat: Annotated[
510
+ bool, typer.Option("--chat", "-c", help="Start in chat mode", rich_help_panel="Run Option")
511
+ ] = False,
512
+ shell: Annotated[
513
+ bool, typer.Option("--shell", "-s", help="Generate and execute shell command", rich_help_panel="Run Option")
514
+ ] = False,
515
+ verbose: Annotated[
516
+ bool, typer.Option("--verbose", "-V", help="Show verbose information", rich_help_panel="Run Option")
517
+ ] = False,
518
+ template: Annotated[bool, typer.Option("--template", help="Show the config template.")] = False,
506
519
  ):
507
520
  """yaicli - Your AI interface in cli."""
508
521
  if prompt == "":
509
522
  typer.echo("Empty prompt, ignored")
510
523
  return
524
+ if template:
525
+ typer.echo(DEFAULT_CONFIG_INI)
526
+ return
511
527
  if not prompt and not chat:
512
528
  typer.echo(ctx.get_help())
513
529
  return
File without changes
File without changes