-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
👑 [是否有计划支持websocket] #77
Comments
能不能给个 demo 关于使用 ws 的请求的?我们好了解下具体咋用的 |
@arvinxx 您看您是否方便看看https://github.com/pors/langchain-chat-websockets 这个示例, 核心就是我们在chain中完成了检索、对话、存储,然后在对话返回过程中通过websocket向前端返回,待都返回完成后后端进行存储。 |
使用websocket请求更新messages有完整使用示例代码吗? |
有一个差不多的例子,可以先参考这个 |
使用websocket怎么在服务端推送消息时再响应更新assistant的消息而不是user一发送就response消息啊? |
现在可以这样子做,首先你要在 request 里面阻止当前的内容生成,有一个 hooks stopGenerateMessage 停止生成消息,这样子相当于打破了默认的逻辑。然后返回一个空的 new response。 然后你使用 Chats 进行受控,你想什么时候响应更新就都可以了。 这块我稍后补一个文档。当然最好的方式还是让服务端把 websocket 改成 sse 哈哈哈 |
我就是这样构造一个websocket得ReadableStream就可以了 |
这个stopGenerateMessage 没有文档吗?具体怎么使用啊-_- |
@Antony-Jia Could you please give some more details about the implementation of
This is what I am doing: export default async function getResponse(ws, reqMessages) {
const readableStream = new ReadableStream({
async start(controller) {
ws.send(JSON.stringify(reqMessages)); //send the request messages on websocket
const encoder = new TextEncoder();
ws.on("message", ev => controller.enqueue(encoder.encode(ev.data)));
ws.on("close", ev => controller.close());
ws.on("error", ev => controller.error(ev));
},
});
return new Response(readableStream);
} The above is used as below: <ProChat
request={messages => getResponse(ws, messages)}
/> The websocket works fine. I am getting the response from the websocket and it is being enqueued to the controller. But when it is enqueued the UI does not update with the partial data. It just keeps spinning. What am I doing wrong? (The WS code above is simplified here for example purposes, but its lifetime is taken care of to avoid duplicate connections etc.) |
Sorry, I'm done replying. I've encountered what you said online, but not locally. The way I use it is roughly the same as yours. `
` I use useEffect to controll the controller close or enqueue |
🥰 需求描述
能否支持websocket的streaming流模式,目前一些对话需要在后台处理以后才能发送到前端,非常感谢!
🧐 解决方案
🚑 其他信息
The text was updated successfully, but these errors were encountered: