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
包中设置。
实例化
<!--IMPORTS:[{"imported": "ChatNebula", "source": "langchain_community.chat_models.symblai_nebula", "docs": "https://python.langchain.com/api_reference/community/chat_models/langchain_community.chat_models.symblai_nebula.ChatNebula.html", "title": "Nebula (Symbl.ai)"}, {"imported": "AIMessage", "source": "langchain_core.messages", "docs": "https://python.langchain.com/api_reference/core/messages/langchain_core.messages.ai.AIMessage.html", "title": "Nebula (Symbl.ai)"}, {"imported": "HumanMessage", "source": "langchain_core.messages", "docs": "https://python.langchain.com/api_reference/core/messages/langchain_core.messages.human.HumanMessage.html", "title": "Nebula (Symbl.ai)"}, {"imported": "SystemMessage", "source": "langchain_core.messages", "docs": "https://python.langchain.com/api_reference/core/messages/langchain_core.messages.system.SystemMessage.html", "title": "Nebula (Symbl.ai)"}]-->
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.'}])]
链接
<!--IMPORTS:[{"imported": "ChatPromptTemplate", "source": "langchain_core.prompts", "docs": "https://python.langchain.com/api_reference/core/prompts/langchain_core.prompts.chat.ChatPromptTemplate.html", "title": "Nebula (Symbl.ai)"}]-->
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_template("Tell me a joke about {topic}")
chain = prompt | chat
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 参考 以获取更多详细信息。