Arcee
本笔记本演示了如何使用 Arcee 类,通过 Arcee 的领域自适应语言模型 (DALMs) 来生成文本。
##Installing the langchain packages needed to use the integration
%pip install -qU langchain-community
设置
在使用 Arcee 之前,请确保 Arcee API 密钥已设置为 ARCEE_API_KEY 环境变量。您也可以将 API 密钥作为命名参数传递。
from langchain_community.llms import Arcee
# Create an instance of the Arcee class
arcee = Arcee(
model="DALM-PubMed",
# arcee_api_key="ARCEE-API-KEY" # if not already set in the environment
)
API Reference:Arcee
其他配置
您还可以根据需要配置 Arcee 的参数,例如 arcee_api_url、arcee_app_url 和 model_kwargs。
在对象初始化时设置 model_kwargs 会将这些参数作为默认值应用于后续的所有生成响应的调用。
arcee = Arcee(
model="DALM-Patent",
# arcee_api_key="ARCEE-API-KEY", # if not already set in the environment
arcee_api_url="https://custom-api.arcee.ai", # default is https://api.arcee.ai
arcee_app_url="https://custom-app.arcee.ai", # default is https://app.arcee.ai
model_kwargs={
"size": 5,
"filters": [
{
"field_name": "document",
"filter_type": "fuzzy_search",
"value": "Einstein",
}
],
},
)
生成文本
您可以提供一个提示(prompt)来从 Arcee 生成文本。下面是一个示例:
# Generate text
prompt = "Can AI-driven music therapy contribute to the rehabilitation of patients with disorders of consciousness?"
response = arcee(prompt)
其他参数
Arcee 允许您应用 filters 并设置检索到的文档的数量(size)来辅助文本生成。Filters(过滤器)有助于缩小搜索结果的范围。以下是使用这些参数的方法:
# Define filters
filters = [
{"field_name": "document", "filter_type": "fuzzy_search", "value": "Einstein"},
{"field_name": "year", "filter_type": "strict_search", "value": "1905"},
]
# Generate text with filters and size params
response = arcee(prompt, size=5, filters=filters)
Related
- LLM conceptual guide
- LLM how-to guides