+
95
-

微信小程序如何流式请求大模型接口?

微信小程序如何流式请求大模型接口?


网友回复

+
17
-

微信小程序流式请求chatgpt api接口的示例代码,兼容国内所有大模型api,示例代码如下:

   
    var requestTask = wx.request({
        url: 'https://api.openai.com/v1/chat/completions', // 流式接口的URL
        method: 'POST',
        data:  JSON.stringify({
            model: 'gpt4o',
            messages: [{
                role: 'user', conten...

点击查看剩余70%

+
14
-
wx.request({
  url: 'https://example.com/stream', // 流式接口的URL
  method: 'GET',
  responseType: 'stream', // 设置为stream以接收流式数据
  success: function (res) {
    const reader = res.data[0].g...

点击查看剩余70%

我知道答案,我要回答