mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
Add return_exceptions to litellm.batch_completion for optionally returing exceptions and partial resuslt instead of throwing exceptions
This commit is contained in:
parent
caf19478af
commit
64d229caaa
1 changed files with 12 additions and 1 deletions
|
@ -2303,6 +2303,7 @@ def batch_completion(
|
||||||
user (str, optional): The user string for generating completions. Defaults to "".
|
user (str, optional): The user string for generating completions. Defaults to "".
|
||||||
deployment_id (optional): The deployment ID for generating completions. Defaults to None.
|
deployment_id (optional): The deployment ID for generating completions. Defaults to None.
|
||||||
request_timeout (int, optional): The request timeout for generating completions. Defaults to None.
|
request_timeout (int, optional): The request timeout for generating completions. Defaults to None.
|
||||||
|
return_exceptions (bool): Whether to return exceptions and partial results when exceptions occur. Defaults to False.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list: A list of completion results.
|
list: A list of completion results.
|
||||||
|
@ -2361,7 +2362,17 @@ def batch_completion(
|
||||||
completions.append(future)
|
completions.append(future)
|
||||||
|
|
||||||
# Retrieve the results from the futures
|
# Retrieve the results from the futures
|
||||||
results = [future.result() for future in completions]
|
# results = [future.result() for future in completions]
|
||||||
|
if return_exceptions:
|
||||||
|
results = []
|
||||||
|
for future in completions:
|
||||||
|
try:
|
||||||
|
results.append(future.result())
|
||||||
|
except Exception as exc:
|
||||||
|
results.append(exc)
|
||||||
|
else:
|
||||||
|
results = [future.result() for future in completions]
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue