File size: 2,029 Bytes
d317445 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #!/usr/bin/env python3
"""
Local runner for Memory-Enabled LangChain Agent
"""
from langchain_memory_tools import create_memory_enabled_agent
def main():
print("🧠 Starting Memory-Enabled Chat with Ollama...")
# Убедитесь, что Ollama запущен и модель доступна
model_name = "llama3.2:3b" # или другая модель в вашем Ollama
try:
agent = create_memory_enabled_agent(model_name)
print(f"✅ Agent with model '{model_name}' ready!")
print("💡 Example commands:")
print(
" - Save this insight: 'Quantum computers use qubits' with title 'Quantum Computing Basics' and tags 'quantum,computing,physics'")
print(" - Search my memories for quantum")
print(" - List all my memories")
print(" - Show memory statistics")
print(" - Type 'quit' to exit")
print()
while True:
try:
user_input = input("You: ").strip()
if user_input.lower() in ['quit', 'exit', 'bye']:
print("👋 Goodbye!")
break
if not user_input:
continue
print("🤔 Thinking...")
response = agent.invoke({"input": user_input})
print(f"🤖 Agent: {response['output']}")
print("-" * 50)
except KeyboardInterrupt:
print("\n👋 Goodbye!")
break
except Exception as e:
print(f"❌ Error: {e}")
print("Continuing...")
continue
except Exception as e:
print(f"❌ Failed to initialize agent: {e}")
print("\n🔧 Troubleshooting:")
print("1. Make sure Ollama is running: ollama serve")
print(f"2. Make sure model is available: ollama pull {model_name}")
print("3. Check if Ollama is accessible at http://localhost:11434")
if __name__ == "__main__":
main() |