SpellcraftAI / nextjs-openai

Hooks and components for working with OpenAI streams.
https://nextjs-openai.vercel.app
MIT License
239 stars 18 forks source link

no way to "POST" a body using <StreamingText> #2

Closed Johnrobmiller closed 1 year ago

Johnrobmiller commented 1 year ago

I know it's possible to put a query in the url, and maybe this is more RESTful, but it's also a more complex solution, which, in my opinon, makes it not as good as simply being able to add a POST body when making the api call.

ctjlewis commented 1 year ago

What behavior would you want instead?

Johnrobmiller commented 1 year ago

I suppose to make sure we are on this same page, is this the intended way to pass the user's input and a summary to my endpoint?

image
ctjlewis commented 1 year ago

Ah, I see what you mean. I'll add support for data and GET or POST mode, will just default to GET.

I'll use URLSearchParams() behind the scenes but yes this would be how you do it for now, just put it in the query params manually and read it from req in your API route. I've got you on a better pattern shortly though.

ctjlewis commented 1 year ago

@Johnrobmiller New major should work for this, can you let me know if the docs are clear enough and whether you find it easy enough to use?

See the demo at https://nextjs-openai.vercel.app/ which now uses POST data. It is also POST by default now.

Just use const data = await req.json() in the Edge function, where you sent data as <StreamingTextURL url={url} data={data}> or equivalent buffer options for the hook via useTextBuffer({ url, data }).