MCPcopy
hub / github.com/666ghj/BettaFish / run

Method run

InsightEngine/nodes/search_node.py:45–79  ·  view source on GitHub ↗

调用LLM生成搜索查询和理由 Args: input_data: 包含title和content的字符串或字典 **kwargs: 额外参数 Returns: 包含search_query和reasoning的字典

(self, input_data: Any, **kwargs)

Source from the content-addressed store, hash-verified

43 return False
44
45 def run(self, input_data: Any, **kwargs) -> Dict[str, str]:
46 """
47 调用LLM生成搜索查询和理由
48
49 Args:
50 input_data: 包含title和content的字符串或字典
51 **kwargs: 额外参数
52
53 Returns:
54 包含search_query和reasoning的字典
55 """
56 try:
57 if not self.validate_input(input_data):
58 raise ValueError("输入数据格式错误,需要包含title和content字段")
59
60 # 准备输入数据
61 if isinstance(input_data, str):
62 message = input_data
63 else:
64 message = json.dumps(input_data, ensure_ascii=False)
65
66 logger.info("正在生成首次搜索查询")
67
68 # 调用LLM(流式,安全拼接UTF-8)
69 response = self.llm_client.stream_invoke_to_string(SYSTEM_PROMPT_FIRST_SEARCH, message)
70
71 # 处理响应
72 processed_response = self.process_output(response)
73
74 logger.info(f"生成搜索查询: {processed_response.get('search_query', 'N/A')}")
75 return processed_response
76
77 except Exception as e:
78 logger.exception(f"生成首次搜索查询失败: {str(e)}")
79 raise e
80
81 def process_output(self, output: str) -> Dict[str, str]:
82 """

Callers

nothing calls this directly

Calls 4

validate_inputMethod · 0.95
process_outputMethod · 0.95
getMethod · 0.45

Tested by

no test coverage detected