56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
import asyncio
|
||
import sys
|
||
import os
|
||
from openai import OpenAI
|
||
from rich.console import Console
|
||
from rich.panel import Panel
|
||
|
||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
from sci_mcp import *
|
||
from test_tools.multi_round_conversation import process_conversation_round
|
||
|
||
# 初始化rich控制台
|
||
console = Console()
|
||
|
||
# 设计一个简单但需要多轮查询的问题(可能会调用mattergen)
|
||
# complex_question = """我想了解LiFePO4材料在不同温度下的性能变化。请先告诉我这种材料的基本结构特性。"""
|
||
|
||
# 设计一个不调用mattergen但仍然可以触发多轮工具调用的问题(之前的尝试)
|
||
# complex_question = """我想比较TiO2和ZnO这两种材料作为光催化剂的性能。请先告诉我TiO2的晶体结构和能带特性。"""
|
||
|
||
# 设计一个需要先获取信息然后基于这些信息进行进一步分析的问题
|
||
complex_question = """我需要分析一种名为Na2Fe2(SO4)3的钠离子电池材料。请先查询这种材料的晶体结构。"""
|
||
|
||
def run_complex_query():
|
||
"""运行复杂的材料科学查询演示"""
|
||
console.print(Panel.fit(
|
||
"[bold cyan]复杂材料科学查询演示[/bold cyan] - 测试多轮对话逻辑",
|
||
border_style="cyan"
|
||
))
|
||
|
||
# 处理复杂问题
|
||
conversation_history = process_conversation_round(complex_question)
|
||
|
||
# 多轮对话循环
|
||
while True:
|
||
console.print("\n[bold cyan]输入问题继续对话,或输入 'exit' 或 'quit' 退出[/bold cyan]")
|
||
user_input = input("> ")
|
||
|
||
# 检查是否退出
|
||
if user_input.lower() in ['exit', 'quit', '退出']:
|
||
console.print("[bold cyan]演示结束,再见![/bold cyan]")
|
||
break
|
||
|
||
# 处理用户输入
|
||
conversation_history = process_conversation_round(user_input, conversation_history)
|
||
|
||
if __name__ == '__main__':
|
||
try:
|
||
run_complex_query()
|
||
except KeyboardInterrupt:
|
||
console.print("\n[bold cyan]程序被用户中断,再见![/bold cyan]")
|
||
except Exception as e:
|
||
console.print(f"\n[bold red]发生错误: {str(e)}[/bold red]")
|
||
import traceback
|
||
console.print(traceback.format_exc())
|