1
1
# inference/models/inference.py
2
+ from django .conf import settings
2
3
from django .db import models
3
4
from django .utils import timezone
4
5
@@ -119,11 +120,9 @@ def log_error_and_set_status_failed(self, error_msg: str) -> None:
119
120
self .completed_at = timezone .now ()
120
121
self .save (update_fields = ["error_message" , "status" , "completed_at" , "updated_at" ])
121
122
122
- def create_external_job (self , batch_data ) -> "ExternalJob" :
123
+ def _create_external_job (self , batch_data , api_client ) -> "ExternalJob" :
123
124
"""Create and submit an external job for a batch"""
124
125
try :
125
- api_client = InferenceAPIClient ()
126
-
127
126
# Submit batch to API using model version identifier
128
127
job_id = api_client .submit_batch (self .model_version .api_identifier , batch_data )
129
128
@@ -144,22 +143,22 @@ def create_external_job(self, batch_data) -> "ExternalJob":
144
143
self .log_error_and_set_status_failed (f"Failed to create external job: { str (e )} " )
145
144
return None
146
145
147
- def initiate (self ) -> None :
146
+ def initiate (self , inference_api_url = settings . INFERENCE_API_URL ) -> None :
148
147
"""Initialize job and create batches"""
149
148
try :
150
149
# Load model using the refactored API client
151
- api_client = InferenceAPIClient ()
150
+ api_client = InferenceAPIClient (inference_api_url = inference_api_url )
152
151
if not api_client .load_model (self .model_version .api_identifier ):
153
152
# TODO: should refactor to get an exact error out of the api client
154
153
self .log_error_and_set_status_failed ("Failed to load model" )
155
154
return
156
155
157
156
batch_processor = BatchProcessor ()
158
- urls = self .collection .curated_urls .all ()
157
+ urls = self .collection .dump_urls .all ()
159
158
created_batch = False
160
159
161
160
for batch in batch_processor .iter_url_batches (urls ):
162
- external_job = self .create_external_job (batch )
161
+ external_job = self ._create_external_job (batch , api_client )
163
162
if external_job :
164
163
created_batch = True
165
164
else :
0 commit comments