docs/examples/llm/databricks.ipynb
Integrate with Databricks LLMs APIs.
Databricks personal access token to query and access Databricks model serving endpoints.
Databricks workspace in a supported region for Foundation Model APIs pay-per-token.
If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙.
% pip install llama-index-llms-databricks
!pip install llama-index
from llama_index.llms.databricks import Databricks
export DATABRICKS_TOKEN=<your api key>
export DATABRICKS_SERVING_ENDPOINT=<your api serving endpoint>
Alternatively, you can pass your API key and serving endpoint to the LLM when you init it:
llm = Databricks(
model="databricks-dbrx-instruct",
api_key="your_api_key",
api_base="https://[your-work-space].cloud.databricks.com/serving-endpoints/",
)
A list of available LLM models can be found here.
response = llm.complete("Explain the importance of open source LLMs")
print(response)
chat with a list of messagesfrom llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.chat(messages)
print(resp)
Using stream_complete endpoint
response = llm.stream_complete("Explain the importance of open source LLMs")
for r in response:
print(r.delta, end="")
Using stream_chat endpoint
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system", content="You are a pirate with a colorful personality"
),
ChatMessage(role="user", content="What is your name"),
]
resp = llm.stream_chat(messages)
for r in resp:
print(r.delta, end="")