Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude max_tokens from request if it's None #14334

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libs/langchain/langchain/chat_models/mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ def _generate(
"messages": message_dicts,
"temperature": self.temperature,
"n": self.n,
"stop": stop or self.stop,
"max_tokens": self.max_tokens,
**self.extra_params,
**kwargs,
}
if stop := self.stop or stop:
data["stop"] = stop
if self.max_tokens is not None:
data["max_tokens"] = self.max_tokens
resp = self._client.predict(endpoint=self.endpoint, inputs=data)
return ChatMlflow._create_chat_result(resp)

Expand Down
15 changes: 7 additions & 8 deletions libs/langchain/langchain/llms/databricks.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,14 @@ class Config:

@property
def _llm_params(self) -> Dict[str, Any]:
params = {
params: Dict[str, Any] = {
"temperature": self.temperature,
"n": self.n,
"stop": self.stop,
"max_tokens": self.max_tokens,
**(self.model_kwargs or self.extra_params),
}
if self.stop:
params["stop"] = self.stop
if self.max_tokens is not None:
params["max_tokens"] = self.max_tokens
return params

@validator("cluster_id", always=True)
Expand Down Expand Up @@ -457,11 +458,9 @@ def _call(
request: Dict[str, Any] = {"prompt": prompt}
if self._client.llm:
request.update(self._llm_params)
request.update(self.model_kwargs or self.extra_params)
else:
request.update(self.model_kwargs or self.extra_params)
request.update(self.model_kwargs or self.extra_params)
request.update(kwargs)
if stop := self.stop or stop:
if stop:
request["stop"] = stop

if self.transform_input_fn:
Expand Down
4 changes: 3 additions & 1 deletion libs/langchain/langchain/llms/mlflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ def _call(
"prompt": prompt,
"temperature": self.temperature,
"n": self.n,
"max_tokens": self.max_tokens,
**self.extra_params,
**kwargs,
}
if stop := self.stop or stop:
data["stop"] = stop
if self.max_tokens is not None:
data["max_tokens"] = self.max_tokens

resp = self._client.predict(endpoint=self.endpoint, inputs=data)
return resp["choices"][0]["text"]

Expand Down
Loading