init
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Basic usage examples for the LangChain + LangGraph scaffolding
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
from workflows.workflow_manager import WorkflowManager, WorkflowType
|
||||
|
||||
|
||||
def example_conversation():
|
||||
"""Example of using the conversation workflow"""
|
||||
print("=== Conversation Workflow Example ===")
|
||||
|
||||
manager = WorkflowManager()
|
||||
|
||||
# First message
|
||||
result1 = manager.execute_workflow(
|
||||
WorkflowType.CONVERSATION,
|
||||
"Hello! Can you help me with some calculations?"
|
||||
)
|
||||
|
||||
print(f"Session ID: {result1['session_id']}")
|
||||
print(f"Response: {result1['result']['messages'][-1].content}")
|
||||
|
||||
# Second message in the same session
|
||||
result2 = manager.execute_workflow(
|
||||
WorkflowType.CONVERSATION,
|
||||
"What can you help me with?",
|
||||
session_id=result1['session_id']
|
||||
)
|
||||
|
||||
print(f"Second response: {result2['result']['messages'][-1].content}")
|
||||
print("\n")
|
||||
|
||||
|
||||
def example_tool_usage():
|
||||
"""Example of using the tool workflow"""
|
||||
print("=== Tool Workflow Example ===")
|
||||
|
||||
manager = WorkflowManager()
|
||||
|
||||
# Use calculator tool
|
||||
result = manager.execute_workflow(
|
||||
WorkflowType.TOOL_USING,
|
||||
"Calculate 25 * 4 + 10"
|
||||
)
|
||||
|
||||
print(f"Session ID: {result['session_id']}")
|
||||
|
||||
# Extract tool messages and responses
|
||||
for message in result['result']['messages']:
|
||||
if hasattr(message, 'tool_calls') and message.tool_calls:
|
||||
print(f"Tool call: {message.tool_calls}")
|
||||
elif hasattr(message, 'content'):
|
||||
print(f"Response: {message.content}")
|
||||
|
||||
print("\n")
|
||||
|
||||
|
||||
def list_available_workflows():
|
||||
"""List all available workflows"""
|
||||
print("=== Available Workflows ===")
|
||||
|
||||
manager = WorkflowManager()
|
||||
workflows = manager.get_available_workflows()
|
||||
|
||||
for workflow in workflows:
|
||||
print(f"- {workflow}")
|
||||
|
||||
print("\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Check if configuration is valid
|
||||
try:
|
||||
from config import Config
|
||||
Config.validate_config()
|
||||
print("✅ Configuration is valid")
|
||||
print("\n")
|
||||
|
||||
# Run examples
|
||||
list_available_workflows()
|
||||
example_conversation()
|
||||
example_tool_usage()
|
||||
|
||||
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")
|
||||
Reference in New Issue
Block a user