file_allcontent.py 993 B

12345678910111213141516171819202122232425262728
  1. from typing import Type
  2. from pydantic import BaseModel, Field
  3. from app.core.tools.base_tool import BaseTool
  4. from config.llm import tool_settings
  5. from sqlalchemy.orm import Session
  6. from app.models.run import Run
  7. from app.services.file.file import FileService
  8. class FileContnetTool(BaseTool):
  9. name: str = "file_content"
  10. description: str = (
  11. "读取文件的所有或者全部内容并返回给用户,这里每一次只允许触发一次"
  12. "只有提到读取全部内容的时候才会返回全部内容,其他时候这个工具不会调用"
  13. "和file_search工具不会同时使用,用了此工具就不会调用file_search"
  14. )
  15. file_ids: list[str] = []
  16. args_schema: Type[BaseModel] = {}
  17. def configure(self, session: Session, run: Run, **kwargs):
  18. if run.file_ids is not None and len(run.file_ids) > 0:
  19. self.file_ids = run.file_ids
  20. def run(self) -> dict:
  21. return FileService.retrieve_documents(ids=self.file_ids)