folder-classifier 0.3.3__tar.gz → 0.3.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: folder-classifier
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: Deploy folder classifier API to a Ray cluster
5
5
  Author: Crispin Almodovar
6
6
  Author-email:
@@ -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.logger.info(f"Initializing Folder Classifier model: {model_config}")
20
- model_handle = serve.get_deployment_handle(app_name=model_config.app_name, deployment_name=model_config.deployment)
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:
@@ -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, model_handle: DeploymentHandle):
86
+ def __init__(self, app_name: str, deployment: str, model: str):
85
87
  self.logger = logging.getLogger(__name__)
86
- self.model_handle = model_handle
87
- self.llm = AsyncOpenAI(base_url=OPENAI_BASE_URL, api_key=OPENAI_API_KEY)
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.llm.chat.completions.create(**chat_completion_request)
95
- content = response.choices[0].message.content
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
- @staticmethod
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": 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)}
@@ -5,6 +5,7 @@ from pydantic import BaseModel, Field, ConfigDict
5
5
  class ModelConfig(BaseModel):
6
6
  app_name: str
7
7
  deployment: str
8
+ model: str
8
9
 
9
10
 
10
11
  class AppConfig(BaseModel):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: folder-classifier
3
- Version: 0.3.3
3
+ Version: 0.3.4
4
4
  Summary: Deploy folder classifier API to a Ray cluster
5
5
  Author: Crispin Almodovar
6
6
  Author-email:
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = folder-classifier
3
- version = 0.3.3
3
+ version = 0.3.4
4
4
  author = Crispin Almodovar
5
5
  author_email =
6
6
  description = Deploy folder classifier API to a Ray cluster