Merge pull request #306 from syn-nick/develop

Handle empty finish_reason
This commit is contained in:
Alex O'Connell
2025-10-23 21:20:18 -04:00
committed by GitHub

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}")