yaicli 0.3.0__tar.gz → 0.3.2__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.3.0
3
+ Version: 0.3.2
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
@@ -465,6 +465,9 @@ ai --chat
465
465
  # Generate and execute shell commands
466
466
  ai --shell "Create a backup of my Documents folder"
467
467
 
468
+ # Generate code snippets, default in Python
469
+ ai --code "Write a Python function to sort a list"
470
+
468
471
  # Analyze code from a file
469
472
  cat app.py | ai "Explain what this code does"
470
473
 
@@ -475,17 +478,50 @@ ai --verbose "Explain quantum computing"
475
478
  ### Command Line Reference
476
479
 
477
480
  ```
478
- Usage: ai [OPTIONS] [PROMPT]
481
+ Usage: ai [OPTIONS] [PROMPT]
482
+
483
+ YAICLI: Your AI assistant in the command line.
484
+ Call with a PROMPT to get a direct answer, use --shell to execute as command, or use --chat for an interactive session.
485
+
486
+ ╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
487
+ │ prompt [PROMPT] The prompt to send to the LLM. Reads from stdin if available. [default: None] │
488
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
489
+ ╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
490
+ │ --install-completion Install completion for the current shell. │
491
+ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
492
+ │ --help -h Show this message and exit. │
493
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
494
+ ╭─ LLM Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
495
+ │ --model -M TEXT Specify the model to use. │
496
+ │ --temperature -T FLOAT RANGE [0.0<=x<=2.0] Specify the temperature to use. [default: 0.7] │
497
+ │ --top-p -P FLOAT RANGE [0.0<=x<=1.0] Specify the top-p to use. [default: 1.0] │
498
+ │ --max-tokens -M INTEGER RANGE [x>=1] Specify the max tokens to use. [default: 1024] │
499
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
500
+ ╭─ Role Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
501
+ │ --role -r TEXT Specify the assistant role to use. [default: DEFAULT] │
502
+ │ --create-role TEXT Create a new role with the specified name. │
503
+ │ --delete-role TEXT Delete a role with the specified name. │
504
+ │ --list-roles List all available roles. │
505
+ │ --show-role TEXT Show the role with the specified name. │
506
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
507
+ ╭─ Chat Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
508
+ │ --chat -c Start in interactive chat mode. │
509
+ │ --list-chats List saved chat sessions. │
510
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
511
+ ╭─ Shell Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
512
+ │ --shell -s Generate and optionally execute a shell command (non-interactive). │
513
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
514
+ ╭─ Code Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
515
+ │ --code Generate code in plaintext (non-interactive). │
516
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
517
+ ╭─ Other Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
518
+ │ --verbose -V Show verbose output (e.g., loaded config). │
519
+ │ --template Show the default config file template and exit. │
520
+ │ --show-reasoning --no-show-reasoning Show reasoning content from the LLM. (default: True) │
521
+ │ --justify -j [default|left|center|right|full] Specify the justify to use. [default: default] │
522
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
479
523
  ```
480
524
 
481
- | Option | Short | Description |
482
- |--------------|-------|-------------------------------------|
483
- | `--chat` | `-c` | Start in interactive chat mode |
484
- | `--shell` | `-s` | Generate and execute shell commands |
485
- | `--help` | `-h` | Show help message and exit |
486
- | `--verbose` | `-V` | Show detailed debug information |
487
- | `--template` | | Display the config template |
488
-
489
525
  ### Interactive Mode Features
490
526
 
491
527
  <table>
@@ -640,6 +676,32 @@ cat demo.py | ai "Explain this code"
640
676
  cat error.log | ai "Why am I getting these errors in my Python app?"
641
677
  ```
642
678
 
679
+ ### Role Management
680
+
681
+ ```bash
682
+ # Create a new role, you need to input the role description
683
+ ai --create-role "Philosopher Master"
684
+
685
+ # List all roles
686
+ ai --list-roles
687
+
688
+ # Show a role
689
+ ai --show-role "Philosopher Master"
690
+
691
+ # Delete a role
692
+ ai --delete-role "Philosopher Master"
693
+ ```
694
+
695
+ Once you create a role, you can use it in the `--role` option.
696
+
697
+ ```bash
698
+ # Use a specific role
699
+ ai --role "Philosopher Master" "What is the meaning of life?"
700
+
701
+ # Use a role in chat
702
+ ai --chat --role "Philosopher Master"
703
+ ```
704
+
643
705
  ### History Management
644
706
 
645
707
  YAICLI maintains a history of your interactions (default: 500 entries) stored in `~/.yaicli_history`. You can:
@@ -674,6 +736,23 @@ Output:
674
736
  109M ./
675
737
  ```
