feat: aggiungi EnhancedCLI con prompt_toolkit
- Nuovo modulo enhanced_cli.py con UI moderna - Colors: user (cyan), agent (green), system (yellow), error (red) - History persistente in .langcode/.cli_history - Autocomplete comandi (/help, /status, /clear, /theme, /exit) - Supporto temi: default, dark, light - Multiline input - Integrato in langcode.py chat mode
This commit is contained in:
1 parent
32ed76e5be
commit
4a0342dcb7
2 files changed
+397
-18
No files matched your search
+16
-18
@@ -30,9 +30,10 @@ VERSION = "1.0.0"
|
||||
|
||||
|
||||
def cmd_chat(args):
|
||||
"""Avvia l'agent in modalità chat interattiva"""
|
||||
"""Avvia l'agent in modalità chat interattiva con EnhancedCLI"""
|
||||
from main import create_langcode_agent, process_command
|
||||
from langchain_core.messages import HumanMessage
|
||||
from enhanced_cli import create_enhanced_cli
|
||||
|
||||
print("🚀 Inizializzo LangCode Agent...")
|
||||
|
||||
@@ -53,34 +54,31 @@ def cmd_chat(args):
|
||||
print(" /exit - Esci dall'agente")
|
||||
print("\n💡 Per chattare, scrivi semplicemente il tuo messaggio.")
|
||||
|
||||
while True:
|
||||
try:
|
||||
user_input = input("\n👤 You: ").strip()
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
print("\n👋 Arrivederci!")
|
||||
break
|
||||
|
||||
if not user_input:
|
||||
continue
|
||||
|
||||
# Callback per processare i messaggi con l'agente
|
||||
def agent_callback(user_input: str) -> str:
|
||||
# Check if it's a command (starts with /)
|
||||
if process_command(user_input):
|
||||
continue
|
||||
|
||||
return "Comando eseguito."
|
||||
|
||||
# Otherwise, treat it as a chat message
|
||||
try:
|
||||
result = agent.invoke({"messages": [HumanMessage(content=user_input)]})
|
||||
|
||||
# Extract response - support both simple agent (messages[-1]) and tool agent (response)
|
||||
if "response" in result:
|
||||
response_text = result["response"]
|
||||
return result["response"]
|
||||
else:
|
||||
ai_message = result["messages"][-1]
|
||||
response_text = ai_message.content if hasattr(ai_message, 'content') else str(ai_message)
|
||||
|
||||
print(f"\n🤖 LangCode: {response_text}")
|
||||
return ai_message.content if hasattr(ai_message, 'content') else str(ai_message)
|
||||
except Exception as e:
|
||||
print(f"\n❌ Errore: {str(e)}")
|
||||
return f"Errore: {str(e)}"
|
||||
|
||||
# Usa EnhancedCLI con history e autocomplete
|
||||
cli = create_enhanced_cli(
|
||||
history_file="./.langcode/.cli_history",
|
||||
theme="default"
|
||||
)
|
||||
cli.run(agent_callback)
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Inizializzazione fallita: {str(e)}")
|
||||
|
||||
Reference in new issue
Block a user