fix(llms): accept and forward **kwargs in Together/LangChain/Sarvam providers (#5556)

This commit is contained in:
Yash Singh
2026-06-15 12:23:04 +05:30
committed by GitHub
parent a1eefc31bc
commit 66901d7393
6 changed files with 92 additions and 2 deletions
+4 -1
View File
@@ -57,6 +57,7 @@ class LangchainLLM(LLMBase):
response_format=None,
tools: Optional[List[Dict]] = None,
tool_choice: str = "auto",
**kwargs,
):
"""
Generate a response based on the given messages using langchain_community.
@@ -66,6 +67,8 @@ class LangchainLLM(LLMBase):
response_format (str or object, optional): Format of the response. Not used in Langchain.
tools (list, optional): List of tools that the model can call.
tool_choice (str, optional): Tool choice method.
**kwargs: Additional model parameters forwarded to the underlying LangChain
model's ``invoke`` (matches the ``LLMBase.generate_response`` contract).
Returns:
str: The generated response.
@@ -90,5 +93,5 @@ class LangchainLLM(LLMBase):
if tools:
langchain_model = langchain_model.bind_tools(tools=tools, tool_choice=tool_choice)
response: AIMessage = langchain_model.invoke(langchain_messages)
response: AIMessage = langchain_model.invoke(langchain_messages, **kwargs)
return self._parse_response(response, tools)
+6 -1
View File
@@ -28,7 +28,7 @@ class SarvamLLM(LLMBase):
getattr(self.config, "sarvam_base_url", None) or os.getenv("SARVAM_API_BASE") or "https://api.sarvam.ai/v1"
)
def generate_response(self, messages: List[Dict[str, str]], response_format=None) -> str:
def generate_response(self, messages: List[Dict[str, str]], response_format=None, **kwargs) -> str:
"""
Generate a response based on the given messages using Sarvam-M.
@@ -36,6 +36,8 @@ class SarvamLLM(LLMBase):
messages (list): List of message dicts containing 'role' and 'content'.
response_format (str or object, optional): Format of the response.
Currently not used by Sarvam API.
**kwargs: Additional provider-specific parameters forwarded to the Sarvam
request payload (matches the ``LLMBase.generate_response`` contract).
Returns:
str: The generated response.
@@ -72,6 +74,9 @@ class SarvamLLM(LLMBase):
if param in self.config.model:
params[param] = self.config.model[param]
# Forward any per-call provider-specific parameters (LLMBase contract).
params.update(kwargs)
try:
response = requests.post(url, headers=headers, json=params, timeout=30)
response.raise_for_status()
+4
View File
@@ -58,6 +58,7 @@ class TogetherLLM(LLMBase):
response_format=None,
tools: Optional[List[Dict]] = None,
tool_choice: str = "auto",
**kwargs,
):
"""
Generate a response based on the given messages using TogetherAI.
@@ -67,6 +68,8 @@ class TogetherLLM(LLMBase):
response_format (str or object, optional): Format of the response. Defaults to "text".
tools (list, optional): List of tools that the model can call. Defaults to None.
tool_choice (str, optional): Tool choice method. Defaults to "auto".
**kwargs: Additional provider-specific parameters forwarded to the Together
client (matches the ``LLMBase.generate_response`` contract).
Returns:
str: The generated response.
@@ -78,6 +81,7 @@ class TogetherLLM(LLMBase):
"max_tokens": self.config.max_tokens,
"top_p": self.config.top_p,
}
params.update(kwargs)
if response_format:
params["response_format"] = response_format
if tools: # TODO: Remove tools if no issues found with new memory addition logic