forked from phoenix/litellm-mirror
Add return_exceptions to batch_completion (retry)
This commit is contained in:
parent
fc63c3f555
commit
2713272bba
2 changed files with 47 additions and 2 deletions
|
@ -2166,7 +2166,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': {
|
||||
|
@ -2331,6 +2331,12 @@ def batch_completion(
|
|||
list: A list of completion results.
|
||||
"""
|
||||
args = locals()
|
||||
|
||||
# extra kw for dealing with exceptions
|
||||
return_exceptions = args.get("kwargs").get("return_exceptions", False)
|
||||
if "return_exceptions" in args.get("kwargs"):
|
||||
args.get("kwargs").pop("return_exceptions")
|
||||
|
||||
batch_messages = messages
|
||||
completions = []
|
||||
model = model
|
||||
|
@ -2384,7 +2390,16 @@ 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: # original
|
||||
results = [future.result() for future in completions]
|
||||
return results
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue