跳至主要內容

ChatKonko

Konko

Konko API 是一個完全託管的 Web API,旨在協助應用程式開發人員

  1. 為其應用程式選擇合適的開放原始碼或專有 LLM
  2. 透過與領先應用程式框架和完全託管的 API 整合,更快地建置應用程式
  3. 微調較小的開放原始碼 LLM,以一小部分的成本實現業界領先的效能
  4. 部署生產規模的 API,這些 API 符合安全性、隱私權、輸送量和延遲 SLA,而無需使用 Konko AI 的 SOC 2 合規、多雲基礎架構進行基礎架構設定或管理

此範例說明如何使用 LangChain 與 Konko ChatCompletion 模型互動

若要執行此筆記本,您需要 Konko API 金鑰。登入我們的 Web 應用程式以建立 API 金鑰來存取模型

from langchain_community.chat_models import ChatKonko
from langchain_core.messages import HumanMessage, SystemMessage

設定環境變數

  1. 您可以為以下項目設定環境變數
    1. KONKO_API_KEY (必要)
    2. OPENAI_API_KEY (選用)
  2. 在您目前的 Shell 工作階段中,使用 export 命令
export KONKO_API_KEY={your_KONKO_API_KEY_here}
export OPENAI_API_KEY={your_OPENAI_API_KEY_here} #Optional

呼叫模型

Konko 概觀頁面上尋找模型

尋找 Konko 執行個體上執行模型清單的另一種方法是透過此端點

從這裡,我們可以初始化我們的模型

chat = ChatKonko(max_tokens=400, model="meta-llama/llama-2-13b-chat")
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="Explain Big Bang Theory briefly"),
]
chat(messages)
AIMessage(content="  Sure thing! The Big Bang Theory is a scientific theory that explains the origins of the universe. In short, it suggests that the universe began as an infinitely hot and dense point around 13.8 billion years ago and expanded rapidly. This expansion continues to this day, and it's what makes the universe look the way it does.\n\nHere's a brief overview of the key points:\n\n1. The universe started as a singularity, a point of infinite density and temperature.\n2. The singularity expanded rapidly, causing the universe to cool and expand.\n3. As the universe expanded, particles began to form, including protons, neutrons, and electrons.\n4. These particles eventually came together to form atoms, and later, stars and galaxies.\n5. The universe is still expanding today, and the rate of this expansion is accelerating.\n\nThat's the Big Bang Theory in a nutshell! It's a pretty mind-blowing idea when you think about it, and it's supported by a lot of scientific evidence. Do you have any other questions about it?")

此頁面是否對您有幫助?