Enhancement Suite: Anti-loop protection, Kokoro TTS integration, ComfyUI status monitoring, and auto-open image functionality
This commit is contained in:
0
build/lib/ollama_cli/ui/__init__.py
Normal file
0
build/lib/ollama_cli/ui/__init__.py
Normal file
40
build/lib/ollama_cli/ui/formatter.py
Normal file
40
build/lib/ollama_cli/ui/formatter.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from rich.console import Console
|
||||
from rich.markdown import Markdown
|
||||
from rich.panel import Panel
|
||||
from rich.live import Live
|
||||
from rich.text import Text
|
||||
from rich.syntax import Syntax
|
||||
from typing import Optional
|
||||
|
||||
console = Console()
|
||||
|
||||
def print_markdown(text: str):
|
||||
console.print(Markdown(text))
|
||||
|
||||
def print_panel(text: str, title: Optional[str] = None, style: str = "blue"):
|
||||
console.print(Panel(text, title=title, border_style=style))
|
||||
|
||||
def print_error(text: str):
|
||||
console.print(f"[bold red]Error:[/bold red] {text}")
|
||||
|
||||
def print_status(text: str):
|
||||
console.print(f"[bold blue]>>>[/bold blue] {text}")
|
||||
|
||||
class StreamingDisplay:
|
||||
def __init__(self, title: Optional[str] = None):
|
||||
self.text = ""
|
||||
self.live = Live(Text(self.text), refresh_per_second=10)
|
||||
self.title = title
|
||||
|
||||
def __enter__(self):
|
||||
self.live.start()
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self.live.stop()
|
||||
|
||||
def update(self, chunk: str):
|
||||
self.text += chunk
|
||||
# Try to parse markdown if it looks complete-ish, otherwise just show text
|
||||
# For performance, we might just show raw text during streaming
|
||||
self.live.update(Markdown(self.text) if "```" in self.text else Text(self.text))
|
||||
25
build/lib/ollama_cli/ui/repl.py
Normal file
25
build/lib/ollama_cli/ui/repl.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from prompt_toolkit import PromptSession
|
||||
from prompt_toolkit.history import FileHistory
|
||||
from prompt_toolkit.styles import Style
|
||||
from prompt_toolkit.formatted_text import HTML
|
||||
import os
|
||||
|
||||
class REPL:
|
||||
def __init__(self):
|
||||
history_file = os.path.expanduser("~/.ollama-cli-history")
|
||||
self.session = PromptSession(history=FileHistory(history_file))
|
||||
self.style = Style.from_dict({
|
||||
'prompt': 'ansicyan bold',
|
||||
'command': 'ansigreen',
|
||||
})
|
||||
|
||||
def get_input(self) -> str:
|
||||
try:
|
||||
return self.session.prompt(
|
||||
HTML('<prompt><b>> </b></prompt>'),
|
||||
style=self.style
|
||||
).strip()
|
||||
except KeyboardInterrupt:
|
||||
return ""
|
||||
except EOFError:
|
||||
return "/quit"
|
||||
Reference in New Issue
Block a user