This commit is contained in:
2026-02-26 13:43:44 +08:00
parent 2c2db92ae9
commit 68200cdfe6
51 changed files with 2107 additions and 351 deletions
+32 -17
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
Basic usage examples for the LangChain + LangGraph scaffolding
LangChain + LangGraph 脚手架的基础用法示例
"""
import sys
@@ -11,57 +11,72 @@ from workflows.workflow_manager import WorkflowManager, WorkflowType
def example_conversation():
"""Example of using the conversation workflow"""
"""对话工作流示例"""
print("=== Conversation Workflow Example ===")
# 使用 config.ini 中的默认模型
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")
# 使用不同模型的示例
# print("\n--- Using a different model (gpt-3.5-turbo) ---")
# try:
# manager_alt_model = WorkflowManager(default_model_section='gpt-3.5-turbo')
# result_alt = manager_alt_model.execute_workflow(
# WorkflowType.CONVERSATION,
# "Hi, what model are you?"
# )
# print(f"Response from gpt-3.5-turbo: {result_alt['result']['messages'][-1].content}")
# except ValueError as e:
# print(f"Could not run alternate model example: {e}")
# print("Please ensure you have a [gpt-3.5-turbo] section in your config.ini")
#
# 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"
"计算 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'):
elif hasattr(message, 'content') and message.content:
print(f"Response: {message.content}")
print("\n")
def list_available_workflows():
"""List all available workflows"""
"""列出可用工作流"""
print("=== Available Workflows ===")
manager = WorkflowManager()
@@ -74,14 +89,14 @@ def list_available_workflows():
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()
@@ -89,6 +104,6 @@ if __name__ == "__main__":
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("1. Copy 'config/config.ini.example' to 'config/config.ini'")
print("2. Set your API key in the 'config/config.ini' file")
print("3. Install dependencies: pip install -r requirements.txt")