mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-29 01:58:14 +00:00
fix: resolve test failures for telemetry and PDF knowledge source
- Fix telemetry.ready to be False when opentelemetry is unavailable - Fix PDF knowledge source to delay pdfplumber import check until needed - Add shutdown method to SafeOTLPSpanExporter to prevent AttributeError - Verified fixes work locally with test script Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -16,8 +16,9 @@ class PDFKnowledgeSource(BaseFileKnowledgeSource):
|
|||||||
|
|
||||||
def load_content(self) -> Dict[Path, str]:
|
def load_content(self) -> Dict[Path, str]:
|
||||||
"""Load and preprocess PDF file content."""
|
"""Load and preprocess PDF file content."""
|
||||||
pdfplumber = self._import_pdfplumber()
|
if not PDFPLUMBER_AVAILABLE:
|
||||||
|
return {}
|
||||||
|
|
||||||
content = {}
|
content = {}
|
||||||
|
|
||||||
for path in self.safe_file_paths:
|
for path in self.safe_file_paths:
|
||||||
@@ -45,6 +46,8 @@ class PDFKnowledgeSource(BaseFileKnowledgeSource):
|
|||||||
Add PDF file content to the knowledge source, chunk it, compute embeddings,
|
Add PDF file content to the knowledge source, chunk it, compute embeddings,
|
||||||
and save the embeddings.
|
and save the embeddings.
|
||||||
"""
|
"""
|
||||||
|
self._import_pdfplumber()
|
||||||
|
|
||||||
for _, text in self.content.items():
|
for _, text in self.content.items():
|
||||||
new_chunks = self._chunk_text(text)
|
new_chunks = self._chunk_text(text)
|
||||||
self.chunks.extend(new_chunks)
|
self.chunks.extend(new_chunks)
|
||||||
|
|||||||
@@ -72,6 +72,15 @@ class SafeOTLPSpanExporter:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(e)
|
logger.error(e)
|
||||||
return SpanExportResult.FAILURE if SpanExportResult else None
|
return SpanExportResult.FAILURE if SpanExportResult else None
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
"""Shutdown the exporter."""
|
||||||
|
if OPENTELEMETRY_AVAILABLE and self._exporter and hasattr(self._exporter, 'shutdown'):
|
||||||
|
try:
|
||||||
|
return self._exporter.shutdown()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error during exporter shutdown: {e}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Telemetry:
|
class Telemetry:
|
||||||
@@ -107,6 +116,7 @@ class Telemetry:
|
|||||||
self._initialized: bool = True
|
self._initialized: bool = True
|
||||||
|
|
||||||
if self._is_telemetry_disabled() or not OPENTELEMETRY_AVAILABLE:
|
if self._is_telemetry_disabled() or not OPENTELEMETRY_AVAILABLE:
|
||||||
|
self.ready = False
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user