Databricks
Databricks
Databricks LLM API와 통합해요.
출처: 문서
본문
사전 준비사항 (Pre-requisites)
- Databricks 모델 서빙 엔드포인트를 쿼리하고 접근하기 위한 Databricks 개인 액세스 토큰.
- Foundation Model APIs pay-per-token을 위한 지원 지역의 Databricks workspace.
설정 (Setup)
Colab에서 이 노트북을 여는 경우라면 LlamaIndex 🦙 설치가 필요할 거예요.
% pip install llama-index-llms-databricks
!pip install llama-index
from llama_index.llms.databricks import Databricks
None 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.
Terminal window
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)
메시지 목록으로 chat 호출
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)
스트리밍 (Streaming)
stream_complete 엔드포인트 사용
response = llm.stream_complete("Explain the importance of open source LLMs")
for r in response:
print(r.delta, end="")
stream_chat 엔드포인트 사용
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="")