Fix/fix finish reason in empty response - #290
Merged
Merged
Conversation
junya-takayama
left a comment
Collaborator
There was a problem hiding this comment.
今後ほかの種類のエラーに遭遇するかもしれないので、 finish_reason = "empty" とかがわかりやすいかも?と思いました
Contributor
Author
|
emptyに変更しました! |
junya-takayama
self-requested a review
July 16, 2026 07:07
junya-takayama
approved these changes
Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
LanguageModelで、APIリトライを使い果たした際のダミーレスポンス(empty_response)が、finish_reasonが"stop"になっており、正常応答と見分けがつかない形で下流に流れてしまっていた問題を修正OpenAICompletionAPIとOpenAIChatBatchAPIでは、上記に加えてダミーレスポンスの形が実際のレスポンス型と一致しておらず、失敗時にAttributeError/TypeErrorでクラッシュする経路も存在(by claude)変更
flexeval/core/language_model/openai_api.pyOpenAIChatAPI._batch_complete_text/_batch_generate_chat_response: 応答がself.empty_response(=リトライを使い果たした結果)の場合、finish_reasonを"error"にするよう変更OpenAICompletionAPI._batch_complete_text: 同様にfinish_reason="error"を設定empty_responseがchat API用の形(messageのみでtext属性を持たない)で構築されているため、そのままres.choices[0].textにアクセスするとAttributeErrorになっていたバグを修正OpenAIChatAPI._batch_compute_chat_log_probs:empty_responseはlogprobs=Noneのまま構築されているため、res.choices[0].logprobs.content[0]でAttributeErrorになっていたバグを修正。flexeval/core/language_model/openai_batch_api.pyOpenAIChatBatchAPI._batch_complete_text/_batch_generate_chat_response: Batch APIでリクエストが失敗した項目は""(空文字列)のまま残る実装になっており、res["choices"]でインデックスアクセスするとTypeError: string indices must be integersになっていたバグを修正。isinstance(res, str)で失敗分を判定し、LMOutput(text="", finish_reason="error")を返すよう変更OpenAIChatBatchAPI._batch_compute_chat_log_probs: 同様に失敗分("")へのインデックスアクセスによるTypeErrorを修正し、log_prob=Noneにフォールバックするよう変更