ChatYI
这将帮助您开始使用 Yi 聊天模型。有关所有 ChatYi 功能和配置的详细文档,请访问API 参考。
01.AI由李开复博士创立,是一家处于人工智能 2.0 前沿的全球公司。他们提供最先进的大型语言模型,包括 Yi 系列,参数范围从 60 亿到数百亿不等。01.AI 还提供多模态模型、开放式 API 平台以及 Yi-34B/9B/6B 和 Yi-VL 等开源选项。
概述
集成详细信息
类 | 包 | 本地 | 可序列化 | JS 支持 | 包下载 | 包最新版本 |
---|---|---|---|---|---|---|
ChatYi | langchain_community | ✅ | ❌ | ❌ |
模型功能
工具调用 | 结构化输出 | JSON 模式 | 图像输入 | 音频输入 | 视频输入 | 令牌级流式传输 | 原生异步 | 令牌使用 | Logprobs |
---|---|---|---|---|---|---|---|---|---|
❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ❌ | ✅ | ❌ |
设置
要访问 ChatYi 模型,您需要创建一个 01.AI 帐户、获取 API 密钥并安装 langchain_community
集成包。
凭据
访问01.AI 以注册 01.AI 并生成 API 密钥。完成此操作后,设置 YI_API_KEY
环境变量
import getpass
import os
os.environ["YI_API_KEY"] = getpass.getpass("Enter your Yi API key: ")
如果您希望自动跟踪模型调用,您还可以通过取消注释以下内容来设置您的LangSmith API 密钥
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
# os.environ["LANGSMITH_TRACING"] = "true"
安装
LangChain 模块名称集成位于 langchain_community
包中
%pip install -qU langchain_community
实例化
现在我们可以实例化我们的模型对象并生成聊天完成。
- 待办事项:使用相关参数更新模型实例化。
from langchain_community.chat_models.yi import ChatYi
llm = ChatYi(
model="yi-large",
temperature=0,
timeout=60,
yi_api_base="https://api.01.ai/v1/chat/completions",
# other params...
)
API 参考:ChatYi
调用
from langchain_core.messages import HumanMessage, SystemMessage
messages = [
SystemMessage(content="You are an AI assistant specializing in technology trends."),
HumanMessage(
content="What are the potential applications of large language models in healthcare?"
),
]
ai_msg = llm.invoke(messages)
ai_msg
API 参考:HumanMessage | SystemMessage
AIMessage(content="Large Language Models (LLMs) have the potential to significantly impact healthcare by enhancing various aspects of patient care, research, and administrative processes. Here are some potential applications:\n\n1. **Clinical Documentation and Reporting**: LLMs can assist in generating patient reports and documentation by understanding and summarizing clinical notes, making the process more efficient and reducing the administrative burden on healthcare professionals.\n\n2. **Medical Coding and Billing**: These models can help in automating the coding process for medical billing by accurately translating clinical notes into standardized codes, reducing errors and improving billing efficiency.\n\n3. **Clinical Decision Support**: LLMs can analyze patient data and medical literature to provide evidence-based recommendations to healthcare providers, aiding in diagnosis and treatment planning.\n\n4. **Patient Education and Communication**: By simplifying medical jargon, LLMs can help in educating patients about their conditions, treatment options, and preventive care, improving patient engagement and health literacy.\n\n5. **Natural Language Processing (NLP) for EHRs**: LLMs can enhance NLP capabilities in Electronic Health Records (EHRs) systems, enabling better extraction of information from unstructured data, such as clinical notes, to support data-driven decision-making.\n\n6. **Drug Discovery and Development**: LLMs can analyze biomedical literature and clinical trial data to identify new drug candidates, predict drug interactions, and support the development of personalized medicine.\n\n7. **Telemedicine and Virtual Health Assistants**: Integrated into telemedicine platforms, LLMs can provide preliminary assessments and triage, offering patients basic health advice and determining the urgency of their needs, thus optimizing the utilization of healthcare resources.\n\n8. **Research and Literature Review**: LLMs can expedite the process of reviewing medical literature by quickly identifying relevant studies and summarizing findings, accelerating research and evidence-based practice.\n\n9. **Personalized Medicine**: By analyzing a patient's genetic information and medical history, LLMs can help in tailoring treatment plans and medication dosages, contributing to the advancement of personalized medicine.\n\n10. **Quality Improvement and Risk Assessment**: LLMs can analyze healthcare data to identify patterns that may indicate areas for quality improvement or potential risks, such as hospital-acquired infections or adverse drug events.\n\n11. **Mental Health Support**: LLMs can provide mental health support by offering coping strategies, mindfulness exercises, and preliminary assessments, serving as a complement to professional mental health services.\n\n12. **Continuing Medical Education (CME)**: LLMs can personalize CME by recommending educational content based on a healthcare provider's practice area, patient demographics, and emerging medical literature, ensuring that professionals stay updated with the latest advancements.\n\nWhile the applications of LLMs in healthcare are promising, it's crucial to address challenges such as data privacy, model bias, and the need for regulatory approval to ensure that these technologies are implemented safely and ethically.", response_metadata={'token_usage': {'completion_tokens': 656, 'prompt_tokens': 40, 'total_tokens': 696}, 'model': 'yi-large'}, id='run-870850bd-e4bf-4265-8730-1736409c0acf-0')
链接
我们可以像这样将我们的模型与提示模板链接
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a helpful assistant that translates {input_language} to {output_language}.",
),
("human", "{input}"),
]
)
chain = prompt | llm
chain.invoke(
{
"input_language": "English",
"output_language": "German",
"input": "I love programming.",
}
)
API 参考:ChatPromptTemplate
AIMessage(content='Ich liebe das Programmieren.', response_metadata={'token_usage': {'completion_tokens': 8, 'prompt_tokens': 33, 'total_tokens': 41}, 'model': 'yi-large'}, id='run-daa3bc58-8289-4d72-a24e-80622fa90d6d-0')
API 参考
有关所有 ChatYi 功能和配置的详细文档,请访问 API 参考:https://python.langchain.ac.cn/v0.2/api_reference/community/chat_models/langchain_community.chat_models.yi.ChatYi.html