复制
向 AI 提问
# Installing the langchain package needed to use the integration
pip install -qU langchain-community
复制
向 AI 提问
# Install the package
pip install -qU aleph-alpha-client
复制
向 AI 提问
# create a new token: https://docs.aleph-alpha.com/docs/account/#create-a-new-token
from getpass import getpass
ALEPH_ALPHA_API_KEY = getpass()
复制
向 AI 提问
········
复制
向 AI 提问
from langchain_community.llms import AlephAlpha
from langchain_core.prompts import PromptTemplate
复制
向 AI 提问
template = """Q: {question}
A:"""
prompt = PromptTemplate.from_template(template)
复制
向 AI 提问
llm = AlephAlpha(
model="luminous-extended",
maximum_tokens=20,
stop_sequences=["Q:"],
aleph_alpha_api_key=ALEPH_ALPHA_API_KEY,
)
复制
向 AI 提问
llm_chain = prompt | llm
复制
向 AI 提问
question = "What is AI?"
llm_chain.invoke({"question": question})
复制
向 AI 提问
' Artificial Intelligence is the simulation of human intelligence processes by machines.\n\n'
以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。