跳至主要內容

ChatOctoAI

OctoAI 提供簡易存取高效能運算資源的管道,並讓使用者能將其選擇的 AI 模型整合到應用程式中。OctoAI 運算服務協助您輕鬆執行、調整和擴展 AI 應用程式。

本筆記本示範如何使用 langchain.chat_models.ChatOctoAI 來處理 OctoAI 端點

Setup(設定)

若要執行我們的範例應用程式,需要兩個簡單步驟

  1. 您的 OctoAI 帳戶頁面 取得 API Token。

  2. 將您的 API Token 貼到下方的程式碼儲存格中,或者使用 octoai_api_token 關鍵字引數。

注意:如果您想使用 可用的模型 以外的不同模型,您可以將模型容器化,並建立自訂的 OctoAI 端點,方法是按照 從 Python 從頭開始建立容器 以及 從容器建立自訂端點 中的說明進行,然後更新您的 OCTOAI_API_BASE 環境變數。

import os

os.environ["OCTOAI_API_TOKEN"] = "OCTOAI_API_TOKEN"
from langchain_community.chat_models import ChatOctoAI
from langchain_core.messages import HumanMessage, SystemMessage

Example(範例)

chat = ChatOctoAI(max_tokens=300, model_name="mixtral-8x7b-instruct")
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="Tell me about Leonardo da Vinci briefly."),
]
print(chat(messages).content)

Leonardo da Vinci (1452-1519) was an Italian polymath who is often considered one of the greatest painters in history. However, his genius extended far beyond art. He was also a scientist, inventor, mathematician, engineer, anatomist, geologist, and cartographer.

Da Vinci is best known for his paintings such as the Mona Lisa, The Last Supper, and The Virgin of the Rocks. His scientific studies were ahead of his time, and his notebooks contain detailed drawings and descriptions of various machines, human anatomy, and natural phenomena.

Despite never receiving a formal education, da Vinci's insatiable curiosity and observational skills made him a pioneer in many fields. His work continues to inspire and influence artists, scientists, and thinkers today.


Was this page helpful?(此頁面是否對您有幫助?)