Source code for langchain_community.chat_models.databricks
import logging
from urllib.parse import urlparse
from langchain_community.chat_models.mlflow import ChatMlflow
logger = logging.getLogger(__name__)
[docs]class ChatDatabricks(ChatMlflow):
"""`Databricks` 聊天模型 API。
要使用,您应该已安装 ``mlflow`` python 包。
有关更多信息,请参阅 https://mlflow.org/docs/latest/llms/deployments。
示例:
.. code-block:: python
from langchain_community.chat_models import ChatDatabricks
chat_model = ChatDatabricks(
target_uri="databricks",
endpoint="databricks-llama-2-70b-chat",
temperature=0.1,
)
# 单个输入调用
print(chat_model.invoke("What is MLflow?").content)
# 带有流式响应的单个输入调用
for chunk in chat_model.stream("What is MLflow?"):
print(chunk.content, end="|")"""
target_uri: str = "databricks"
"""要使用的目标URI。默认为“databricks”。"""
@property
def _llm_type(self) -> str:
"""聊天模型的返回类型。"""
return "databricks-chat"
@property
def _mlflow_extras(self) -> str:
return ""
def _validate_uri(self) -> None:
if self.target_uri == "databricks":
return
if urlparse(self.target_uri).scheme != "databricks":
raise ValueError(
"Invalid target URI. The target URI must be a valid databricks URI."
)