Refactor: Extract AbstractObservableChatModel to centralize all chat models' common logic #4689
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.
When reviewing #4649, I found that the issue isn’t limited to DeepSeek and all other models have similar logic for observation, retry, return directly and tool calling. So the best solution would be to refactor all the chat model code to centralize the common logic. That way, we can avoid having to make the same change in multiple places (10+ models mean 10+ * work load), and it will also make future maintenance easier across all models.
BTW, since this is a change which could easily conflict with other ongoing work (though it’s low risk due to method extracting only), and I’m not sure about the community’s thoughts on it, I only applied the refactor to two models for now to get feedback. If this approach looks good and gets reviewed, I can go ahead and update the rest of the models in some more separate PRs.
Thanks for reviewing!