handle empty finish_reason

This commit is contained in:
syn-nick
2025-10-22 11:19:30 +02:00
committed by GitHub
parent 99aea64f57
commit 089aa8cff0

View File

@@ -217,8 +217,9 @@ class GenericOpenAIAPIClient(LocalLLMClient):
response_text = choice["text"]
streamed = False
if not streamed or streamed and choice["finish_reason"]:
if choice["finish_reason"] == "length" or choice["finish_reason"] == "content_filter":
if not streamed or (streamed and choice.get("finish_reason")):
finish_reason = choice.get("finish_reason")
if finish_reason in ("length", "content_filter"):
_LOGGER.warning("Model response did not end on a stop token (unfinished sentence)")
return response_text, tool_calls
@@ -405,4 +406,4 @@ class GenericOpenAIResponsesAPIClient(LocalLLMClient):
_LOGGER.debug(f"Err was: {err}")
_LOGGER.debug(f"Request was: {request_params}")
_LOGGER.debug(f"Result was: {response}")
return TextGenerationResult(raise_error=True, error_msg=f"Failed to communicate with the API! {err}")
return TextGenerationResult(raise_error=True, error_msg=f"Failed to communicate with the API! {err}")