Skip to content

Commit 72ff497

Browse files
authored
Merge pull request #3 from pygig/feat/knowledge-source
feat/knowledge-source
2 parents c065370 + e8c3451 commit 72ff497

19 files changed

Lines changed: 1895 additions & 75 deletions

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This project and everyone participating in it is governed by our Code of Conduct
3434
```bash
3535
# Create a virtual environment
3636
python -m venv venv
37-
source venv/bin/activate # On Windows: venv\Scripts\activate
37+
knowledge venv/bin/activate # On Windows: venv\Scripts\activate
3838

3939
# Install dependencies
4040
pip install poetry
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pydantic import BaseModel, Field
99

1010

11-
from pilottai.config.model import KnowledgeSource, CacheEntry
11+
from pilottai_tools.config.model import KnowledgeSource, CacheEntry
1212

1313
class DataManager:
1414
def __init__(self, cache_size: int = 1000, cache_ttl: int = 3600):
@@ -58,7 +58,7 @@ async def add_source(self, source: KnowledgeSource) -> bool:
5858
return connected
5959

6060
except Exception as e:
61-
self.logger.error(f"Error adding source {source.name}: {str(e)}")
61+
self.logger.error(f"Error adding knowledge {source.name}: {str(e)}")
6262
return False
6363

6464
async def query_knowledge(
@@ -89,7 +89,7 @@ async def query_knowledge(
8989
if result is not None:
9090
results.append(result)
9191
except Exception as e:
92-
self.logger.error(f"Error querying source {source_type}: {str(e)}")
92+
self.logger.error(f"Error querying knowledge {source_type}: {str(e)}")
9393
source.error_count += 1
9494
continue
9595
if results:
@@ -119,12 +119,12 @@ async def _query_source_with_retry(
119119
return result
120120
except asyncio.TimeoutError:
121121
self.logger.warning(
122-
f"Query timeout for source {source.name}, attempt {attempt + 1}"
122+
f"Query timeout for knowledge {source.name}, attempt {attempt + 1}"
123123
)
124124
source.error_count += 1
125125
except Exception as e:
126126
self.logger.error(
127-
f"Query failed for source {source.name}, attempt {attempt + 1}: {str(e)}"
127+
f"Query failed for knowledge {source.name}, attempt {attempt + 1}: {str(e)}"
128128
)
129129
source.error_count += 1
130130
if attempt < source.max_retries - 1:
@@ -223,7 +223,7 @@ async def cleanup(self):
223223
]
224224
for k in expired_keys:
225225
del self.cache[k]
226-
# Check source health
226+
# Check knowledge health
227227
for source_name, source in self.sources.items():
228228
if source.error_count > source.max_retries:
229229
source.is_connected = False
File renamed without changes.

pilottai_tools/source/source/audio_input.py renamed to pilottai_tools/knowledge/source/audio_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
from datetime import datetime, timedelta
66

77

8-
from pilottai.knowledge.source.base_input import BaseInputSource
8+
from pilottai_tools.knowledge.source.base_input import BaseInputSource
99

1010

1111
class AudioInput(BaseInputSource):
1212
"""
13-
Input source for processing audio files.
13+
Input knowledge for processing audio files.
1414
Extracts and processes speech from audio files using speech-to-text technology.
1515
"""
1616

pilottai_tools/source/source/base_input.py renamed to pilottai_tools/knowledge/source/base_input.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class SourceMetadata(BaseModel):
11-
"""Metadata for an input source"""
11+
"""Metadata for an input knowledge"""
1212
source_type: str
1313
created_at: datetime = Field(default_factory=datetime.now)
1414
updated_at: datetime = Field(default_factory=datetime.now)
@@ -19,7 +19,7 @@ class SourceMetadata(BaseModel):
1919

2020
class BaseInputSource(ABC):
2121
"""
22-
Abstract base class for all source input sources.
22+
Abstract base class for all knowledge input sources.
2323
Provides common functionality for processing and storing content.
2424
"""
2525
model_config = ConfigDict(arbitrary_types_allowed=True)
@@ -62,7 +62,7 @@ def __init__(
6262
self.logger = self._setup_logger()
6363

6464
def _setup_logger(self) -> logging.Logger:
65-
"""Setup a logger for this input source"""
65+
"""Setup a logger for this input knowledge"""
6666
logger = logging.getLogger(f"InputSource_{self.name}")
6767
if not logger.handlers:
6868
handler = logging.StreamHandler()
@@ -77,36 +77,36 @@ def _setup_logger(self) -> logging.Logger:
7777
@abstractmethod
7878
async def connect(self) -> bool:
7979
"""
80-
Establish a connection to the source.
80+
Establish a connection to the knowledge.
8181
Returns True if successful, False otherwise.
8282
"""
8383
pass
8484

8585
@abstractmethod
8686
async def query(self, query: str) -> Any:
8787
"""
88-
Query the source with the given query.
88+
Query the knowledge with the given query.
8989
This method should be implemented by subclasses.
9090
"""
9191
pass
9292

9393
@abstractmethod
9494
async def validate_content(self) -> bool:
9595
"""
96-
Validate that the content from the source is accessible and processable.
96+
Validate that the content from the knowledge is accessible and processable.
9797
Returns True if valid, False otherwise.
9898
"""
9999
pass
100100

101101
async def add(self) -> bool:
102102
"""
103-
Process content from the source, chunk it, and save it to storage.
103+
Process content from the knowledge, chunk it, and save it to storage.
104104
Returns True if successful, False otherwise.
105105
"""
106106
try:
107107
# Validate content
108108
if not await self.validate_content():
109-
self.logger.error(f"Content validation failed for source {self.name}")
109+
self.logger.error(f"Content validation failed for knowledge {self.name}")
110110
return False
111111

112112
# Process and chunk content
@@ -119,14 +119,14 @@ async def add(self) -> bool:
119119
return len(self.chunks) > 0
120120

121121
except Exception as e:
122-
self.logger.error(f"Error adding content from source {self.name}: {str(e)}")
122+
self.logger.error(f"Error adding content from knowledge {self.name}: {str(e)}")
123123
self.error_count += 1
124124
return False
125125

126126
@abstractmethod
127127
async def _process_content(self) -> None:
128128
"""
129-
Process the content from the source and populate the chunks.
129+
Process the content from the knowledge and populate the chunks.
130130
This method should be implemented by subclasses.
131131
"""
132132
pass
@@ -139,7 +139,7 @@ async def _save_to_storage(self) -> bool:
139139

140140
# Create metadata for each chunk
141141
chunk_metadata = [{
142-
"source": self.name,
142+
"knowledge": self.name,
143143
"collection": self.collection_name,
144144
"chunk_index": i,
145145
"total_chunks": len(self.chunks),
@@ -169,12 +169,12 @@ def _chunk_text(self, text: str) -> List[str]:
169169
return chunks
170170

171171
async def refresh(self) -> bool:
172-
"""Refresh content from the source"""
172+
"""Refresh content from the knowledge"""
173173
self.chunks = []
174174
return await self.add()
175175

176176
def get_info(self) -> Dict[str, Any]:
177-
"""Get information about this input source"""
177+
"""Get information about this input knowledge"""
178178
return {
179179
"name": self.name,
180180
"type": self.__class__.__name__,

pilottai_tools/source/source/doc_input.py renamed to pilottai_tools/knowledge/source/doc_input.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import docx
55
import io
66

7-
from pilottai.knowledge.source.base_input import BaseInputSource
7+
from pilottai_tools.knowledge.source.base_input import BaseInputSource
88

99

1010
class DocInput(BaseInputSource):
1111
"""
12-
Input source for processing Microsoft Word documents (.doc, .docx).
12+
Input knowledge for processing Microsoft Word documents (.doc, .docx).
1313
Extracts and processes text content from Word documents.
1414
"""
1515

pilottai_tools/source/source/image_input.py renamed to pilottai_tools/knowledge/source/image_input.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
from datetime import datetime
44
import io
55
from PIL import Image
6-
import pytesseract
76
import numpy as np
8-
import cv2.cv2 as cv2
7+
import cv2 as cv2
98

109

11-
from pilottai.knowledge.source.base_input import BaseInputSource
10+
from pilottai_tools.knowledge.source.base_input import BaseInputSource
1211

1312

1413
class ImageInput(BaseInputSource):
1514
"""
16-
Input source for processing images.
15+
Input knowledge for processing images.
1716
Extracts text content from images using OCR (Optical Character Recognition).
1817
"""
1918

@@ -69,7 +68,7 @@ async def connect(self) -> bool:
6968
self.is_connected = True
7069
return True
7170

72-
self.logger.error("No image source provided")
71+
self.logger.error("No image knowledge provided")
7372
self.is_connected = False
7473
return False
7574

@@ -138,12 +137,12 @@ async def extract_text(self) -> bool:
138137
if self.preprocess:
139138
image_for_ocr = self._preprocess_image(self.pil_image)
140139

141-
# Run OCR
142-
self.text_content = pytesseract.image_to_string(
143-
image_for_ocr,
144-
lang=self.lang,
145-
config=self.ocr_config
146-
)
140+
#TODO
141+
# self.text_content = pytesseract.image_to_string(
142+
# image_for_ocr,
143+
# lang=self.lang,
144+
# config=self.ocr_config
145+
# )
147146

148147
return bool(self.text_content.strip())
149148

pilottai_tools/source/source/json_input.py renamed to pilottai_tools/knowledge/source/json_input.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from typing import Any, Dict, List, Optional, Union
33
from datetime import datetime
44

5-
from pilottai.knowledge.source.base_input import BaseInputSource
5+
from pilottai_tools.knowledge.source.base_input import BaseInputSource
66

77

88
class JSONInput(BaseInputSource):
99
"""
10-
Input source for processing JSON data.
11-
Handles structured JSON content for source extraction.
10+
Input knowledge for processing JSON data.
11+
Handles structured JSON content for knowledge extraction.
1212
"""
1313

1414
def __init__(
@@ -148,7 +148,7 @@ async def _process_content(self) -> None:
148148
text_content = json.dumps(self.json_data, indent=2)
149149

150150
self.chunks = self._chunk_text(text_content)
151-
self.logger.info(f"Created {len(self.chunks)} chunks from JSON source {self.name}")
151+
self.logger.info(f"Created {len(self.chunks)} chunks from JSON knowledge {self.name}")
152152

153153
def _flatten_json(self, data, parent_key='', sep='.') -> str:
154154
"""Flatten nested JSON into a string representation"""

pilottai_tools/source/source/markup_input.py renamed to pilottai_tools/knowledge/source/markup_input.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import json
99
from xml.etree import ElementTree as ET
1010

11-
from pilottai.knowledge.source.base_input import BaseInputSource
11+
from pilottai_tools.knowledge.source.base_input import BaseInputSource
1212

1313

1414
class MarkupInput(BaseInputSource):
1515
"""
16-
Input source for processing markup documents (HTML, XML, Markdown, YAML).
16+
Input knowledge for processing markup documents (HTML, XML, Markdown, YAML).
1717
Extracts and processes content from various markup formats.
1818
"""
1919

@@ -80,7 +80,7 @@ async def connect(self) -> bool:
8080
self.is_connected = bool(self.raw_content)
8181
return self.is_connected
8282

83-
self.logger.error("No content source provided")
83+
self.logger.error("No content knowledge provided")
8484
self.is_connected = False
8585
return False
8686

pilottai_tools/source/source/stream_input.py renamed to pilottai_tools/knowledge/source/stream_input.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import threading
77
from collections import deque
88

9-
from pilottai.knowledge.source.base_input import BaseInputSource
9+
from pilottai_tools.knowledge.source.base_input import BaseInputSource
1010

1111

1212
class StreamInput(BaseInputSource):
1313
"""
14-
Input source for processing streaming data.
14+
Input knowledge for processing streaming data.
1515
Handles continuous data streams and real-time processing.
1616
"""
1717

@@ -62,7 +62,7 @@ def __init__(
6262
self.start()
6363

6464
async def connect(self) -> bool:
65-
"""Check if the streaming source is accessible"""
65+
"""Check if the streaming knowledge is accessible"""
6666
try:
6767
# For streaming sources, connection is established by starting the worker
6868
if self.running:

0 commit comments

Comments
 (0)