folder-classifier 0.3.3__py3-none-any.whl → 0.3.4__py3-none-any.whl
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.
- folder_classifier/app.py +2 -4
- folder_classifier/classifier.py +10 -8
- folder_classifier/dto.py +1 -0
- {folder_classifier-0.3.3.dist-info → folder_classifier-0.3.4.dist-info}/METADATA +1 -1
- folder_classifier-0.3.4.dist-info/RECORD +10 -0
- folder_classifier-0.3.3.dist-info/RECORD +0 -10
- {folder_classifier-0.3.3.dist-info → folder_classifier-0.3.4.dist-info}/WHEEL +0 -0
- {folder_classifier-0.3.3.dist-info → folder_classifier-0.3.4.dist-info}/top_level.txt +0 -0
folder_classifier/app.py
CHANGED
@@ -16,10 +16,8 @@ class FolderClassifierAPI:
|
|
16
16
|
assert model_config.app_name and model_config.deployment, "Invalid ModelConfig values"
|
17
17
|
logging.basicConfig(level=logging.INFO)
|
18
18
|
self.logger = logging.getLogger(__name__)
|
19
|
-
self.
|
20
|
-
|
21
|
-
self.classifier = FolderClassifier(model_handle)
|
22
|
-
self.logger.info(f"Successfully initialized Folder Classifier API")
|
19
|
+
self.classifier = FolderClassifier(app_name=model_config.app_name, deployment=model_config.deployment, model=model_config.model)
|
20
|
+
self.logger.info(f"Successfully initialized Folder Classifier using config: {model_config}")
|
23
21
|
|
24
22
|
@web_api.post("/predict")
|
25
23
|
async def predict(self, request: FolderClassificationRequest) -> FolderClassificationResponse:
|
folder_classifier/classifier.py
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
import json
|
1
2
|
import logging
|
2
3
|
import os
|
3
4
|
from typing import Tuple, Dict, Any
|
4
5
|
|
6
|
+
from ray import serve
|
5
7
|
from ray.serve.handle import DeploymentHandle
|
6
8
|
|
7
9
|
from folder_classifier.dto import FolderClassificationRequest, FolderClassification
|
@@ -81,18 +83,19 @@ FOLDER_CLASSIFICATION_SCHEMA = FolderClassification.model_json_schema()
|
|
81
83
|
|
82
84
|
|
83
85
|
class FolderClassifier:
|
84
|
-
def __init__(self,
|
86
|
+
def __init__(self, app_name: str, deployment: str, model: str):
|
85
87
|
self.logger = logging.getLogger(__name__)
|
86
|
-
self.model_handle =
|
87
|
-
self.
|
88
|
+
self.model_handle = serve.get_deployment_handle(app_name=app_name, deployment_name=deployment)
|
89
|
+
self.model = model
|
88
90
|
self.logger.info(f"Successfully initialized FolderClassifier")
|
89
91
|
|
90
92
|
async def predict(self, request: FolderClassificationRequest) -> Tuple[str, str]:
|
91
93
|
content = ""
|
92
94
|
try:
|
93
95
|
chat_completion_request = self._to_chat_completion_request(request)
|
94
|
-
response = await self.
|
95
|
-
|
96
|
+
response = await self.model_handle.create_chat_completion_internal.remote(chat_completion_request)
|
97
|
+
response_dict = json.loads(response.body)
|
98
|
+
content = response_dict["choices"][0]["message"]["content"]
|
96
99
|
result = FolderClassification.model_validate_json(content)
|
97
100
|
except Exception as ex:
|
98
101
|
self.logger.error(f"Failed to parse response: {content}\n{ex}")
|
@@ -102,13 +105,12 @@ class FolderClassifier:
|
|
102
105
|
result = FolderClassification(category="other", reasoning="NA")
|
103
106
|
return result.category, result.reasoning
|
104
107
|
|
105
|
-
|
106
|
-
def _to_chat_completion_request(request: FolderClassificationRequest) -> Dict[str, Any]:
|
108
|
+
def _to_chat_completion_request(self, request: FolderClassificationRequest) -> Dict[str, Any]:
|
107
109
|
input_paths = request.items
|
108
110
|
folder = build_folder(input_paths)
|
109
111
|
folder_tree = render_tree(folder)
|
110
112
|
chat_completion_request = {
|
111
|
-
"model":
|
113
|
+
"model": self.model,
|
112
114
|
"messages": [
|
113
115
|
{"role": "system", "content": SYSTEM_PROMPT},
|
114
116
|
{"role": "user", "content": USER_PROMPT_TEMPLATE.replace("{folder_tree}", folder_tree)}
|
folder_classifier/dto.py
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
folder_classifier/__init__.py,sha256=k0YWZyUNe7myJiKeX0OaXtJ30_3EGE-vsZiAUbqa-3E,46
|
2
|
+
folder_classifier/app.py,sha256=_BUFSR7TJMoylrEwImDlln98C4BciPXoPqM6SQYkc1g,1255
|
3
|
+
folder_classifier/classifier.py,sha256=XTqCfUAc4-vX1bS4LixPFNMgvNNFX2mLdWXekHHB-fQ,8285
|
4
|
+
folder_classifier/deploy.py,sha256=06UAxz40IaP28e_RRohJoFwPUrWTaMquGbDylI-oHWA,424
|
5
|
+
folder_classifier/dto.py,sha256=KRHEfXKlsIYkBySwHOlo4k5Z4J_F3eR3PeEdUAwj8lI,819
|
6
|
+
folder_classifier/util.py,sha256=-Ptxkba5UzmhLrqoiiKZS3G56_cuAMkWlTyHcqdJkg0,3160
|
7
|
+
folder_classifier-0.3.4.dist-info/METADATA,sha256=YwlhWYE_vMFYfBb0lib6kHUGZjUyH3soNKQiJq0jVmY,392
|
8
|
+
folder_classifier-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
+
folder_classifier-0.3.4.dist-info/top_level.txt,sha256=36ugc9pEbNQ-mnzz4Ot2WVjY3t_LzAN6XOCjDFP4p4k,18
|
10
|
+
folder_classifier-0.3.4.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
folder_classifier/__init__.py,sha256=k0YWZyUNe7myJiKeX0OaXtJ30_3EGE-vsZiAUbqa-3E,46
|
2
|
-
folder_classifier/app.py,sha256=Xp3qkxQDWhFJKINMSMiDPtn1EEJrGm7XdTJAPZz6I4w,1358
|
3
|
-
folder_classifier/classifier.py,sha256=mBt6QvWIWiKdfwqRXog_p0nRqEnZ6mKwgGf8VADx930,8146
|
4
|
-
folder_classifier/deploy.py,sha256=06UAxz40IaP28e_RRohJoFwPUrWTaMquGbDylI-oHWA,424
|
5
|
-
folder_classifier/dto.py,sha256=bVai09FuPXktOo5Y_9dzXXj0ZvriDwZOho0ZYmWvc7E,803
|
6
|
-
folder_classifier/util.py,sha256=-Ptxkba5UzmhLrqoiiKZS3G56_cuAMkWlTyHcqdJkg0,3160
|
7
|
-
folder_classifier-0.3.3.dist-info/METADATA,sha256=Tj220ru3uyno5el6TPyEJ12ew8pDzzdA-hIHKkD7Y8Y,392
|
8
|
-
folder_classifier-0.3.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
9
|
-
folder_classifier-0.3.3.dist-info/top_level.txt,sha256=36ugc9pEbNQ-mnzz4Ot2WVjY3t_LzAN6XOCjDFP4p4k,18
|
10
|
-
folder_classifier-0.3.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|