mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
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:
@ -48,10 +48,10 @@ __all__ = list(__all_classes.keys()) + ["__all_classes"]
|
||||
|
||||
del _package_path, _import_submodules, _extract_classes_from_module
|
||||
|
||||
|
||||
def component_class(class_name):
|
||||
m = importlib.import_module("agent.component")
|
||||
try:
|
||||
return getattr(m, class_name)
|
||||
except Exception:
|
||||
return getattr(importlib.import_module("agent.tools"), class_name)
|
||||
|
||||
|
||||
@ -23,7 +23,6 @@ from typing import Any
|
||||
|
||||
import json_repair
|
||||
|
||||
from agent.component.llm import LLMParam, LLM
|
||||
from agent.tools.base import LLMToolPluginCallSession, ToolParamBase, ToolBase, ToolMeta
|
||||
from api.db.services.llm_service import LLMBundle, TenantLLMService
|
||||
from api.db.services.mcp_server_service import MCPServerService
|
||||
@ -32,6 +31,7 @@ from rag.prompts import message_fit_in
|
||||
from rag.prompts.prompts import next_step, COMPLETE_TASK, analyze_task, \
|
||||
citation_prompt, reflect, rank_memories, kb_prompt, citation_plus, full_question
|
||||
from rag.utils.mcp_tool_call_conn import MCPToolCallSession, mcp_tool_metadata_to_openai_tool
|
||||
from agent.component.llm import LLMParam, LLM
|
||||
|
||||
|
||||
class AgentParam(LLMParam, ToolParamBase):
|
||||
@ -330,3 +330,4 @@ Respond immediately with your final comprehensive answer.
|
||||
logging.exception(e)
|
||||
|
||||
return "Error occurred."
|
||||
|
||||
|
||||
@ -13,9 +13,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import re
|
||||
import time
|
||||
from abc import ABC
|
||||
from abc import ABC, abstractmethod
|
||||
import builtins
|
||||
import json
|
||||
import os
|
||||
@ -535,3 +536,6 @@ class ComponentBase(ABC):
|
||||
def get_exception_default_value(self):
|
||||
return self._param.exception_default_value
|
||||
|
||||
@abstractmethod
|
||||
def thoughts(self) -> str:
|
||||
...
|
||||
|
||||
@ -44,3 +44,6 @@ class Begin(UserFillUp):
|
||||
v = v.get("value")
|
||||
self.set_output(k, v)
|
||||
self.set_input_value(k, v)
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "☕ Here we go..."
|
||||
|
||||
@ -20,7 +20,7 @@ from abc import ABC
|
||||
|
||||
from api.db import LLMType
|
||||
from api.db.services.llm_service import LLMBundle
|
||||
from agent.component import LLMParam, LLM
|
||||
from agent.component.llm import LLMParam, LLM
|
||||
from api.utils.api_utils import timeout
|
||||
from rag.llm.chat_model import ERROR_PREFIX
|
||||
|
||||
@ -133,3 +133,5 @@ class Categorize(LLM, ABC):
|
||||
self.set_output("category_name", max_category)
|
||||
self.set_output("_next", cpn_ids)
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "Which should it falls into {}? ...".format(",".join([f"`{c}`" for c, _ in self._param.category_description.items()]))
|
||||
@ -34,6 +34,7 @@ class UserFillUp(ComponentBase):
|
||||
for k, v in kwargs.get("inputs", {}).items():
|
||||
self.set_output(k, v)
|
||||
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "Waiting for your input..."
|
||||
|
||||
|
||||
|
||||
@ -137,3 +137,6 @@ class Invoke(ComponentBase, ABC):
|
||||
return f"Http request error: {last_e}"
|
||||
|
||||
assert False, self.output()
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "Waiting for the server respond..."
|
||||
@ -53,6 +53,8 @@ class Iteration(ComponentBase, ABC):
|
||||
if not isinstance(arr, list):
|
||||
self.set_output("_ERROR", self._param.items_ref + " must be an array, but its type is "+str(type(arr)))
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "Need to process {} items.".format(len(self._canvas.get_variable_value(self._param.items_ref)))
|
||||
|
||||
|
||||
|
||||
|
||||
@ -79,3 +79,5 @@ class IterationItem(ComponentBase, ABC):
|
||||
def end(self):
|
||||
return self._idx == -1
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "Next turn..."
|
||||
@ -240,3 +240,7 @@ class LLM(ComponentBase):
|
||||
summ = tool_call_summary(self.chat_mdl, func_name, params, results)
|
||||
logging.info(f"[MEMORY]: {summ}")
|
||||
self._canvas.add_memory(user, assist, summ)
|
||||
|
||||
def thoughts(self) -> str:
|
||||
_, msg = self._prepare_prompt_variables()
|
||||
return f"I’m thinking and planning the next move, starting from the prompt:<br/>“{msg[-1]['content']}”<span class=\"collapse\"> (tap to see full text)</span>"
|
||||
@ -142,3 +142,5 @@ class Message(ComponentBase):
|
||||
|
||||
self.set_output("content", content)
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "Thinking ..."
|
||||
|
||||
@ -94,5 +94,7 @@ class StringTransform(Message, ABC):
|
||||
|
||||
self.set_output("result", script)
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return f"It's {self._param.method}ing."
|
||||
|
||||
|
||||
|
||||
@ -125,4 +125,7 @@ class Switch(ComponentBase, ABC):
|
||||
except Exception:
|
||||
return True if input <= value else False
|
||||
|
||||
raise ValueError('Not supported operator' + operator)
|
||||
raise ValueError('Not supported operator' + operator)
|
||||
|
||||
def thoughts(self) -> str:
|
||||
return "I’m weighing a few options and will pick the next step shortly."
|
||||
Reference in New Issue
Block a user