Skip to main content
Databricks Lakehouse Platform unifies data, analytics, and AI on one platform.
本指南提供了开始使用 Databricks LLM models. 有关所有 功能和配置的详细文档,请前往 API reference.

概述

Databricks LLM class wraps a completion endpoint hosted as either of these two endpoint types:
  • Databricks Model Serving, recommended for production and development,
  • Cluster driver proxy app, recommended for interactive development.
This example notebook shows how to wrap your LLM endpoint and use it as an LLM in your LangChain application.

Limitations

The Databricks LLM class is legacy implementation and has several limitations in the feature compatibility.
  • Only supports synchronous invocation. Streaming or async APIs are not supported.
  • batch API is not supported.
To use those features, please use the new ChatDatabricks class instead. ChatDatabricks supports all APIs of ChatModel including streaming, async, batch, etc.

设置

要访问 Databricks 模型,您需要创建一个 Databricks account, set up credentials (only if you are outside Databricks workspace), and install required packages.

Credentials (only if you are outside databricks)

If you are running LangChain app inside Databricks, you can skip this step. Otherwise, you need manually set the Databricks workspace hostname and personal access token to DATABRICKS_HOST and DATABRICKS_TOKEN environment variables, respectively. See Authentication Documentation for how to get an access token.
Alternatively, you can pass those parameters when initializing the Databricks class.

安装

LangChain 的 Databricks 集成位于 langchain-community package. Also, mlflow >= 2.9 is required to run the code in this notebook.

Wrapping model serving endpoint

Prerequisites

The expected MLflow model signature is:
  • inputs: [{"name": "prompt", "type": "string"}, {"name": "stop", "type": "list[string]"}]
  • outputs: [{"type": "string"}]

调用

Transform input and output

Sometimes you may want to wrap a serving endpoint that has incompatible model signature or you want to insert extra configs. You can use the transform_input_fn and transform_output_fn arguments to define additional pre/post process.