Nebula (Symbl.ai)
概觀
本筆記本涵蓋如何開始使用 Nebula - Symbl.ai 的聊天模型。
整合細節
前往 API 參考 以取得詳細文件。
模型功能:待辦事項
設定
憑證
若要開始,請請求 Nebula API 金鑰 並設定 NEBULA_API_KEY
環境變數
import getpass
import os
os.environ["NEBULA_API_KEY"] = getpass.getpass()
安裝
整合已在 langchain-community
套件中設定。
實例化
from langchain_community.chat_models.symblai_nebula import ChatNebula
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
chat = ChatNebula(max_tokens=1024, temperature=0.5)
調用
messages = [
SystemMessage(
content="You are a helpful assistant that answers general knowledge questions."
),
HumanMessage(content="What is the capital of France?"),
]
chat.invoke(messages)
AIMessage(content=[{'role': 'human', 'text': 'What is the capital of France?'}, {'role': 'assistant', 'text': 'The capital of France is Paris.'}])
非同步
await chat.ainvoke(messages)
AIMessage(content=[{'role': 'human', 'text': 'What is the capital of France?'}, {'role': 'assistant', 'text': 'The capital of France is Paris.'}])
串流
for chunk in chat.stream(messages):
print(chunk.content, end="", flush=True)
The capital of France is Paris.
批次
chat.batch([messages])
[AIMessage(content=[{'role': 'human', 'text': 'What is the capital of France?'}, {'role': 'assistant', 'text': 'The capital of France is Paris.'}])]
鏈式
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_template("Tell me a joke about {topic}")
chain = prompt | chat
API 參考:ChatPromptTemplate
chain.invoke({"topic": "cows"})
AIMessage(content=[{'role': 'human', 'text': 'Tell me a joke about cows'}, {'role': 'assistant', 'text': "Sure, here's a joke about cows:\n\nWhy did the cow cross the road?\n\nTo get to the udder side!"}])
API 參考
查看 API 參考 以了解更多詳細資訊。