vercel / ai

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

Client Side for LocalStorage #382

Closed satpalsr closed 1 year ago

satpalsr commented 1 year ago

I want to use localstorage with vercel ai-chatbot, but api/chat/route.ts is a server side code. A call to this api endpoint is made via useChat handleSubmit() which in turns call getStreamedResponse() and make a post request to api endpoint.

Now, as I want to use localstorage at api/chat/route, I also need to make ai-sdk code client side. Since, otherwise I get Attempted to call POST() from the server but POST is on the client. It's not possible to invoke a client function from the server

Also created the same issue on vercel ai-chatbot

MaxLeiter commented 1 year ago

This library won't support making the llm API requests on the client as that requires exposing your API key(s) to the browser, but you’re welcome to work around that.

What are you trying to accomplish?

satpalsr commented 1 year ago

Hey @MaxLeiter,

I am creating a client side chat ui application only where users can use their own api key & use their own browser local storage. Though no problem now, I moved local storage to chat panel & it seems to be working fine.