676
738
 
739
+ ### Code Generation
740
+
741
+ In code mode, select the language for code generation. If none is specified, Python is the default.
742
+
743
+ The `--code` mode outputs plain text, making it easy to copy, paste, or redirect to a file, especially when using the standard model.
744
+
745
+ When using a deep reasoning model, the thinking content is displayed with syntax highlighting. To disable this, use the `--no-show-reasoning` option or set `SHOW_REASONING` to `false` in the configuration.
746
+
747
+ ```bash
748
+ $ ai --code 'Write a fib generator'
749
+ def fib_generator():
750
+ a, b = 0, 1
751
+ while True:
752
+ yield a
753
+ a, b = b, a + b
754
+ ```
755
+
677
756
  ### Chat Mode Example
678
757
 
679
758
  ```bash
@@ -747,6 +826,14 @@ Output:
747
826
  ...
748
827
  ```
749
828
 
829
+ ### Code Mode Example
830
+
831
+ ```bash
832
+ $ ai --code "write a fib generator" --model deepseek-r1
833
+ ```
834
+
835
+ ![fib code example](artwork/reasoning_code_example.png)
836
+
750
837
  ## 💻 Technical Details
751
838
 
752
839
  ### Architecture
@@ -241,6 +241,9 @@ ai --chat
241
241
  # Generate and execute shell commands
242
242
  ai --shell "Create a backup of my Documents folder"
243
243
 
244
+ # Generate code snippets, default in Python
245
+ ai --code "Write a Python function to sort a list"
246
+
244
247
  # Analyze code from a file
245
248
  cat app.py | ai "Explain what this code does"
246
249
 
@@ -251,17 +254,50 @@ ai --verbose "Explain quantum computing"
251
254
  ### Command Line Reference
252
255
 
253
256
  ```
254
- Usage: ai [OPTIONS] [PROMPT]
257
+ Usage: ai [OPTIONS] [PROMPT]
258
+
259
+ YAICLI: Your AI assistant in the command line.
260
+ Call with a PROMPT to get a direct answer, use --shell to execute as command, or use --chat for an interactive session.
261
+
262
+ ╭─ Arguments ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
263
+ │ prompt [PROMPT] The prompt to send to the LLM. Reads from stdin if available. [default: None] │
264
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
265
+ ╭─ Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
266
+ │ --install-completion Install completion for the current shell. │
267
+ │ --show-completion Show completion for the current shell, to copy it or customize the installation. │
268
+ │ --help -h Show this message and exit. │
269
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
270
+ ╭─ LLM Options ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
271
+ │ --model -M TEXT Specify the model to use. │
272
+ │ --temperature -T FLOAT RANGE [0.0<=x<=2.0] Specify the temperature to use. [default: 0.7] │
273
+ │ --top-p -P FLOAT RANGE [0.0<=x<=1.0] Specify the top-p to use. [default: 1.0] │
274
+ │ --max-tokens -M INTEGER RANGE [x>=1] Specify the max tokens to use. [default: 1024] │
275
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
276
+ ╭─ Role Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
277
+ │ --role -r TEXT Specify the assistant role to use. [default: DEFAULT] │
278
+ │ --create-role TEXT Create a new role with the specified name. │
279
+ │ --delete-role TEXT Delete a role with the specified name. │
280
+ │ --list-roles List all available roles. │
281
+ │ --show-role TEXT Show the role with the specified name. │
282
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
283
+ ╭─ Chat Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
284
+ │ --chat -c Start in interactive chat mode. │
285
+ │ --list-chats List saved chat sessions. │
286
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
287
+ ╭─ Shell Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
288
+ │ --shell -s Generate and optionally execute a shell command (non-interactive). │
289
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
290
+ ╭─ Code Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
291
+ │ --code Generate code in plaintext (non-interactive). │
292
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
293
+ ╭─ Other Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
294
+ │ --verbose -V Show verbose output (e.g., loaded config). │
295
+ │ --template Show the default config file template and exit. │
296
+ │ --show-reasoning --no-show-reasoning Show reasoning content from the LLM. (default: True) │
297
+ │ --justify -j [default|left|center|right|full] Specify the justify to use. [default: default] │
298
+ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
255
299
  ```
256
300
 
257
- | Option | Short | Description |
258
- |--------------|-------|-------------------------------------|
259
- | `--chat` | `-c` | Start in interactive chat mode |
260
- | `--shell` | `-s` | Generate and execute shell commands |
261
- | `--help` | `-h` | Show help message and exit |
262
- | `--verbose` | `-V` | Show detailed debug information |
263
- | `--template` | | Display the config template |
264
-
265
301
  ### Interactive Mode Features
