阿里云PAI EAS
Alibaba Cloud PAI (Platform for AI) is a lightweight and cost-efficient machine learning platform that uses cloud-native technologies. It provides you with an end-to-end modelling service. It accelerates model training based on tens of billions of features and hundreds of billions of samples in more than 100 scenarios.
Machine Learning Platform for AI of Alibaba Cloud is a machine learning or deep learning engineering platform intended for enterprises and developers. It provides easy-to-use, cost-effective, high-performance, and easy-to-scale plug-ins that can be applied to various industry scenarios. With over 140 built-in optimization algorithms,
Machine Learning Platform for AIprovides whole-process AI engineering capabilities including data labelling (PAI-iTAG), model building (PAI-DesignerandPAI-DSW), model training (PAI-DLC), compilation optimization, and inference deployment (PAI-EAS).
PAI-EASsupports different types of hardware resources, including CPUs and GPUs, and features high throughput and low latency. It allows you to deploy large-scale complex models with a few clicks and perform elastic scale-ins and scale-outs in real-time. It also provides a comprehensive O&M and monitoring system.
设置EAS服务
设置环境变量以初始化EAS服务URL和令牌。 更多信息请参阅此文档。
export EAS_SERVICE_URL=XXX
export EAS_SERVICE_TOKEN=XXX
另一个选项是使用此代码:
import os
from langchain_community.chat_models import PaiEasChatEndpoint
from langchain_core.language_models.chat_models import HumanMessage
os.environ["EAS_SERVICE_URL"] = "Your_EAS_Service_URL"
os.environ["EAS_SERVICE_TOKEN"] = "Your_EAS_Service_Token"
chat = PaiEasChatEndpoint(
eas_service_url=os.environ["EAS_SERVICE_URL"],
eas_service_token=os.environ["EAS_SERVICE_TOKEN"],
)
运行聊天模型
您可以使用默认设置调用EAS服务,如下所示:
output = chat.invoke([HumanMessage(content="write a funny joke")])
print("output:", output)
或者,使用新的推理参数调用EAS服务:
kwargs = {"temperature": 0.8, "top_p": 0.8, "top_k": 5}
output = chat.invoke([HumanMessage(content="write a funny joke")], **kwargs)
print("output:", output)
或者,运行流式调用以获取流式响应:
outputs = chat.stream([HumanMessage(content="hi")], streaming=True)
for output in outputs:
print("stream output:", output)