refactor(model): integrate ModelAPI into model proxy and service classes#36
Merged
refactor(model): integrate ModelAPI into model proxy and service classes#36
Conversation
This change introduces ModelAPI as a mixin to both ModelProxy and ModelService classes, consolidating common API functionality. The completions and responses methods have been removed from these classes as they are now inherited from ModelAPI, reducing code duplication and improving maintainability. The refactoring affects multiple files including __model_proxy_async_template.py, __model_service_async_template.py, model_proxy.py, and model_service.py, along with the new model_api.py module definition. Two new files were created: agentrun/model/api/model_api.py which defines the ModelAPI base class, and examples/embedding.py which provides usage examples for embedding functionality. // 此更改将ModelAPI作为mixin引入到ModelProxy和ModelService类中, 整合了通用的API功能。completions和responses方法已从这些类中移除, 因为它们现在继承自ModelAPI,减少了代码重复并提高了可维护性。 重构影响了多个文件,包括__model_proxy_async_template.py、 __model_service_async_template.py、model_proxy.py和model_service.py, 以及新的model_api.py模块定义。 创建了两个新文件:agentrun/model/api/model_api.py定义了ModelAPI基类, examples/embedding.py提供了嵌入功能的使用示例。 Change-Id: I81045039bef65df9d7daab6a56ff2e1442fddcb7 Signed-off-by: OhYee <oyohyee@oyohyee.com>
…ters Update the unit tests for ModelProxy completions and responses methods to properly mock litellm functions instead of mocking the data client completions/responses methods. Also correct the test_responses method to pass the correct 'input' parameter instead of 'messages'. The changes ensure that the tests accurately reflect how the ModelProxy interacts with the underlying litellm API while maintaining proper mocking behavior. 更新 ModelProxy 测试以使用正确的模拟和参数 更新 ModelProxy 完成和响应方法的单元测试,以正确模拟 litellm 函数, 而不是模拟数据客户端的完成/响应方法。同时修正 test_responses 方法, 传递正确的 'input' 参数而不是 'messages'。 这些更改确保测试准确反映 ModelProxy 如何与底层 litellm API 交互, 同时保持适当的模拟行为。 Change-Id: I5fffbf165d23efa7607c2618b1fd9604df3caeb6 Signed-off-by: OhYee <oyohyee@oyohyee.com>
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.
This change introduces ModelAPI as a mixin to both ModelProxy and ModelService classes, consolidating common API functionality. The completions and responses methods have been removed from these classes as they are now inherited from ModelAPI, reducing code duplication and improving maintainability.
The refactoring affects multiple files including __model_proxy_async_template.py, __model_service_async_template.py, model_proxy.py, and model_service.py, along with the new model_api.py module definition.
Two new files were created: agentrun/model/api/model_api.py which defines the ModelAPI base class, and examples/embedding.py which provides usage examples for embedding functionality.
//
此更改将ModelAPI作为mixin引入到ModelProxy和ModelService类中,
整合了通用的API功能。completions和responses方法已从这些类中移除,
因为它们现在继承自ModelAPI,减少了代码重复并提高了可维护性。
重构影响了多个文件,包括__model_proxy_async_template.py、
__model_service_async_template.py、model_proxy.py和model_service.py, 以及新的model_api.py模块定义。
创建了两个新文件:agentrun/model/api/model_api.py定义了ModelAPI基类, examples/embedding.py提供了嵌入功能的使用示例。
Change-Id: I81045039bef65df9d7daab6a56ff2e1442fddcb7
Fix bugs
Bug detail
Pull request tasks
Update docs
Reason for update
Pull request tasks
Add contributor
Contributed content
Content detail
Others
Reason for update