Skip to main content
Open In ColabOpen on GitHub

Nebula (Symbl.ai)

概览

这个笔记本介绍了如何开始使用Nebula - Symbl.ai的聊天模型。

集成细节

前往详细的文档,请访问API参考

模型特点:TODO

设置

Credentials

要开始,请请求一个Nebula API密钥,并设置NEBULA_API_KEY环境变量:

import getpass
import os

os.environ["NEBULA_API_KEY"] = getpass.getpass()

安装

该集成设置在langchain-community包中。

Instantiation

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)

Invocation

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.'}])

Async

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.

Batch

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
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参考以获得更多信息。