Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -27,25 +27,13 @@ async def testv1(request: Request, background_tasks: BackgroundTasks):
|
|
27 |
body_data = await request.json()
|
28 |
|
29 |
print(body_data)
|
30 |
-
|
31 |
-
save_data = {
|
32 |
-
'batch_job_id': f"batch_{datetime.utcnow().strftime('%Y%m%d_%H%M%S')}",
|
33 |
-
"batch_job_status": False,
|
34 |
-
"created_at": datetime.utcnow().isoformat()
|
35 |
-
}
|
36 |
-
|
37 |
-
response = (
|
38 |
-
supabase.table("batch_processing_details")
|
39 |
-
.insert(save_data)
|
40 |
-
.execute()
|
41 |
-
)
|
42 |
|
43 |
# Add processing to background tasks
|
44 |
-
background_tasks.add_task(process_batch_job, body_data
|
45 |
|
46 |
return {'data': 'Batch job is scheduled!'}
|
47 |
|
48 |
-
# return {'data': 'Batch job is scheduled!', 'batch_job_id': save_data['batch_job_id']}
|
49 |
|
50 |
|
51 |
except Exception as e:
|
@@ -124,12 +112,12 @@ def adjust_prompt_tokens_v1(prompt: str) -> str:
|
|
124 |
return trimmed_text
|
125 |
|
126 |
|
127 |
-
async def process_batch_job(dataset: Dict[str, Any]
|
128 |
"""
|
129 |
Background task to process the batch job
|
130 |
"""
|
131 |
try:
|
132 |
-
|
133 |
|
134 |
openai_tasks = []
|
135 |
for ds in dataset.get('data'):
|
@@ -179,12 +167,11 @@ async def process_batch_job(dataset: Dict[str, Any], batch_job_id: str):
|
|
179 |
|
180 |
# Update status in Supabase
|
181 |
supabase.table("batch_processing_details").insert({
|
182 |
-
"batch_job_status":
|
183 |
"batch_job_id" : batch_job.id
|
184 |
}).execute()
|
185 |
|
186 |
-
|
187 |
-
|
188 |
except Exception as e:
|
189 |
logger.error(f"Error processing batch job {batch_job_id}: {str(e)}")
|
190 |
# Update status with error
|
|
|
27 |
body_data = await request.json()
|
28 |
|
29 |
print(body_data)
|
30 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Add processing to background tasks
|
33 |
+
background_tasks.add_task(process_batch_job, body_data)
|
34 |
|
35 |
return {'data': 'Batch job is scheduled!'}
|
36 |
|
|
|
37 |
|
38 |
|
39 |
except Exception as e:
|
|
|
112 |
return trimmed_text
|
113 |
|
114 |
|
115 |
+
async def process_batch_job(dataset: Dict[str, Any]):
|
116 |
"""
|
117 |
Background task to process the batch job
|
118 |
"""
|
119 |
try:
|
120 |
+
|
121 |
|
122 |
openai_tasks = []
|
123 |
for ds in dataset.get('data'):
|
|
|
167 |
|
168 |
# Update status in Supabase
|
169 |
supabase.table("batch_processing_details").insert({
|
170 |
+
"batch_job_status": False,
|
171 |
"batch_job_id" : batch_job.id
|
172 |
}).execute()
|
173 |
|
174 |
+
print("Batch sent for processing")
|
|
|
175 |
except Exception as e:
|
176 |
logger.error(f"Error processing batch job {batch_job_id}: {str(e)}")
|
177 |
# Update status with error
|