sharedkernel 1.9.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/PKG-INFO +5 -2
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/README.md +4 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/setup.py +1 -4
- sharedkernel-2.0.0/sharedkernel/database/__init__.py +1 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/database/mongo_generic_repository.py +2 -3
- sharedkernel-2.0.0/sharedkernel/enum/error_code.py +10 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/objects/base_document.py +2 -3
- sharedkernel-2.0.0/sharedkernel/objects/json_string_model.py +27 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/objects/result.py +7 -11
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel.egg-info/PKG-INFO +5 -2
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel.egg-info/SOURCES.txt +1 -5
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel.egg-info/requires.txt +0 -1
- sharedkernel-1.9.0/sharedkernel/database/__init__.py +0 -2
- sharedkernel-1.9.0/sharedkernel/database/vector_database_repository/__init__.py +0 -2
- sharedkernel-1.9.0/sharedkernel/database/vector_database_repository/chroma_startegy.py +0 -39
- sharedkernel-1.9.0/sharedkernel/database/vector_database_repository/vector_database_repository.py +0 -28
- sharedkernel-1.9.0/sharedkernel/database/vector_database_repository/vector_database_strategy.py +0 -22
- sharedkernel-1.9.0/sharedkernel/enum/error_code.py +0 -14
- sharedkernel-1.9.0/sharedkernel/enum/vector_database_type.py +0 -5
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/setup.cfg +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/common.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/data_format_converter.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/date_converter.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/enum/__init__.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/exception/__init__.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/exception/exception.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/exception/exception_handlers.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/jwt_service.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/normalizer/__init__.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/normalizer/number_normalizer.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/normalizer/phone_number_normalizer.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/objects/__init__.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/objects/jwt_model.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/regex_masking.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/s3_uploader.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/string_extentions.py +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel.egg-info/dependency_links.txt +0 -0
- {sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -9,7 +9,6 @@ Requires-Dist: requests
|
|
|
9
9
|
Requires-Dist: pymongo
|
|
10
10
|
Requires-Dist: fastapi==0.111.0
|
|
11
11
|
Requires-Dist: PyJWT
|
|
12
|
-
Requires-Dist: chromadb
|
|
13
12
|
Requires-Dist: persian_tools
|
|
14
13
|
Requires-Dist: sentry-sdk
|
|
15
14
|
Requires-Dist: jdatetime
|
|
@@ -24,6 +23,10 @@ Requires-Dist: beautifulsoup4
|
|
|
24
23
|
this a shared kernel package
|
|
25
24
|
|
|
26
25
|
# Change Log
|
|
26
|
+
### Version 2.0.0
|
|
27
|
+
- Update pydantic version
|
|
28
|
+
- Delete vector databases
|
|
29
|
+
- Implement JsonStringModel
|
|
27
30
|
### Version 1.9.0
|
|
28
31
|
- Implement DataFormatConverter
|
|
29
32
|
### Version 1.8.0
|
|
@@ -13,7 +13,6 @@ setup(
|
|
|
13
13
|
packages=[
|
|
14
14
|
"sharedkernel",
|
|
15
15
|
"sharedkernel.database",
|
|
16
|
-
"sharedkernel.database.vector_database_repository",
|
|
17
16
|
"sharedkernel.enum",
|
|
18
17
|
"sharedkernel.exception",
|
|
19
18
|
"sharedkernel.objects",
|
|
@@ -26,8 +25,6 @@ setup(
|
|
|
26
25
|
"pymongo",
|
|
27
26
|
"fastapi==0.111.0",
|
|
28
27
|
"PyJWT",
|
|
29
|
-
#"pymilvus",
|
|
30
|
-
"chromadb",
|
|
31
28
|
"persian_tools",
|
|
32
29
|
"sentry-sdk",
|
|
33
30
|
"jdatetime",
|
|
@@ -39,7 +36,7 @@ setup(
|
|
|
39
36
|
"beautifulsoup4"
|
|
40
37
|
],
|
|
41
38
|
# *strongly* suggested for sharing
|
|
42
|
-
version="
|
|
39
|
+
version="2.0.0",
|
|
43
40
|
description="sharekernel is a shared package between all python projects",
|
|
44
41
|
long_description=long_description,
|
|
45
42
|
long_description_content_type="text/markdown",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# from .mongo_repository_base import MongoRepositoryBase
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from pymongo import MongoClient
|
|
2
2
|
from bson import ObjectId
|
|
3
3
|
from typing import Generic, TypeVar, List, Type
|
|
4
|
-
from pydantic import BaseModel
|
|
4
|
+
from pydantic.v1 import BaseModel
|
|
5
5
|
from sharedkernel.string_extentions import camel_to_snake
|
|
6
6
|
|
|
7
7
|
T = TypeVar("T", bound=BaseModel)
|
|
@@ -21,8 +21,7 @@ class MongoGenericRepository(Generic[T]):
|
|
|
21
21
|
def find_one(self, id: str) -> T:
|
|
22
22
|
query = {"_id": ObjectId(id), "is_deleted": False}
|
|
23
23
|
result = self.collection.find_one(query)
|
|
24
|
-
return self._map_to_model(result) if result else None
|
|
25
|
-
|
|
24
|
+
return self._map_to_model(result) if result else None
|
|
26
25
|
|
|
27
26
|
def insert_one(self, data: T) -> str:
|
|
28
27
|
delattr(data, "id")
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ErrorCode(str, Enum):
|
|
5
|
+
Item_NotFound = "یافت نشد"
|
|
6
|
+
Internal_Server = "خطایی در سیستم رخ داده است"
|
|
7
|
+
UnAuthorized = "توکن دسترسی معتبر نمی باشد"
|
|
8
|
+
Success = "با موفقیت انجام شد"
|
|
9
|
+
Intents_Count_Should_Equal_One = "فقط یک اینتنت میتوانید وارد نمایید"
|
|
10
|
+
Unsupported_Date_Type = "تاریخ داده شده پیشتیبانی نمیشود."
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
from pydantic import BaseModel, Field
|
|
2
|
-
from typing import Optional
|
|
3
2
|
from datetime import datetime
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
class BaseDocument(BaseModel):
|
|
7
|
-
id:
|
|
8
|
-
is_deleted: bool = False
|
|
6
|
+
id: str | None = None
|
|
7
|
+
is_deleted: bool | None = False
|
|
9
8
|
created_on: datetime = Field(default_factory=datetime.now)
|
|
10
9
|
updated_on: datetime = Field(default_factory=datetime.now)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any
|
|
3
|
+
from pydantic import BaseModel, model_validator
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class JsonStringModel(BaseModel):
|
|
7
|
+
"""`BaseModel` subclass used to validate objects passed to API as JSON strings.
|
|
8
|
+
|
|
9
|
+
The primary use case is treating one of the form fields as JSON payload. We need to do that
|
|
10
|
+
in case of endpoints that accept both file and rich set of input parameters. We cannot receive
|
|
11
|
+
both file and JSON body because they use conflicting Content-Type header. It is
|
|
12
|
+
"multipart/form-data" for the former and "application/json" for the latter. If we require
|
|
13
|
+
a client to send a file, we have to use the data sent in form for input parameters.
|
|
14
|
+
|
|
15
|
+
Theoretically we could use several form fields to gather all the required input parameters.
|
|
16
|
+
However, some of them are nested in their nature and forms don't support that. That's why we
|
|
17
|
+
consider it better to just use one form field and process its content as JSON payload.
|
|
18
|
+
|
|
19
|
+
If a form field model inherits from this class, we will get API documentation and input
|
|
20
|
+
validation - just the way we get it for JSON body defined with `BaseModel`.
|
|
21
|
+
"""
|
|
22
|
+
@model_validator(mode='before')
|
|
23
|
+
@classmethod
|
|
24
|
+
def validate_to_json(cls, value: Any) -> Any:
|
|
25
|
+
if isinstance(value, str):
|
|
26
|
+
return cls(**json.loads(value))
|
|
27
|
+
return value
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
from pydantic import BaseModel
|
|
2
|
-
|
|
3
1
|
from typing import Generic, TypeVar
|
|
4
|
-
|
|
5
2
|
from pydantic import BaseModel
|
|
6
|
-
from pydantic
|
|
7
|
-
|
|
3
|
+
from pydantic import BaseModel
|
|
8
4
|
from sharedkernel.enum.error_code import ErrorCode
|
|
9
5
|
|
|
10
6
|
ResultT = TypeVar("ResultT")
|
|
@@ -13,16 +9,16 @@ ResultT = TypeVar("ResultT")
|
|
|
13
9
|
class BaseResult(BaseModel):
|
|
14
10
|
isSucceed:bool = True
|
|
15
11
|
message: str = ErrorCode.Success.value
|
|
16
|
-
errorCode: str = None
|
|
12
|
+
errorCode: str | None = None
|
|
17
13
|
|
|
18
|
-
class Result(BaseResult,
|
|
19
|
-
data: ResultT =None
|
|
14
|
+
class Result(BaseResult, Generic[ResultT]):
|
|
15
|
+
data: ResultT = None
|
|
20
16
|
|
|
21
17
|
def __init__(
|
|
22
18
|
self,
|
|
23
19
|
isSucceed:bool = True,
|
|
24
|
-
data: object = None,
|
|
20
|
+
data: object | None = None,
|
|
25
21
|
message: str = ErrorCode.Success.value,
|
|
26
|
-
errorCode: str = None
|
|
22
|
+
errorCode: str | None = None
|
|
27
23
|
)-> None:
|
|
28
|
-
super().__init__(isSucceed=
|
|
24
|
+
super().__init__(isSucceed=isSucceed, data=data, message=message, errorCode=errorCode)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: sharedkernel
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0
|
|
4
4
|
Summary: sharekernel is a shared package between all python projects
|
|
5
5
|
Author: Smilinno
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
@@ -9,7 +9,6 @@ Requires-Dist: requests
|
|
|
9
9
|
Requires-Dist: pymongo
|
|
10
10
|
Requires-Dist: fastapi==0.111.0
|
|
11
11
|
Requires-Dist: PyJWT
|
|
12
|
-
Requires-Dist: chromadb
|
|
13
12
|
Requires-Dist: persian_tools
|
|
14
13
|
Requires-Dist: sentry-sdk
|
|
15
14
|
Requires-Dist: jdatetime
|
|
@@ -24,6 +23,10 @@ Requires-Dist: beautifulsoup4
|
|
|
24
23
|
this a shared kernel package
|
|
25
24
|
|
|
26
25
|
# Change Log
|
|
26
|
+
### Version 2.0.0
|
|
27
|
+
- Update pydantic version
|
|
28
|
+
- Delete vector databases
|
|
29
|
+
- Implement JsonStringModel
|
|
27
30
|
### Version 1.9.0
|
|
28
31
|
- Implement DataFormatConverter
|
|
29
32
|
### Version 1.8.0
|
|
@@ -14,13 +14,8 @@ sharedkernel.egg-info/requires.txt
|
|
|
14
14
|
sharedkernel.egg-info/top_level.txt
|
|
15
15
|
sharedkernel/database/__init__.py
|
|
16
16
|
sharedkernel/database/mongo_generic_repository.py
|
|
17
|
-
sharedkernel/database/vector_database_repository/__init__.py
|
|
18
|
-
sharedkernel/database/vector_database_repository/chroma_startegy.py
|
|
19
|
-
sharedkernel/database/vector_database_repository/vector_database_repository.py
|
|
20
|
-
sharedkernel/database/vector_database_repository/vector_database_strategy.py
|
|
21
17
|
sharedkernel/enum/__init__.py
|
|
22
18
|
sharedkernel/enum/error_code.py
|
|
23
|
-
sharedkernel/enum/vector_database_type.py
|
|
24
19
|
sharedkernel/exception/__init__.py
|
|
25
20
|
sharedkernel/exception/exception.py
|
|
26
21
|
sharedkernel/exception/exception_handlers.py
|
|
@@ -29,5 +24,6 @@ sharedkernel/normalizer/number_normalizer.py
|
|
|
29
24
|
sharedkernel/normalizer/phone_number_normalizer.py
|
|
30
25
|
sharedkernel/objects/__init__.py
|
|
31
26
|
sharedkernel/objects/base_document.py
|
|
27
|
+
sharedkernel/objects/json_string_model.py
|
|
32
28
|
sharedkernel/objects/jwt_model.py
|
|
33
29
|
sharedkernel/objects/result.py
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import chromadb
|
|
2
|
-
import numpy as np
|
|
3
|
-
from chromadb.config import Settings
|
|
4
|
-
from .vector_database_strategy import VectorDatabaseStrategy
|
|
5
|
-
import uuid
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class ChromaStrategy(VectorDatabaseStrategy):
|
|
9
|
-
def __init__(self, collection_name: str):
|
|
10
|
-
self.collection_name = collection_name
|
|
11
|
-
self.collection = None
|
|
12
|
-
|
|
13
|
-
def connect(self, host: str = "localhost", port: int = 8000):
|
|
14
|
-
client = chromadb.Client(
|
|
15
|
-
Settings(
|
|
16
|
-
chroma_api_impl="rest",
|
|
17
|
-
chroma_server_host=host,
|
|
18
|
-
chroma_server_http_port=port,
|
|
19
|
-
)
|
|
20
|
-
)
|
|
21
|
-
self.collection = client.get_or_create_collection(self.collection_name)
|
|
22
|
-
|
|
23
|
-
def insert_vector(self, vector: np.ndarray, metadata: dict) -> str:
|
|
24
|
-
id = str(uuid.uuid4())
|
|
25
|
-
self.collection.upsert(ids=id, embeddings=vector.tolist(), metadatas=[metadata])
|
|
26
|
-
|
|
27
|
-
return id
|
|
28
|
-
|
|
29
|
-
def search_vector(self, vector: np.ndarray, top_k: int):
|
|
30
|
-
results = self.collection.query(vectors=[vector.tolist()], n_results=top_k)
|
|
31
|
-
return results
|
|
32
|
-
|
|
33
|
-
def get_vector_by_id(self, id: str):
|
|
34
|
-
result = self.collection.get(ids=id)
|
|
35
|
-
|
|
36
|
-
return result
|
|
37
|
-
|
|
38
|
-
def delete_vector(self, id: str):
|
|
39
|
-
self.collection.delete(ids=id)
|
sharedkernel-1.9.0/sharedkernel/database/vector_database_repository/vector_database_repository.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from .vector_database_strategy import VectorDatabaseStrategy
|
|
3
|
-
# from .milvus_strategy import MilvusStrategy
|
|
4
|
-
from .chroma_startegy import ChromaStrategy
|
|
5
|
-
from sharedkernel.enum.vector_database_type import VectorDatabaseType
|
|
6
|
-
|
|
7
|
-
class VectorRepository:
|
|
8
|
-
def __init__(self, database_type: VectorDatabaseType, collection_name: str, **connection_params):
|
|
9
|
-
self.strategy = self._get_strategy(database_type, collection_name)
|
|
10
|
-
self.strategy.connect(**connection_params)
|
|
11
|
-
|
|
12
|
-
def _get_strategy(self, database_type: VectorDatabaseType, collection_name: str) -> VectorDatabaseStrategy:
|
|
13
|
-
# if database_type == VectorDatabaseType.MILVUS:
|
|
14
|
-
# return MilvusStrategy(collection_name)
|
|
15
|
-
# else:
|
|
16
|
-
return ChromaStrategy(collection_name)
|
|
17
|
-
|
|
18
|
-
def add_vector(self, vector: np.ndarray, metadata: dict) -> str:
|
|
19
|
-
return self.strategy.insert_vector(vector, metadata)
|
|
20
|
-
|
|
21
|
-
def find_similar_vectors(self, vector: np.ndarray, top_k: int):
|
|
22
|
-
return self.strategy.search_vector(vector, top_k)
|
|
23
|
-
|
|
24
|
-
def remove_vector(self, id: str):
|
|
25
|
-
self.strategy.delete_vector(id)
|
|
26
|
-
|
|
27
|
-
def get_vector_by_id(self, id: str):
|
|
28
|
-
return self.strategy.get_vector_by_id(id)
|
sharedkernel-1.9.0/sharedkernel/database/vector_database_repository/vector_database_strategy.py
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
from abc import ABC, abstractmethod
|
|
2
|
-
import numpy as np
|
|
3
|
-
|
|
4
|
-
class VectorDatabaseStrategy(ABC):
|
|
5
|
-
@abstractmethod
|
|
6
|
-
def connect(self, **kwargs):
|
|
7
|
-
pass
|
|
8
|
-
@abstractmethod
|
|
9
|
-
def insert_vector(self, vector: np.ndarray, metadata: dict) -> str:
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
@abstractmethod
|
|
13
|
-
def search_vector(self, vector: np.ndarray, top_k: int):
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
@abstractmethod
|
|
17
|
-
def delete_vector(self, id: str):
|
|
18
|
-
pass
|
|
19
|
-
|
|
20
|
-
@abstractmethod
|
|
21
|
-
def get_vector_by_id(self, id: str):
|
|
22
|
-
pass
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
|
-
|
|
3
|
-
class ErrorCode(str, Enum):
|
|
4
|
-
Item_NotFound= "یافت نشد"
|
|
5
|
-
|
|
6
|
-
Internal_Server= "خطایی در سیستم رخ داده است"
|
|
7
|
-
|
|
8
|
-
UnAuthorized= "توکن دسترسی معتبر نمی باشد"
|
|
9
|
-
|
|
10
|
-
Success= "با موفقیت انجام شد"
|
|
11
|
-
|
|
12
|
-
Intents_Count_Should_Equal_One= "فقط یک اینتنت میتوانید وارد نمایید"
|
|
13
|
-
|
|
14
|
-
Unsupported_Date_Type = "تاریخ داده شده پیشتیبانی نمیشود."
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sharedkernel-1.9.0 → sharedkernel-2.0.0}/sharedkernel/normalizer/phone_number_normalizer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|