Skip to content

Commit 34adab5

Browse files
committed
feat(model): support specific model parameter in CommonModel
Add specific_model parameter to CommonModel class and implement logic to handle string input for model function. The changes allow specifying a particular model when creating CommonModel instances and ensure the specific model is used when available. The model function now properly handles string inputs by converting them to appropriate model objects through ModelClient, and includes the specific_model in the returned CommonModel instance. fixes issue with model selection when using string-based model references feat(model): 在 CommonModel 中支持 specific model 参数 向 CommonModel 类添加 specific_model 参数并实现处理模型函数的字符串输入的逻辑。这些更改允许在创建 CommonModel 实例时指定特定模型,并确保在可用时使用特定模型。 模型函数现在通过 ModelClient 正确处理字符串输入并将它们转换为适当的模型对象,并在返回的 CommonModel 实例中包含 specific_model。 解决了使用基于字符串的模型引用时的模型选择问题 Change-Id: Ic4c853923510fe28eac7b5b84242e3be23474fa8 Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent f377b0d commit 34adab5

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

agentrun/integration/builtin/model.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,29 +69,27 @@ def model(
6969
backend_type = kwargs.get("backend_type")
7070
model = kwargs.get("model")
7171

72+
if isinstance(input, str):
73+
from agentrun.model.client import ModelClient
74+
75+
client = ModelClient(config=config)
76+
input = client.get(name=input, backend_type=backend_type, config=config)
77+
7278
if isinstance(input, ModelProxy):
7379
return CommonModel(
7480
model=model or "",
7581
model_obj=input,
7682
backend_type=BackendType.PROXY,
83+
specific_model=model,
7784
config=config,
7885
)
7986
elif isinstance(input, ModelService):
8087
return CommonModel(
8188
model=model or "",
8289
model_obj=input,
8390
backend_type=BackendType.SERVICE,
91+
specific_model=model,
8492
config=config,
8593
)
86-
87-
from agentrun.model.client import ModelClient
88-
89-
client = ModelClient(config=config)
90-
model_obj = client.get(name=input, backend_type=backend_type, config=config)
91-
92-
return CommonModel(
93-
model=input,
94-
model_obj=model_obj,
95-
backend_type=backend_type,
96-
config=config,
97-
)
94+
else:
95+
raise TypeError("input must be str, ModelProxy or ModelService")

agentrun/integration/utils/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ def __init__(
2222
model: Optional[str],
2323
model_obj: Union[ModelService, ModelProxy],
2424
backend_type: Optional[BackendType] = None,
25+
specific_model: Optional[str] = None,
2526
config: Optional[Config] = None,
2627
):
2728
self.model = model
2829
self.model_obj = model_obj
2930
self.backend_type = backend_type
31+
self.specific_model = specific_model
3032
self.config = config or Config()
3133

3234
def completions(self, *args, **kwargs):
@@ -40,7 +42,10 @@ def responses(self, *args, **kwargs):
4042
def get_model_info(self, config: Optional[Config] = None):
4143
"""获取模型信息"""
4244
cfg = Config.with_configs(self.config, config)
43-
return self.model_obj.model_info(config=cfg)
45+
info = self.model_obj.model_info(config=cfg)
46+
if self.specific_model:
47+
info.model = self.specific_model
48+
return info
4449

4550
def __convert_model(self, adapter_name: str):
4651
try:

0 commit comments

Comments
 (0)