(fix) improve batch_completion_models + multiple deployments, if 1 model fails, return result from 2nd

This commit is contained in:
ishaan-jaff 2023-10-30 17:19:50 -07:00
parent 9b84a4c8bd
commit 9f72ce9fc6

View file

@ -1441,10 +1441,33 @@ def batch_completion_models(*args, **kwargs):
kwargs = {**deployment, **nested_kwargs}
futures[deployment["model"]] = executor.submit(completion, **kwargs)
done, not_done = concurrent.futures.wait(futures.values(), return_when=concurrent.futures.FIRST_COMPLETED)
while futures:
# wait for the first returned future
print_verbose("\n\n waiting for next result\n\n")
done, _ = concurrent.futures.wait(futures.values(), return_when=concurrent.futures.FIRST_COMPLETED)
print_verbose(f"done list\n{done}")
for future in done:
try:
result = future.result()
return result
except Exception as e:
# if model 1 fails, continue with response from model 2, model3
print_verbose(f"\n\ngot an exception, ignoring, removing from futures")
print_verbose(futures)
new_futures = {}
for key, value in futures.items():
if future == value:
print_verbose(f"removing key{key}")
continue
else:
new_futures[key] = value
futures = new_futures
print_verbose(f"new futures{futures}")
continue
for future in done:
return future.result()
print_verbose("\n\ndone looping through futures\n\n")
print_verbose(futures)
return None # If no response is received from any model