.ipynb
.pdf
Databricks
 Contents 
Wrapping a serving endpoint
Wrapping a cluster driver proxy app
Databricks#
The Databricks Lakehouse Platform unifies data, analytics, and AI on one platform.
This example notebook shows how to wrap Databricks endpoints as LLMs in LangChain.
It supports two endpoint types:
Serving endpoint, recommended for production and development,
Cluster driver proxy app, recommended for iteractive development.
from langchain.llms import Databricks
Wrapping a serving endpoint#
Prerequisites:
An LLM was registered and deployed to a Databricks serving endpoint.
You have “Can Query” permission to the endpoint.
The expected MLflow model signature is:
inputs: [{"name": "prompt", "type": "string"}, {"name": "stop", "type": "list[string]"}]
outputs: [{"type": "string"}]
If the model signature is incompatible or you want to insert extra configs, you can set transform_input_fn and transform_output_fn accordingly.
# If running a Databricks notebook attached to an interactive cluster in "single user" 
# or "no isolation shared" mode, you only need to specify the endpoint name to create 
# a `Databricks` instance to query a serving endpoint in the same workspace.
llm = Databricks(endpoint_name="dolly")
llm("How are you?")
'I am happy to hear that you are in good health and as always, you are appreciated.'
llm("How are you?", stop=["."])
'Good'
# Otherwise, you can manually specify the Databricks workspace hostname and personal access token 
# or set `DATABRICKS_HOST` and `DATABRICKS_TOKEN` environment variables, respectively.
rtdocs_stable/api.python.langchain.com/en/stable/modules/models/llms/integrations/databricks.html