mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
(fix) improve batch_completion_models + multiple deployments, if 1 model fails, return result from 2nd
This commit is contained in:
parent
63310558a5
commit
85cd1faddd
1 changed files with 26 additions and 3 deletions
|
@ -1441,10 +1441,33 @@ def batch_completion_models(*args, **kwargs):
|
||||||
kwargs = {**deployment, **nested_kwargs}
|
kwargs = {**deployment, **nested_kwargs}
|
||||||
futures[deployment["model"]] = executor.submit(completion, **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
|
return None # If no response is received from any model
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue