ai chat protocol
Typescript Release 1.0.0-beta.20240814.1
Microsoft AI 聊天协议 SDK 是一个库,用于通过遵循 AI 聊天协议 API 规范的服务轻松构建 AI 聊天接口,这两个接口均位于此存储库中。
通过就标准 API 合同达成一致,无论使用何种模型、编排工具或设计模式,都可以在不同的服务中轻松、一致地执行 AI 后端消费和评估。
注意:我们目前处于公共预览版。非常感谢您的反馈,我们已准备好全面上市!
通过人工智能聊天协议,您将能够:
请为该存储库加注星标以表示您对该项目的支持!
我们的综合入门指南即将推出!请务必查看示例和 API 规范以了解更多详细信息。
要在本地查看,请通过 npm 安装库:
npm install @microsoft/ai-chat-protocol
创建客户端对象:
const client = new AIChatProtocolClient ( "/api/chat" ) ;
将完成情况流式传输到您的 UI:
let sessionState = undefined ;
// add any logic to handle state here
function setSessionState ( value ) {
sessionState = value ;
}
const message : AIChatMessage = {
role : "user" ,
content : "Hello World!" ,
} ;
const result = await client . getStreamedCompletion ( [ message ] , {
sessionState : sessionState ,
} ) ;
for await ( const response of result ) {
if ( response . sessionState ) {
//do something with the session state returned
}
if ( response . delta . role ) {
// do something with the information about the role
}
if ( response . delta . content ) {
// do something with the content of the message
}
}
如果您对 Azure 上托管的示例感到好奇,以下示例在前端使用 AI 聊天协议 SDK:
此外,许多 Azure AI 示例项目在没有 SDK 的情况下使用 AI 聊天协议 API 规范,要么是因为它们没有前端,要么是因为它们是在库发布之前制作的:
该项目采用了微软开源行为准则。有关详细信息,请参阅行为准则常见问题解答或联系 [email protected] 提出任何其他问题或意见。
版权所有 (c) Microsoft Corporation。版权所有。
根据 MIT 许可证获得许可。