You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
背景
文心一言作为呼声非常高的 Model Provider ,我们是需要支持的。但是百度的 SDK 设计的复杂度挺高,因此没法很轻易地接入。但通过之前 #1310 的实现改造,现在已经具备了处理各异流式请求的 provider 的能力。因此计划在本篇 RFC 中记录相应的实现思路。
同时顺带改造优化前置 UI 环节的处理流程,简化一个 provider 的接入实现。
设计思路
Provider 接入初始化
核心是实现一个
LobeRuntimeAI
类的初始化和chat
方法。初始化:
chat
接口调用:这里其实就是百度的 sdk 的实现和 openai 等比起来非常不友好的地方,像
AsyncIterable
这种东西 90% 的前端估计都没接触过。而接入复杂度也在这里。wenxin Stream 处理
在我们的流处理框架中,核心思路就两条:
pipeThrough
能力,将流按需转换成目标协议的内容,并添加回调;在 Wenxin 接入的过程中,Stream 处理流程如下:
ai
方法中的readableFromAsyncIterable
和自行实现的chatStreamable
,将流转换为 ReadableStreampipeThrough
中传入一个TransformStream
,来实现每个 chunk 的数据转换。createSSEProtocolTransformer
核心就是一个转换方法,用于创建我们定义的 SSE 的传输协议具体转换实现
首先看下 wenxin 的接口返回数据结构:
核心就是提取
result
字段,因此实现就很简单:以上就完成了 wenxin 的流式协议转换
chat 方法中接入
有了上述方法以后,在chat层实现就很简单了,
补齐测试
主要做下协议转换的测试:
进展
Beta Was this translation helpful? Give feedback.
All reactions