ant-design / pro-chat

🤖 Components Library for Quickly Building LLM Chat Interfaces.
https://pro-chat.antdigital.dev
MIT License
667 stars 83 forks source link

🧐[问题]配置流式输出问题 #173

Closed PeiJM closed 4 months ago

PeiJM commented 4 months ago

🧐 问题描述

自己开的后台服务,自己组装 Reader 老是会报各种各样的错误,使用 详见 Github ChatGPT-NextJs 说的这个里边 demos/chatgpt-nextjs/src/app/api/openai/route.ts 的这个文件的代码 request: Request 参数不知道是什么 没有找到使用示例 .按照官网 使用三方 Reader 解析器解决方案 const openai = new OpenAI({ apiKey: "OpenAI-Key", baseurl:"" // 绝对路径跨域 相对路径url不符合规范 }); 这个里边去使用 baseurl填写相对路径 报错url不规范,使用绝对路径 又报跨域 真的累了 搞了1天 求求给个明明白白的示例把

ONLY-yours commented 4 months ago

这个 BaseUrl 一般指的是 ChatGPT 转发的中转服务,例如 https://api.chatanywhere.com.cn/v1 这种三方

如果你是自己的后台服务,也没有必要用所谓的 new OpenAI,因为你不是 ChatGPT 服务呀。

你直接在 Request 里面通过 fetch 发起请求就好了,例如

request={async (messages: Array<any>, modal) => {
          return await fetch("http://127.0.0.1/get/xxx", {
            method: "POST",
            body: JSON.stringify({ messages: messages }),
          });
        }}

@PeiJM

PeiJM commented 4 months ago

下面四张图片是对应图片配置和效果,效果都不对 返回的数据并没有被处理 帮忙看一下到底咋回事啊 谢谢 感恩 三方库配置效果 使用三方库配置 正常配置 正常配置后效果图 @ONLY-yours

ONLY-yours commented 4 months ago

@PeiJM 看起来你这个结构和这个 demo 里面的很类似

https://pro-chat.antdigital.dev/components/pro-chat#sse-%E6%95%B0%E6%8D%AE%E6%B5%81%E5%A4%84%E7%90%86

image

参造这里写一个 reader 去处理这个