Repository navigation
Warn when model output stops at the token limit - #592
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
ae82317 to
3151906
Compare
A Gemini MAX_TOKENS or OpenAI length finish with non-empty text was passed through silently, so a truncated JSON response surfaced only as an opaque 'Unterminated string' ResolverParsingError (or was dropped without a trace under suppress_parse_errors). Log a warning naming the finish reason and the max_output_tokens and max_char_buffer knobs in the Gemini, Gemini batch and OpenAI providers. The output is still returned unchanged. Related to google#287
3151906 to
f233b03
Compare
|
Your branch is 1 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
|
Your branch is 8 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
# Conflicts: # tests/inference_test.py
…polish DAMP tests
aa2e702 to
9de5b6b
Compare
Description
Summary
finish_reason=MAX_TOKENS/ numeric2in Gemini, orfinish_reason=lengthin OpenAI) after emitting non-empty partial text, the truncated payload reachedResolversilently and surfaced only asResolverParsingError: Failed to parse JSON content: Unterminated string ...(or was dropped without explanation whensuppress_parse_errors=True).logging.warningnaming thefinish_reasonand pointing tomax_output_tokensandmax_char_bufferwhenever a non-empty response stops at the output token limit across:GeminiLanguageModel._response_to_scored_output(langextract/providers/gemini.py)_is_max_tokens_finishand_parse_batch_lineinlangextract/providers/gemini_batch.py, supporting string"MAX_TOKENS", numeric2, andFinishReason.MAX_TOKENSenum values while rejectingbool)OpenAILanguageModel._response_to_scored_output(langextract/providers/openai.py)_extract_text_from_response_bodyand_collect_outputs_from_jsonlinlangextract/providers/openai_batch.py, including the batch itemcustom_id)InferenceRuntimeErrorbehavior, downstreamResolverparsing, and public signatures unchanged.Fixes #287
Bug fix
How Has This Been Tested?
Tests
266 passedunder bothgoogle-genai==2.29.0andgoogle-genai==3.0.0):pytest tests/gemini_retry_test.py tests/test_gemini_batch_api.py tests/inference_test.py tests/openai_batch_test.py -q10.00/10on both source and test modules):isort --check-onlyandpyink --check --config pyproject.tomlon all modified filespylint --rcfile=.pylintrc langextract/providers/gemini.py langextract/providers/gemini_batch.py langextract/providers/openai.py langextract/providers/openai_batch.pypylint --rcfile=tests/.pylintrc tests/gemini_retry_test.py tests/test_gemini_batch_api.py tests/inference_test.py tests/openai_batch_test.py9de5b6bbcd722c23a3fea7dfd316fb69bacdce50: https://github.com/google/langextract/actions/runs/42734188186 (format-check, Python 3.10/3.11/3.12 unit + lint suites,ollama-integration-test, andplugin-integration-testpassed).9de5b6bbcd722c23a3fea7dfd316fb69bacdce50: https://github.com/google/langextract/actions/runs/42735393166 (12 passedlive Gemini and OpenAI tests;4 skippedopt-in Vertex AI Batch and live OpenAI Batch tests).Checklist
pylintover the affected code.