yaicli 0.0.13__py3-none-any.whl → 0.0.14__py3-none-any.whl
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.
- pyproject.toml +1 -1
- {yaicli-0.0.13.dist-info → yaicli-0.0.14.dist-info}/METADATA +1 -1
- yaicli-0.0.14.dist-info/RECORD +7 -0
- yaicli.py +22 -10
- yaicli-0.0.13.dist-info/RECORD +0 -7
- {yaicli-0.0.13.dist-info → yaicli-0.0.14.dist-info}/WHEEL +0 -0
- {yaicli-0.0.13.dist-info → yaicli-0.0.14.dist-info}/entry_points.txt +0 -0
- {yaicli-0.0.13.dist-info → yaicli-0.0.14.dist-info}/licenses/LICENSE +0 -0
pyproject.toml
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
pyproject.toml,sha256=D0K1CAn3p9Tf-E9VMq82Ml0jX44Eh6gYRzn5qKQD5xs,1452
|
2
|
+
yaicli.py,sha256=5tQBYifI2CFJj_7BpRfRox7yeEYhDu9T9rDkKBppKzE,21392
|
3
|
+
yaicli-0.0.14.dist-info/METADATA,sha256=738uxK3JVEOXwcR3m_KZqni9CRSSnj9RLbEOVIzXgCQ,29445
|
4
|
+
yaicli-0.0.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
+
yaicli-0.0.14.dist-info/entry_points.txt,sha256=gdduQwAuu_LeDqnDU81Fv3NPmD2tRQ1FffvolIP3S1Q,34
|
6
|
+
yaicli-0.0.14.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
7
|
+
yaicli-0.0.14.dist-info/RECORD,,
|
yaicli.py
CHANGED
@@ -2,6 +2,7 @@ import configparser
|
|
2
2
|
import json
|
3
3
|
import platform
|
4
4
|
import subprocess
|
5
|
+
import time
|
5
6
|
from os import getenv
|
6
7
|
from os.path import basename, pathsep
|
7
8
|
from pathlib import Path
|
@@ -11,7 +12,7 @@ import httpx
|
|
11
12
|
import jmespath
|
12
13
|
import typer
|
13
14
|
from distro import name as distro_name
|
14
|
-
from prompt_toolkit import PromptSession
|
15
|
+
from prompt_toolkit import PromptSession, prompt
|
15
16
|
from prompt_toolkit.completion import WordCompleter
|
16
17
|
from prompt_toolkit.history import FileHistory
|
17
18
|
from prompt_toolkit.key_binding import KeyBindings, KeyPressEvent
|
@@ -19,6 +20,7 @@ from prompt_toolkit.keys import Keys
|
|
19
20
|
from rich.console import Console
|
20
21
|
from rich.live import Live
|
21
22
|
from rich.markdown import Markdown
|
23
|
+
from rich.panel import Panel
|
22
24
|
from rich.prompt import Prompt
|
23
25
|
|
24
26
|
SHELL_PROMPT = """Your are a Shell Command Generator.
|
@@ -325,6 +327,8 @@ class CLI:
|
|
325
327
|
self.console.print("Assistant:", style="bold green")
|
326
328
|
full_completion = ""
|
327
329
|
in_reasoning = False
|
330
|
+
cursor_chars = ["_", " "]
|
331
|
+
cursor_index = 0
|
328
332
|
|
329
333
|
with Live() as live:
|
330
334
|
for line in response.iter_lines():
|
@@ -344,15 +348,17 @@ class CLI:
|
|
344
348
|
delta.get("content", "") or "", full_completion, in_reasoning
|
345
349
|
)
|
346
350
|
|
347
|
-
live.update(Markdown(markup=full_completion), refresh=True)
|
348
|
-
|
351
|
+
live.update(Markdown(markup=full_completion + cursor_chars[cursor_index]), refresh=True)
|
352
|
+
cursor_index = (cursor_index + 1) % 2
|
353
|
+
time.sleep(0.005) # Slow down the printing speed, avoiding screen flickering
|
354
|
+
live.update(Markdown(markup=full_completion), refresh=True)
|
349
355
|
return full_completion
|
350
356
|
|
351
357
|
def _print_normal(self, response: httpx.Response) -> str:
|
352
358
|
"""Print response from LLM in non-streaming mode"""
|
353
359
|
self.console.print("Assistant:", style="bold green")
|
354
360
|
full_completion = jmespath.search(self.config.get("ANSWER_PATH", "choices[0].message.content"), response.json())
|
355
|
-
self.console.print(Markdown(full_completion +
|
361
|
+
self.console.print(Markdown(full_completion + "\n"))
|
356
362
|
return full_completion
|
357
363
|
|
358
364
|
def get_prompt_tokens(self) -> list[tuple[str, str]]:
|
@@ -384,13 +390,19 @@ class CLI:
|
|
384
390
|
if not cmd:
|
385
391
|
self.console.print("No command generated", style="bold red")
|
386
392
|
return
|
387
|
-
self.console.print(
|
388
|
-
_input = Prompt.ask(
|
389
|
-
|
393
|
+
self.console.print(Panel(cmd, title="Command", title_align="left", border_style="bold magenta", expand=False))
|
394
|
+
_input = Prompt.ask(
|
395
|
+
r"Execute command? \[e]dit, \[y]es, \[n]o",
|
396
|
+
choices=["y", "n", "e"],
|
397
|
+
default="n",
|
398
|
+
case_sensitive=False,
|
399
|
+
show_choices=False,
|
400
|
+
)
|
401
|
+
if _input == "y": # execute cmd
|
390
402
|
self.console.print("Output:", style="bold green")
|
391
403
|
subprocess.call(cmd, shell=True)
|
392
|
-
elif _input ==
|
393
|
-
cmd =
|
404
|
+
elif _input == "e": # edit cmd
|
405
|
+
cmd = prompt("Edit command, press enter to execute:\n", default=cmd)
|
394
406
|
self.console.print("Output:", style="bold green")
|
395
407
|
subprocess.call(cmd, shell=True)
|
396
408
|
|
@@ -398,7 +410,7 @@ class CLI:
|
|
398
410
|
return [
|
399
411
|
{"role": "system", "content": self.get_system_prompt()},
|
400
412
|
*self.history,
|
401
|
-
{"role": "user", "content": user_input}
|
413
|
+
{"role": "user", "content": user_input},
|
402
414
|
]
|
403
415
|
|
404
416
|
def _handle_llm_response(self, response: httpx.Response, user_input: str) -> str:
|
yaicli-0.0.13.dist-info/RECORD
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
pyproject.toml,sha256=15od1R0Bb-b7YKSSlz1SmzGoaNNbfHgv8y5Zr0gXfBU,1452
|
2
|
-
yaicli.py,sha256=Cby2e0HHoh7sAOIvAxEKoZA0TRS3A3ikkfZ6o3bem0o,20955
|
3
|
-
yaicli-0.0.13.dist-info/METADATA,sha256=5Yc9O8k_N66OpBTqKG9kVGUvXzj2-L3UrXaiZziWfVU,29445
|
4
|
-
yaicli-0.0.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
-
yaicli-0.0.13.dist-info/entry_points.txt,sha256=gdduQwAuu_LeDqnDU81Fv3NPmD2tRQ1FffvolIP3S1Q,34
|
6
|
-
yaicli-0.0.13.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
7
|
-
yaicli-0.0.13.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|