OctoAI
OctoAI
OctoAI LLM을 LlamaIndex에서 바로 사용할 수 있게 정리한 문서예요. llama-index-llms-octoai 패키지를 설치하고 API 키만 설정하면 완성·채팅·스트리밍은 물론 모델 파라미터까지 손쉽게 다룰 수 있어요.
출처: 문서
본문
Colab에서 이 노트북을 여는 경우 LlamaIndex 🦙 설치가 필요할 거예요.
%pip install llama-index-llms-octoai
%pip install llama-index
%pip install octoai-sdk
아래에 OctoAI API 키를 넣어주세요. 키는 OctoAI에서 발급받을 수 있어요.
좀 더 도움이 필요하다면 여기 지침을 참고하세요.
OCTOAI_API_KEY = ""
기본 모델로 통합 초기화하기
from llama_index.llms.octoai import OctoAI
octoai = OctoAI(token=OCTOAI_API_KEY)
프롬프트로 complete 호출하기
response = octoai.complete("Paul Graham is ")
print(response)
메시지 목록으로 chat 호출하기
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system",
content="Below is an instruction that describes a task. Write a response that appropriately completes the request.",
),
ChatMessage(role="user", content="Write a blog about Seattle"),
]
response = octoai.chat(messages)
print(response)
Streaming (스트리밍)
stream_complete 엔드포인트 사용하기
response = octoai.stream_complete("Paul Graham is ")
for r in response:
print(r.delta, end="")
메시지 목록으로 stream_chat 사용하기
from llama_index.core.llms import ChatMessage
messages = [
ChatMessage(
role="system",
content="Below is an instruction that describes a task. Write a response that appropriately completes the request.",
),
ChatMessage(role="user", content="Write a blog about Seattle"),
]
response = octoai.stream_chat(messages)
for r in response:
print(r.delta, end="")
Configure Model (모델 설정)
# To customize your API token, do this
# otherwise it will lookup OCTOAI_TOKEN from your env variable
octoai = OctoAI(
model="mistral-7b-instruct", max_tokens=128, token=OCTOAI_API_KEY
)
response = octoai.complete("Paul Graham is ")
print(response)