vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
10.35k stars 1.56k forks source link

TypeError: Inter-TransformStream ReadableStream.pipeTo() is not implemented #2972

Open liho00 opened 2 months ago

liho00 commented 2 months ago

Description

AI_APICallError: Failed to process successful response
    at postToApi (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/@ai-sdk/openai/node_modules/@ai-sdk/provider-utils/dist/index.mjs:117:13)
    at OpenAIChatLanguageModel.doStream (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/@ai-sdk/openai/dist/index.mjs:302:50)
    at fn (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:335:23)
    at /Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:18:22
    at _retryWithExponentialBackoff (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:37:12)
    at startRoundtrip (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:300:13)
    at fn (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:377:11)
    at /Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:18:22
    at action (/Users/liho/Desktop/epray/hydrogen-sep/epray/app/routes/api.chat.ts:25:18)
    at callRouteAction (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/.vite/deps_ssr/@remix-run_server-runtime.js:3125:16) {
  cause: 'TypeError: Inter-TransformStream ReadableStream.pipeTo() is not implemented.\n' +
    '    at /Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/@ai-sdk/openai/node_modules/@ai-sdk/provider-utils/dist/index.mjs:100:10\n' +
    '    at postToApi (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/@ai-sdk/openai/node_modules/@ai-sdk/provider-utils/dist/index.mjs:105:20)\n' +
    '    at OpenAIChatLanguageModel.doStream (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/@ai-sdk/openai/dist/index.mjs:302:50)\n' +
    '    at fn (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:335:23)\n' +
    '    at /Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:18:22\n' +
    '    at _retryWithExponentialBackoff (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:37:12)\n' +
    '    at startRoundtrip (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:300:13)\n' +
    '    at fn (/Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:377:11)\n' +
    '    at /Users/liho/Desktop/epray/hydrogen-sep/epray/node_modules/ai/dist/index.mjs:18:22\n' +
    '    at action (/Users/liho/Desktop/epray/hydrogen-sep/epray/app/routes/api.chat.ts:25:18)'
}

Code example

// app/routes/api.chat.ts

import type {ActionFunctionArgs} from '@vercel/remix';
import {createOpenAI} from '@ai-sdk/openai';
import {streamText} from 'ai';

export const config = {runtime: 'edge'};

const openrouter = createOpenAI({
  apiKey:
    'xxx',
  baseURL: 'https://openrouter.ai/api/v1',
});
export async function action({request}: ActionFunctionArgs) {
//   const {messages} = await request.json();
console.log('request', request)
  const result = await streamText({
    model: openrouter('qwen/qwen-2-7b-instruct'),
    // messages,
    prompt:
      'How to make a chatbot that can answer questions about the weather?',
  });
  console.log('result', result)

  return result.toDataStreamResponse();

}

Additional context

No response

lgrammel commented 2 months ago

What platform are you running on? Node.js version?

liho00 commented 2 months ago

What platform are you running on? Node.js version?

tried node v18 and node v20, using remix js by hydrogen

{
  "name": "epray",
  "private": true,
  "sideEffects": false,
  "version": "2024.7.5",
  "type": "module",
  "scripts": {
    "build": "shopify hydrogen build --codegen",
    "dev": "shopify hydrogen dev --codegen",
    "preview": "shopify hydrogen preview --build",
    "lint": "eslint --no-error-on-unmatched-pattern --ext .js,.ts,.jsx,.tsx .",
    "codegen": "shopify hydrogen codegen"
  },
  "prettier": "@shopify/prettier-config",
  "dependencies": {
    "@ai-sdk/openai": "^0.0.58",
    "@remix-run/react": "^2.10.1",
    "@remix-run/server-runtime": "^2.10.1",
    "@shopify/hydrogen": "2024.7.4",
    "@shopify/remix-oxygen": "^2.0.6",
    "@vercel/remix": "^2.11.2",
    "ai": "^3.3.32",
    "graphql": "^16.6.0",
    "graphql-tag": "^2.12.6",
    "isbot": "^3.8.0",
    "openai": "^4.58.2",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "web-streams-polyfill": "^4.0.0"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "5.0.2",
    "@remix-run/dev": "^2.10.1",
    "@remix-run/eslint-config": "^2.10.1",
    "@shopify/cli": "~3.65.3",
    "@shopify/hydrogen-codegen": "^0.3.1",
    "@shopify/mini-oxygen": "^3.0.4",
    "@shopify/oxygen-workers-types": "^4.1.2",
    "@shopify/prettier-config": "^1.1.2",
    "@tailwindcss/vite": "4.0.0-alpha.17",
    "@total-typescript/ts-reset": "^0.4.2",
    "@types/eslint": "^8.4.10",
    "@types/react": "^18.2.22",
    "@types/react-dom": "^18.2.7",
    "eslint": "^8.20.0",
    "eslint-plugin-hydrogen": "0.12.2",
    "prettier": "^2.8.4",
    "typescript": "^5.2.2",
    "vite": "^5.1.0",
    "vite-tsconfig-paths": "^4.3.1"
  },
  "engines": {
    "node": ">=18.0.0"
  },
  "browserslist": [
    "defaults"
  ]
}
lgrammel commented 2 months ago

Whatever platform you are using (I guess hydrogen), it does not support the web standard ReadableStream pipeTo: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeTo

CleanShot 2024-09-11 at 18 10 53

Can you inquire with them if they can add support?

lgrammel commented 2 months ago

Also, what is the exact version of @ai-sdk/openai that you are using?

liho00 commented 2 months ago

"@ai-sdk/openai": "^0.0.58",

"@ai-sdk/openai": "^0.0.58",
liho00 commented 2 months ago

Whatever platform you are using (I guess hydrogen), it does not support the web standard ReadableStream pipeTo: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/pipeTo

CleanShot 2024-09-11 at 18 10 53

Can you inquire with them if they can add support?

hydrogen actually using remix js & vite js

lgrammel commented 2 months ago

Do you have a repo with a reproduction? Would love to take a closer look since it seems this should be supported, it's so basic.

liho00 commented 2 months ago

Do you have a repo with a reproduction? Would love to take a closer look since it seems this should be supported, it's so basic.

@lgrammel

https://github.com/liho00/hydrogen-storefront

here you go ser, but have to replace the code https://github.com/liho00/hydrogen-storefront/blob/main/app/routes/api.chat.ts#L10-L14

I wish to use next js, however shopify hydrogen is using remix js which hitting a lot of issues, sad tho...