mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-10 08:38:30 +00:00
fixed types
This commit is contained in:
@@ -156,14 +156,35 @@ crew = Crew(
|
|||||||
agents=[agent],
|
agents=[agent],
|
||||||
tasks=[task],
|
tasks=[task],
|
||||||
knowledge_sources=[source],
|
knowledge_sources=[source],
|
||||||
embedder_config={
|
embedder={
|
||||||
"model": "BAAI/bge-small-en-v1.5",
|
"provider": "ollama",
|
||||||
"normalize": True,
|
"config": {"model": "nomic-embed-text:latest"},
|
||||||
"max_length": 512
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Referencing Sources
|
||||||
|
|
||||||
|
You can reference knowledge sources by their collection name or metadata.
|
||||||
|
|
||||||
|
* Add a directory to your crew project called `knowledge`:
|
||||||
|
* File paths in knowledge can be referenced relative to the `knowledge` directory.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
A file inside the `knowledge` directory called `example.txt` can be referenced as `example.txt`.
|
||||||
|
|
||||||
|
```python
|
||||||
|
source = TextFileKnowledgeSource(
|
||||||
|
file_path="example.txt", # or /example.txt
|
||||||
|
collection_name="example"
|
||||||
|
)
|
||||||
|
crew = Crew(
|
||||||
|
agents=[agent],
|
||||||
|
tasks=[task],
|
||||||
|
knowledge_sources=[source],
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
<AccordionGroup>
|
<AccordionGroup>
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource):
|
|||||||
if not isinstance(paths, list):
|
if not isinstance(paths, list):
|
||||||
raise ValueError("file_path must be a Path or a list of Paths")
|
raise ValueError("file_path must be a Path or a list of Paths")
|
||||||
|
|
||||||
|
# Ensure all paths are Path objects
|
||||||
|
paths = [Path(path) if isinstance(path, str) else path for path in paths]
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
self._logger.log(
|
self._logger.log(
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ class ExcelKnowledgeSource(BaseFileKnowledgeSource):
|
|||||||
pd = self._import_dependencies()
|
pd = self._import_dependencies()
|
||||||
|
|
||||||
if isinstance(self.file_path, list):
|
if isinstance(self.file_path, list):
|
||||||
file_path = self.file_path[0]
|
file_path = self.convert_to_path(self.file_path[0])
|
||||||
else:
|
else:
|
||||||
file_path = self.file_path
|
file_path = self.convert_to_path(self.file_path)
|
||||||
|
|
||||||
df = pd.read_excel(file_path)
|
df = pd.read_excel(file_path)
|
||||||
content = df.to_csv(index=False)
|
content = df.to_csv(index=False)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class JSONKnowledgeSource(BaseFileKnowledgeSource):
|
|||||||
|
|
||||||
content: Dict[Path, str] = {}
|
content: Dict[Path, str] = {}
|
||||||
for path in paths:
|
for path in paths:
|
||||||
|
path = self.convert_to_path(path)
|
||||||
with open(path, "r", encoding="utf-8") as json_file:
|
with open(path, "r", encoding="utf-8") as json_file:
|
||||||
data = json.load(json_file)
|
data = json.load(json_file)
|
||||||
content[path] = self._json_to_text(data)
|
content[path] = self._json_to_text(data)
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class TextFileKnowledgeSource(BaseFileKnowledgeSource):
|
|||||||
paths = [self.file_path] if isinstance(self.file_path, Path) else self.file_path
|
paths = [self.file_path] if isinstance(self.file_path, Path) else self.file_path
|
||||||
content = {}
|
content = {}
|
||||||
for path in paths:
|
for path in paths:
|
||||||
|
path = Path(path)
|
||||||
with open(path, "r", encoding="utf-8") as f:
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
content[path] = f.read()
|
content[path] = f.read()
|
||||||
return content
|
return content
|
||||||
|
|||||||
Reference in New Issue
Block a user