Skip to content
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

Importing & using AssistantStream breaks Angular SSR #896

Open
1 task done
rbaarsma opened this issue Jun 12, 2024 · 2 comments
Open
1 task done

Importing & using AssistantStream breaks Angular SSR #896

rbaarsma opened this issue Jun 12, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@rbaarsma
Copy link

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

Just by adding the following lines in my new Angular project, I get an error.

Lines:

import { AssistantStream } from 'openai/lib/AssistantStream';
...
const stream = AssistantStream.fromReadableStream(response.body);

On compiling the code I get the following error:

7:34:19 PM [vite] Error when evaluating SSR module /main.server.mjs:
2024-06-12T19:34:19.534881356Z |- TypeError: Cannot convert undefined or null to object
2024-06-12T19:34:19.534883506Z     at Function.getPrototypeOf (<anonymous>)
2024-06-12T19:34:19.534885641Z     at eval (/usr/src/app/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js:538:43)
2024-06-12T19:34:19.534887281Z     at eval (/usr/src/app/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js:9:68)
2024-06-12T19:34:19.534888777Z     at node_modules/web-streams-polyfill/dist/ponyfill.es2018.js (/usr/src/app/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js:12:1)
2024-06-12T19:34:19.534890467Z     at __require2 (/usr/src/app/.angular/vite-root/chatsite/chunk-QU2RNZFD.mjs:51:50)
2024-06-12T19:34:19.534891964Z     at eval (/usr/src/app/node_modules/openai/_shims/node-runtime.mjs:9:32)
2024-06-12T19:34:19.534893442Z     at async instantiateModule (file:///usr/src/app/node_modules/vite/dist/node/chunks/dep-cNe07EU9.js:55058:9)
2024-06-12T19:34:19.534894944Z 

Now I'm unsure whether or not this is something you guys can fix, or it should be somehow reported to Angular or the polyfill... but I thought I'd start here, because I really have no clue what's going on. The internals of the AssistantStream are somewhat beyond me and I have no experience with handling streams in Typescript.

Feel free to close this issue and report it to the right place - or I can do it with the right info.

To Reproduce

  1. Install Angular normally with
npm install -g @angular/cli
ng new my-app

As part of the installation prompts, choose to use SSR

  1. Add this lib
npm install openai
  1. Change the app.component.ts to include the openai AssistantStream
import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { AssistantStream } from 'openai/lib/AssistantStream';
import { HttpClient } from "@angular/common/http";

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet],
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss'
})
export class AppComponent {
  title = 'test';
  constructor(private http: HttpClient) {}
  private test() {
    this.http.post<any>('http://test', {}).subscribe((response) => {
      const stream = AssistantStream.fromReadableStream(response.body);
    });
  }
}
  1. Run angular and watch it crash
npm start

Code snippets

x

OS

Linux Mint

Node version

20.9.0 and 22.1.0

Library version

4.51.0

@rbaarsma rbaarsma added the bug Something isn't working label Jun 12, 2024
@rbaarsma
Copy link
Author

I have confirmed that if you don't use SSR in the angular installation, there's no issue.

@matt-casey
Copy link

Hi @rbaarsma, taking a look at this. Will let you know if I have trouble reproducing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants