Squashed 'packages/tools/' content from commit 78317b9c

git-subtree-dir: packages/tools
git-subtree-split: 78317b9c127f18bd040c1d77e3c0840cdc9a5b38
This commit is contained in:
Greyson Lalonde
2025-09-12 21:58:02 -04:00
commit e16606672a
303 changed files with 49010 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
# TXTSearchTool
## Description
This tool is used to perform a RAG (Retrieval-Augmented Generation) search within the content of a text file. It allows for semantic searching of a query within a specified text file's content, making it an invaluable resource for quickly extracting information or finding specific sections of text based on the query provided.
## Installation
To use the TXTSearchTool, you first need to install the crewai_tools package. This can be done using pip, a package manager for Python. Open your terminal or command prompt and enter the following command:
```shell
pip install 'crewai[tools]'
```
This command will download and install the TXTSearchTool along with any necessary dependencies.
## Example
The following example demonstrates how to use the TXTSearchTool to search within a text file. This example shows both the initialization of the tool with a specific text file and the subsequent search within that file's content.
```python
from crewai_tools import TXTSearchTool
# Initialize the tool to search within any text file's content the agent learns about during its execution
tool = TXTSearchTool()
# OR
# Initialize the tool with a specific text file, so the agent can search within the given text file's content
tool = TXTSearchTool(txt='path/to/text/file.txt')
```
## Arguments
- `txt` (str): **Optinal**. The path to the text file you want to search. This argument is only required if the tool was not initialized with a specific text file; otherwise, the search will be conducted within the initially provided text file.
## Custom model and embeddings
By default, the tool uses OpenAI for both embeddings and summarization. To customize the model, you can use a config dictionary as follows:
```python
tool = TXTSearchTool(
config=dict(
llm=dict(
provider="ollama", # or google, openai, anthropic, llama2, ...
config=dict(
model="llama2",
# temperature=0.5,
# top_p=1,
# stream=true,
),
),
embedder=dict(
provider="google",
config=dict(
model="models/embedding-001",
task_type="retrieval_document",
# title="Embeddings",
),
),
)
)
```

View File

@@ -0,0 +1,45 @@
from typing import Optional, Type
from pydantic import BaseModel, Field
from ..rag.rag_tool import RagTool
class FixedTXTSearchToolSchema(BaseModel):
"""Input for TXTSearchTool."""
search_query: str = Field(
...,
description="Mandatory search query you want to use to search the txt's content",
)
class TXTSearchToolSchema(FixedTXTSearchToolSchema):
"""Input for TXTSearchTool."""
txt: str = Field(..., description="File path or URL of a TXT file to be searched")
class TXTSearchTool(RagTool):
name: str = "Search a txt's content"
description: str = (
"A tool that can be used to semantic search a query from a txt's content."
)
args_schema: Type[BaseModel] = TXTSearchToolSchema
def __init__(self, txt: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
if txt is not None:
self.add(txt)
self.description = f"A tool that can be used to semantic search a query the {txt} txt's content."
self.args_schema = FixedTXTSearchToolSchema
self._generate_description()
def _run(
self,
search_query: str,
txt: Optional[str] = None,
) -> str:
if txt is not None:
self.add(txt)
return super()._run(query=search_query)