95 lines
3.0 KiB
Python
95 lines
3.0 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
Main entry point for the LangChain + LangGraph scaffolding project
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
from workflows.workflow_manager import WorkflowManager, WorkflowType
|
||
|
|
|
||
|
|
|
||
|
|
def interactive_cli():
|
||
|
|
"""Interactive command-line interface"""
|
||
|
|
print("🚀 LangChain + LangGraph Scaffolding")
|
||
|
|
print("=" * 50)
|
||
|
|
|
||
|
|
manager = WorkflowManager()
|
||
|
|
|
||
|
|
while True:
|
||
|
|
print("\nAvailable workflows:")
|
||
|
|
for i, workflow in enumerate(manager.get_available_workflows(), 1):
|
||
|
|
print(f"{i}. {workflow}")
|
||
|
|
print("0. Exit")
|
||
|
|
|
||
|
|
try:
|
||
|
|
choice = input("\nSelect workflow (0-2): ").strip()
|
||
|
|
|
||
|
|
if choice == "0":
|
||
|
|
print("Goodbye!")
|
||
|
|
break
|
||
|
|
elif choice == "1":
|
||
|
|
workflow_type = WorkflowType.CONVERSATION
|
||
|
|
print("\n💬 Conversation Mode - Type 'quit' to return to menu")
|
||
|
|
elif choice == "2":
|
||
|
|
workflow_type = WorkflowType.TOOL_USING
|
||
|
|
print("\n🔧 Tool Mode - Type 'quit' to return to menu")
|
||
|
|
else:
|
||
|
|
print("Invalid choice")
|
||
|
|
continue
|
||
|
|
|
||
|
|
# Interactive session
|
||
|
|
session_id = None
|
||
|
|
while True:
|
||
|
|
user_input = input("\nYou: ").strip()
|
||
|
|
|
||
|
|
if user_input.lower() in ['quit', 'exit', 'q']:
|
||
|
|
break
|
||
|
|
|
||
|
|
if not user_input:
|
||
|
|
continue
|
||
|
|
|
||
|
|
try:
|
||
|
|
result = manager.execute_workflow(
|
||
|
|
workflow_type,
|
||
|
|
user_input,
|
||
|
|
session_id=session_id
|
||
|
|
)
|
||
|
|
|
||
|
|
session_id = result['session_id']
|
||
|
|
|
||
|
|
# Extract and display the response
|
||
|
|
last_message = result['result']['messages'][-1]
|
||
|
|
if hasattr(last_message, 'content'):
|
||
|
|
print(f"AI: {last_message.content}")
|
||
|
|
|
||
|
|
# Show tool usage if any
|
||
|
|
if hasattr(last_message, 'tool_calls') and last_message.tool_calls:
|
||
|
|
print(f"🔧 Tools used: {[tc['name'] for tc in last_message.tool_calls]}")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ Error: {e}")
|
||
|
|
|
||
|
|
except KeyboardInterrupt:
|
||
|
|
print("\n\nGoodbye!")
|
||
|
|
break
|
||
|
|
except Exception as e:
|
||
|
|
print(f"Error: {e}")
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
"""Main function"""
|
||
|
|
try:
|
||
|
|
from config import Config
|
||
|
|
Config.validate_config()
|
||
|
|
interactive_cli()
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ Configuration error: {e}")
|
||
|
|
print("\nPlease make sure to:")
|
||
|
|
print("1. Copy .env.example to .env")
|
||
|
|
print("2. Set your OPENAI_API_KEY in the .env file")
|
||
|
|
print("3. Install dependencies: pip install -r requirements.txt")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|