serenarolloh commited on
Commit
a4b8f28
·
verified ·
1 Parent(s): ea2e193

Update config.py

Browse files
Files changed (1) hide show
  1. config.py +4 -14
config.py CHANGED
@@ -20,24 +20,21 @@ class Settings(BaseSettings):
20
  shipper_id: str = Field(default="default_shipper")
21
 
22
  class Config:
23
- # This enables the automatic reloading of values when they change
24
  validate_assignment = True
25
 
26
  def __init__(self, **kwargs):
27
  super().__init__(**kwargs)
28
  self.set_model()
29
 
30
- # Function to dynamically select model and processor based on shipper_id
31
  def set_model(self):
32
- # IMPORTANT: Make sure model names are consistent!
33
- # Map can handle both string and integer keys by converting to string
34
  shipper_model_map = {
35
- # Group 1 models - using donut-v16
36
  "61": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"},
37
  "81": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"},
38
  "139": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"},
39
 
40
- # Group 2 models - using donut-v17
41
  "165": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"},
42
  "127": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"},
43
  "145": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"},
@@ -46,7 +43,6 @@ class Settings(BaseSettings):
46
  previous_model = self.model
47
  previous_processor = self.processor
48
 
49
- # Convert shipper_id to string to handle both numeric and string values
50
  shipper_id_str = str(self.shipper_id)
51
 
52
  config = shipper_model_map.get(
@@ -57,18 +53,12 @@ class Settings(BaseSettings):
57
  self.model = config["model"]
58
  self.processor = config["processor"]
59
 
60
- # Log changes for debugging
61
- logger.info(f"Shipper ID set to: {self.shipper_id}")
62
- logger.info(f"Changed model from {previous_model} to {self.model}")
63
- logger.info(f"Changed processor from {previous_processor} to {self.processor}")
64
-
65
  return self.model, self.processor
66
 
67
- # Create a single instance
68
  settings = Settings()
69
  logger.info(f"Initial model setup: {settings.model}")
70
 
71
- # Function to update shipper and trigger model change
72
  def update_shipper(new_shipper_id):
73
  """
74
  Update the shipper ID and change the model accordingly
 
20
  shipper_id: str = Field(default="default_shipper")
21
 
22
  class Config:
 
23
  validate_assignment = True
24
 
25
  def __init__(self, **kwargs):
26
  super().__init__(**kwargs)
27
  self.set_model()
28
 
29
+ # Dynamically select model and processor based on shipper_id
30
  def set_model(self):
 
 
31
  shipper_model_map = {
32
+ # Shippers using donut-v16
33
  "61": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"},
34
  "81": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"},
35
  "139": {"model": "senga-ml/donut-v16", "processor": "senga-ml/donut-v16"},
36
 
37
+ # Shippers using donut-v17
38
  "165": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"},
39
  "127": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"},
40
  "145": {"model": "senga-ml/donut-v17", "processor": "senga-ml/donut-v17"},
 
43
  previous_model = self.model
44
  previous_processor = self.processor
45
 
 
46
  shipper_id_str = str(self.shipper_id)
47
 
48
  config = shipper_model_map.get(
 
53
  self.model = config["model"]
54
  self.processor = config["processor"]
55
 
 
 
 
 
 
56
  return self.model, self.processor
57
 
 
58
  settings = Settings()
59
  logger.info(f"Initial model setup: {settings.model}")
60
 
61
+ # trigger model change
62
  def update_shipper(new_shipper_id):
63
  """
64
  Update the shipper ID and change the model accordingly