Small changes
This commit is contained in:
13
oai.py
13
oai.py
@@ -70,7 +70,7 @@ except Exception as e:
|
|||||||
models_data = []
|
models_data = []
|
||||||
text_models = []
|
text_models = []
|
||||||
|
|
||||||
# **NEW: Function to clear the screen using ANSI escape sequences (cross-platform)**
|
# Function to clear the screen using ANSI escape sequences (cross-platform)
|
||||||
def clear_screen():
|
def clear_screen():
|
||||||
"""Clear the terminal screen using ANSI escape codes, with fallback to newlines."""
|
"""Clear the terminal screen using ANSI escape codes, with fallback to newlines."""
|
||||||
try:
|
try:
|
||||||
@@ -112,12 +112,11 @@ def chat():
|
|||||||
if not selected_model:
|
if not selected_model:
|
||||||
console.print("[bold yellow]No model selected. Use '/model' to choose one.[/]")
|
console.print("[bold yellow]No model selected. Use '/model' to choose one.[/]")
|
||||||
|
|
||||||
# NEW: Initialize PromptSession for input history and arrow keys
|
# Initialize PromptSession for input history and arrow keys
|
||||||
session = PromptSession(history=None) # 'None' uses InMemoryHistory by default; can be customized later for disk persistence
|
session = PromptSession(history=None) # 'None' uses InMemoryHistory by default; can be customized later for disk persistence
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
# REPLACED: Use session.prompt() instead of typer.prompt() for history/arrow key support
|
|
||||||
user_input = session.prompt("You> ").strip()
|
user_input = session.prompt("You> ").strip()
|
||||||
if user_input.lower() in ["exit", "quit", "bye"]:
|
if user_input.lower() in ["exit", "quit", "bye"]:
|
||||||
console.print("[bold yellow]Goodbye![/]")
|
console.print("[bold yellow]Goodbye![/]")
|
||||||
@@ -195,7 +194,7 @@ def chat():
|
|||||||
table.add_row("Base URL", OPENROUTER_BASE_URL or "[Not set]")
|
table.add_row("Base URL", OPENROUTER_BASE_URL or "[Not set]")
|
||||||
table.add_row("Streaming", "Enabled" if STREAM_ENABLED == "on" else "Disabled")
|
table.add_row("Streaming", "Enabled" if STREAM_ENABLED == "on" else "Disabled")
|
||||||
table.add_row("Database", str(database) or "[Not set]")
|
table.add_row("Database", str(database) or "[Not set]")
|
||||||
table.add_row("Current Model", str(selected_model["name"]) or "[Not set]")
|
table.add_row("Current Model", "[Not set]" if selected_model is None else str(selected_model["name"]))
|
||||||
console.print(Panel(table, title="[bold green]Current Configurations[/]", title_align="left"))
|
console.print(Panel(table, title="[bold green]Current Configurations[/]", title_align="left"))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -233,7 +232,7 @@ def chat():
|
|||||||
"View all current configurations.",
|
"View all current configurations.",
|
||||||
"/config\n(Displays table of API Key, Base URL, etc.)"
|
"/config\n(Displays table of API Key, Base URL, etc.)"
|
||||||
)
|
)
|
||||||
help_table.add_row( # **NEW: Added /clear to help**
|
help_table.add_row(
|
||||||
"/clear",
|
"/clear",
|
||||||
"Clear the terminal screen for a clean interface.",
|
"Clear the terminal screen for a clean interface.",
|
||||||
"/clear\n[bold cyan]Screen cleared. Ready for your next input![/bold cyan]"
|
"/clear\n[bold cyan]Screen cleared. Ready for your next input![/bold cyan]"
|
||||||
@@ -367,11 +366,11 @@ def chat():
|
|||||||
console.print("[bold red]No response received.[/]")
|
console.print("[bold red]No response received.[/]")
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
# NEW: Handle Ctrl+C during prompt input (continue loop instead of crashing)
|
# Handle Ctrl+C during prompt input (continue loop instead of crashing)
|
||||||
console.print("\n[bold yellow]Input interrupted. Continuing...[/]")
|
console.print("\n[bold yellow]Input interrupted. Continuing...[/]")
|
||||||
continue
|
continue
|
||||||
except EOFError:
|
except EOFError:
|
||||||
# NEW: Handle Ctrl+D (exit loop gracefully)
|
# Handle Ctrl+D (exit loop gracefully)
|
||||||
console.print("\n[bold yellow]Goodbye![/]")
|
console.print("\n[bold yellow]Goodbye![/]")
|
||||||
return
|
return
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user