fixed types

This commit is contained in:
Lorenze Jay
2024-12-03 10:12:37 -08:00
parent 543ebbf3a4
commit aab05388d5
5 changed files with 32 additions and 6 deletions

View File

@@ -156,14 +156,35 @@ crew = Crew(
agents=[agent],
tasks=[task],
knowledge_sources=[source],
embedder_config={
"model": "BAAI/bge-small-en-v1.5",
"normalize": True,
"max_length": 512
embedder={
"provider": "ollama",
"config": {"model": "nomic-embed-text:latest"},
}
)
```
### 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
<AccordionGroup>

View File

@@ -37,6 +37,9 @@ class BaseFileKnowledgeSource(BaseKnowledgeSource):
if not isinstance(paths, list):
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:
if not path.exists():
self._logger.log(

View File

@@ -12,9 +12,9 @@ class ExcelKnowledgeSource(BaseFileKnowledgeSource):
pd = self._import_dependencies()
if isinstance(self.file_path, list):
file_path = self.file_path[0]
file_path = self.convert_to_path(self.file_path[0])
else:
file_path = self.file_path
file_path = self.convert_to_path(self.file_path)
df = pd.read_excel(file_path)
content = df.to_csv(index=False)

View File

@@ -15,6 +15,7 @@ class JSONKnowledgeSource(BaseFileKnowledgeSource):
content: Dict[Path, str] = {}
for path in paths:
path = self.convert_to_path(path)
with open(path, "r", encoding="utf-8") as json_file:
data = json.load(json_file)
content[path] = self._json_to_text(data)

View File

@@ -13,6 +13,7 @@ class TextFileKnowledgeSource(BaseFileKnowledgeSource):
paths = [self.file_path] if isinstance(self.file_path, Path) else self.file_path
content = {}
for path in paths:
path = Path(path)
with open(path, "r", encoding="utf-8") as f:
content[path] = f.read()
return content