验证LLM连接
()
| 55 | return False |
| 56 | |
| 57 | def validate_llm_connection(): |
| 58 | """验证LLM连接""" |
| 59 | try: |
| 60 | # Import LLM model when needed |
| 61 | from contest_trade.models.llm_model import GLOBAL_LLM |
| 62 | |
| 63 | console.print("🔍 [cyan]正在验证LLM配置...[/cyan]") |
| 64 | test_messages = [ |
| 65 | {"role": "user", "content": "请回复'连接测试成功',不要添加任何其他内容。"} |
| 66 | ] |
| 67 | result = GLOBAL_LLM.run(test_messages, max_tokens=1, temperature=0.1, max_retries=0) |
| 68 | if result and hasattr(result, 'content') and result.content: |
| 69 | console.print(f"✅ [green]LLM连接成功[/green] - 模型: {GLOBAL_LLM.model_name}") |
| 70 | return True |
| 71 | else: |
| 72 | console.print("❌ [red]LLM连接失败 - 无响应内容[/red]") |
| 73 | return False |
| 74 | except Exception as e: |
| 75 | console.print(f"❌ [red]LLM连接失败: {str(e)}[/red]") |
| 76 | return False |
| 77 | |
| 78 | def validate_required_services(): |
| 79 | """根据配置文件中的tushare_key自动决定验证策略""" |
no test coverage detected