0

For example, I can send request to openai-api by http-client

import { HttpClient } from '@angular/common/http';

return this.http.post(open-ai-interface).subscribe(...);

But, this interface returns ndjson, not json, so, how can I process this? I want a typewriter effect

I have tried ndjson, but I don't know how to use it, or there's having a better choice?

heaxyh
  • 573
  • 6
  • 20
ygz
  • 9
  • 1

1 Answers1

0

you can do this simple trick :

const json = "[" + ndjson.replace(/\r?\n/g, ",").replace(/,\s*$/, "") + "]";
const jsondata = JSON.parse(json);
heaxyh
  • 573
  • 6
  • 20
  • thank you for resp, if the resp of the query cost long time, we have to wait till all data received, maybe this is not the best way. – ygz Apr 19 '23 at 05:52
  • @ygz could you please mark the question as resolved, to help others when they face the same problem as you? – heaxyh Apr 19 '23 at 05:55
  • But this is not resolve my question – ygz Apr 20 '23 at 16:11