fix: fix value error if model returns empty completion

This commit is contained in:
Krrish Dholakia 2023-10-10 10:11:21 -07:00
parent 6d81bcc248
commit af2fd0e0de
21 changed files with 84 additions and 50 deletions

View file

@ -152,9 +152,10 @@ def completion(
status_code=response.status_code,
)
else:
model_response["choices"][0]["message"]["content"] = completion_response[
"completion"
]
if len(completion_response["completion"]) > 0:
model_response["choices"][0]["message"]["content"] = completion_response[
"completion"
]
model_response.choices[0].finish_reason = completion_response["stop_reason"]
## CALCULATING USAGE
@ -162,7 +163,7 @@ def completion(
encoding.encode(prompt)
) ##[TODO] use the anthropic tokenizer here
completion_tokens = len(
encoding.encode(model_response["choices"][0]["message"]["content"])
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
) ##[TODO] use the anthropic tokenizer here
model_response["created"] = time.time()