Skip to content

Commit bd7a781

Browse files
committed
Support using client_params for LangChain client initialization.
1 parent 3aeee27 commit bd7a781

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

ads/llm/autogen/client_v02.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ class LangChainModelClient(ModelClient):
8888
def __init__(self, config: dict, **kwargs) -> None:
8989
super().__init__()
9090
logger.info("LangChain model client config: %s", str(config))
91-
# Make a copy of the config since we are popping the keys
91+
# Make a copy of the config since we are popping some keys
9292
config = copy.deepcopy(config)
93+
# model_client_cls will always be LangChainModelClient
9394
self.client_class = config.pop("model_client_cls")
9495

95-
self.function_call_params = config.pop("function_call_params", {})
96+
# model_name is used in constructing the response.
97+
self.model_name = config.get("model", "")
9698

97-
self.model_name = config.get("model")
99+
# If the config specified function_call_params,
100+
# Pop the params and use them only for tool calling.
101+
self.function_call_params = config.pop("function_call_params", {})
98102

99103
# Import the LangChain class
100104
if "langchain_cls" not in config:
@@ -104,8 +108,13 @@ def __init__(self, config: dict, **kwargs) -> None:
104108
langchain_module = importlib.import_module(module_name)
105109
langchain_cls = getattr(langchain_module, cls_name)
106110

111+
# If the config specified client_params,
112+
# Only use the client_params to initialize the LangChain model.
113+
# Otherwise, use the config
114+
self.client_params = config.get("client_params", config)
115+
107116
# Initialize the LangChain client
108-
self.model = langchain_cls(**config)
117+
self.model = langchain_cls(**self.client_params)
109118

110119
def create(self, params) -> ModelClient.ModelClientResponseProtocol:
111120
"""Creates a LLM completion for a given config.

0 commit comments

Comments
 (0)