feat 新增 process lookbooks 接口
fix
This commit is contained in:
31
app/service/lookbooks/utils/openai_utils.py
Normal file
31
app/service/lookbooks/utils/openai_utils.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import time
|
||||
|
||||
|
||||
def wait_for_job_completion(client, batch_job_id, timeout=6000, interval=10):
|
||||
"""
|
||||
等待批处理作业完成。
|
||||
|
||||
参数:
|
||||
- client: 批处理作业客户端对象
|
||||
- batch_job_id: 批处理作业的ID
|
||||
- timeout: 最大等待时间(秒)
|
||||
- interval: 检查状态的间隔时间(秒)
|
||||
|
||||
返回:
|
||||
- True 如果作业完成,False 如果超时
|
||||
"""
|
||||
start_time = time.time()
|
||||
while time.time() - start_time < timeout:
|
||||
batch_job = client.batches.retrieve(batch_job_id)
|
||||
if batch_job.status == 'completed':
|
||||
print("Batch job completed successfully.")
|
||||
return True
|
||||
elif batch_job.status == 'failed':
|
||||
print("Batch job failed.")
|
||||
return False
|
||||
else:
|
||||
print(f"Current status: {batch_job.status}. Waiting for completion...")
|
||||
time.sleep(interval)
|
||||
|
||||
print("Timeout reached, job did not complete in time.")
|
||||
return False
|
||||
Reference in New Issue
Block a user