Feat: Add thought info to every component. (#9134)

### What problem does this PR solve?

#9082 #6365

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
Kevin Hu
2025-07-31 15:13:45 +08:00
committed by GitHub
parent 0d7a83f05f
commit 3f6177b5e5
32 changed files with 123 additions and 102 deletions

View File

@ -1,3 +1,18 @@
#
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import importlib
import inspect

View File

@ -94,3 +94,9 @@ class ArXiv(ToolBase, ABC):
return f"ArXiv error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return """
Keywords: {}
Looking for the most relevant articles.
""".format(self.get_input().get("query", "-_-!"))

View File

@ -165,3 +165,6 @@ class ToolBase(ComponentBase):
})
self._canvas.add_refernce(chunks, aggs)
self.set_output("formalized_content", "\n".join(kb_prompt({"chunks": chunks, "doc_aggs": aggs}, 200000, True)))
def thoughts(self) -> str:
return self._canvas.get_component_name(self._id) + " is running..."

View File

@ -189,4 +189,5 @@ class CodeExec(ToolBase, ABC):
def _encode_code(self, code: str) -> str:
return base64.b64encode(code.encode("utf-8")).decode("utf-8")
def thoughts(self) -> str:
return "Running a short script to process data."

View File

@ -112,3 +112,9 @@ class DuckDuckGo(ToolBase, ABC):
return f"DuckDuckGo error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return """
Keywords: {}
Looking for the most relevant articles.
""".format(self.get_input().get("query", "-_-!"))

View File

@ -204,4 +204,12 @@ class Email(ToolBase, ABC):
self.set_output("_ERROR", str(last_e))
return False
assert False, self.output()
assert False, self.output()
def thoughts(self) -> str:
inputs = self.get_input()
return """
To: {}
Subject: {}
Your email is on its way—sit tight!
""".format(inputs.get("to_email", "-_-!"), inputs.get("subject", "-_-!"))

View File

@ -128,6 +128,5 @@ class ExeSQL(ToolBase, ABC):
self.set_output("formalized_content", "\n\n".join(formalized_content))
return self.output("formalized_content")
def debug(self, **kwargs):
return self._run([], **kwargs)
def thoughts(self) -> str:
return "Query sent—waiting for the data."

View File

@ -86,3 +86,6 @@ class GitHub(ToolBase, ABC):
return f"GitHub error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return "Scanning GitHub repos related to `{}`.".format(self.get_input().get("query", "-_-!"))

View File

@ -152,3 +152,8 @@ class Google(ToolBase, ABC):
assert False, self.output()
def thoughts(self) -> str:
return """
Keywords: {}
Looking for the most relevant articles.
""".format(self.get_input().get("query", "-_-!"))

View File

@ -91,3 +91,6 @@ class GoogleScholar(ToolBase, ABC):
return f"GoogleScholar error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return "Looking for scholarly papers on `{}`,” prioritising reputable sources.".format(self.get_input().get("query", "-_-!"))

View File

@ -103,3 +103,6 @@ class PubMed(ToolBase, ABC):
return f"PubMed error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return "Looking for scholarly papers on `{}`,” prioritising reputable sources.".format(self.get_input().get("query", "-_-!"))

View File

@ -159,3 +159,9 @@ class Retrieval(ToolBase, ABC):
form_cnt = "\n".join(kb_prompt(kbinfos, 200000, True))
self.set_output("formalized_content", form_cnt)
return form_cnt
def thoughts(self) -> str:
return """
Keywords: {}
Looking for the most relevant articles.
""".format(self.get_input().get("query", "-_-!"))

View File

@ -134,6 +134,12 @@ class TavilySearch(ToolBase, ABC):
assert False, self.output()
def thoughts(self) -> str:
return """
Keywords: {}
Looking for the most relevant articles.
""".format(self.get_input().get("query", "-_-!"))
class TavilyExtractParam(ToolParamBase):
"""
@ -216,3 +222,6 @@ class TavilyExtract(ToolBase, ABC):
return f"Tavily error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return "Opened {}—pulling out the main text…".format(self.get_input().get("urls", "-_-!"))

View File

@ -109,3 +109,6 @@ class WenCai(ToolBase, ABC):
return f"WenCai error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return "Pulling live financial data for `{}`.".format(self.get_input().get("query", "-_-!"))

View File

@ -96,3 +96,9 @@ class Wikipedia(ToolBase, ABC):
return f"Wikipedia error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return """
Keywords: {}
Looking for the most relevant articles.
""".format(self.get_input().get("query", "-_-!"))

View File

@ -109,3 +109,6 @@ class YahooFinance(ToolBase, ABC):
return f"YahooFinance error: {last_e}"
assert False, self.output()
def thoughts(self) -> str:
return "Pulling live financial data for `{}`.".format(self.get_input().get("stock_code", "-_-!"))