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