266
302
 
267
303
  <table>
@@ -416,6 +452,32 @@ cat demo.py | ai "Explain this code"
416
452
  cat error.log | ai "Why am I getting these errors in my Python app?"
417
453
  ```
418
454
 
455
+ ### Role Management
456
+
457
+ ```bash
458
+ # Create a new role, you need to input the role description
459
+ ai --create-role "Philosopher Master"
460
+
461
+ # List all roles
462
+ ai --list-roles
463
+
464
+ # Show a role
465
+ ai --show-role "Philosopher Master"
466
+
467
+ # Delete a role
468
+ ai --delete-role "Philosopher Master"
469
+ ```
470
+
471
+ Once you create a role, you can use it in the `--role` option.
472
+
473
+ ```bash
474
+ # Use a specific role
475
+ ai --role "Philosopher Master" "What is the meaning of life?"
476
+
477
+ # Use a role in chat
478
+ ai --chat --role "Philosopher Master"
479
+ ```
480
+
419
481
  ### History Management
420
482
 
421
483
  YAICLI maintains a history of your interactions (default: 500 entries) stored in `~/.yaicli_history`. You can:
@@ -450,6 +512,23 @@ Output:
450
512
  109M ./
451
513
  ```
452
514
 
515
+ ### Code Generation
516
+
517
+ In code mode, select the language for code generation. If none is specified, Python is the default.
518
+
519
+ The `--code` mode outputs plain text, making it easy to copy, paste, or redirect to a file, especially when using the standard model.
520
+
521
+ When using a deep reasoning model, the thinking content is displayed with syntax highlighting. To disable this, use the `--no-show-reasoning` option or set `SHOW_REASONING` to `false` in the configuration.
522
+
523
+ ```bash
524
+ $ ai --code 'Write a fib generator'
525
+ def fib_generator():
526
+ a, b = 0, 1
527
+ while True:
528
+ yield a
529
+ a, b = b, a + b
530
+ ```
531
+
453
532
  ### Chat Mode Example
454
533
 
455
534
  ```bash
@@ -523,6 +602,14 @@ Output:
523
602
  ...
524
603
  ```
525
604
 
605
+ ### Code Mode Example
606
+
607
+ ```bash
608
+ $ ai --code "write a fib generator" --model deepseek-r1
609
+ ```
610
+
611
+ ![fib code example](artwork/reasoning_code_example.png)
612
+
526
613
  ## 💻 Technical Details
527
614
 
528
615
  ### Architecture
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "yaicli"
3
- version = "0.3.0"
3
+ version = "0.3.2"
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"
@@ -93,7 +93,11 @@ class ApiClient:
93
93
 
94
94
  def get_headers(self) -> Dict[str, str]:
95
95
  """Get the request headers."""
96
- return {"Authorization": f"Bearer {self.api_key}", "Content-Type": "application/json"}
96
+ return {
97
+ "Authorization": f"Bearer {self.api_key}",
98
+ "Content-Type": "application/json",
99
+ "X-Title": "Yaicli",
100
+ }
97
101
 
98
102
  def _process_completion_response(self, response_json: Dict[str, Any]) -> Tuple[Optional[str], Optional[str]]:
99
103
  """Process the JSON response from a non-streamed completion request."""
@@ -344,6 +344,7 @@ class CLI:
344
344
  def get_system_prompt(self) -> str:
345
345
  """Get the system prompt based on current role and mode"""
346
346
  # Use the role manager to get the system prompt
347
+ self.console.print(f"Using role: {self.role}")
347
348
  return self.role_manager.get_system_prompt(self.role)
348
349
 
349
350
  def _build_messages(self, user_input: str) -> List[dict]:
@@ -499,6 +500,7 @@ class CLI:
499
500
  @self.bindings.add(Keys.ControlI) # TAB
500
501
  def _(event: KeyPressEvent) -> None:
501
502
  self.current_mode = EXEC_MODE if self.current_mode == CHAT_MODE else CHAT_MODE
503
+ self.role = DefaultRoleNames.SHELL if self.current_mode == EXEC_MODE else DefaultRoleNames.DEFAULT
502
504
 
503
505
  def _run_once(self, input: str, shell: bool) -> None:
504
506
  """Run a single command (non-interactive)."""
@@ -130,7 +130,7 @@ def main(
130
130
  code: bool = typer.Option(
131
131
  False,
132
132
  "--code",
133
- help="Generate and optionally execute a code block (non-interactive).",
133
+ help="Generate code in plaintext (non-interactive).",
134
134
  rich_help_panel="Code Options",
135
135
  ),
136
136
  # ------------------- Chat Options -------------------
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes