数据砖块
与 Databricks LLMs API 集成。
-
Databricks 个人访问令牌用于查询和访问 Databricks 模型服务端点。
-
Databricks 工作区位于支持区域内,用于按令牌付费的基础模型 API。
如果您在 Colab 上打开这个笔记本,您可能需要安装 LlamaIndex 🦙。
% pip install llama-index-llms-databricks!pip install llama-indexfrom llama_index.llms.databricks import DatabricksNone of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.export DATABRICKS_TOKEN=<your api key>export DATABRICKS_SERVING_ENDPOINT=<your api serving endpoint>或者,您可以在初始化LLM时传递您的API密钥和服务端点:
llm = Databricks( model="databricks-dbrx-instruct", api_key="your_api_key", api_base="https://[your-work-space].cloud.databricks.com/serving-endpoints/",)可用的LLM模型列表可在此处找到。
response = llm.complete("Explain the importance of open source LLMs")print(response)Call chat with a list of messages
Section titled “Call chat with a list of messages”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.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="")