file_allcontent.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from typing import Type, List
  2. from pydantic import BaseModel, Field
  3. from sqlalchemy.orm import Session
  4. from app.core.tools.base_tool import BaseTool
  5. from app.models.run import Run
  6. from app.services.file.file import FileService
  7. class FileContnetToolInput(BaseModel):
  8. """This tool requires no arguments."""
  9. pass
  10. class FileContnetTool(BaseTool):
  11. name: str = "read_full_file_content"
  12. description: str = (
  13. "ONLY trigger this tool when the user explicitly requests to read the COMPLETE or FULL content of an uploaded file. "
  14. "Key trigger phrases include: '读取全部内容', '显示所有内容', '完整的文件', 'read the full content', 'read all content', 'complete file', 'entire content'. "
  15. "Critical rules: "
  16. "1. STRICTLY requires an explicit user command to read everything. Do NOT trigger for summaries, searches, or overviews. "
  17. "2. This tool is mutually exclusive with 'file_search' or 'file_content_processor'. If this tool is triggered, those must NOT be used. "
  18. "3. Operates as a strict singleton: ABSOLUTELY ONLY 1 invocation is permitted per user request. "
  19. "4. MUST confirm that files are available before execution."
  20. )
  21. args_schema: Type[BaseModel] = FileContnetToolInput
  22. def __init__(self) -> None:
  23. super().__init__()
  24. self.file_ids = []
  25. def configure(self, session: Session, run: Run, **kwargs):
  26. if run.file_ids is not None and len(run.file_ids) > 0:
  27. self.file_ids = run.file_ids
  28. def run(self) -> dict:
  29. files = []
  30. if self.file_ids is not None and len(self.file_ids) > 0:
  31. files = FileService.list_chunks(ids=self.file_ids)
  32. return files
  33. def instruction_supplement(self) -> str:
  34. """
  35. 为 Retrieval 提供文件选择信息,用于 llm 调用抉择
  36. """
  37. return ""