Merge pull request #3397 from ffreemt/main

Add return_exceptions to litellm.batch_completion
This commit is contained in:
Ishaan Jaff 2024-05-04 12:41:21 -07:00 committed by GitHub
commit 7094ac9557
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 45 additions and 2 deletions

View file

@ -2165,7 +2165,7 @@ def completion(
"""
assume input to custom LLM api bases follow this format:
resp = requests.post(
api_base,
api_base,
json={
'model': 'meta-llama/Llama-2-13b-hf', # model name
'params': {
@ -2302,6 +2302,7 @@ def batch_completion(
deployment_id=None,
request_timeout: Optional[int] = None,
timeout: Optional[int] = 600,
return_exceptions: bool = False,
# Optional liteLLM function params
**kwargs,
):
@ -2325,6 +2326,7 @@ def batch_completion(
user (str, optional): The user string for generating completions. Defaults to "".
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.
return_exceptions (bool): Whether to return exceptions and partial results when exceptions occur. Defaults to False.
Returns:
list: A list of completion results.
@ -2383,7 +2385,17 @@ def batch_completion(
completions.append(future)
# 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