FlowiseAI / FlowiseChatEmbed

335 stars 1.35k forks source link

No possibility to modify HTTP calls in chat bubble before they are sent to server #227

Open CasperJ opened 3 months ago

CasperJ commented 3 months ago

Problem

When you embed the Chat bubble into a site that is protected by a reverse proxy or API gateway, then all calls must be authenticated. Currently, Flowise doesn't support injecting Auth headers or modifying CORS settings before sending the request to the API server.

Solution

226 fixes this by introducing an OnRequest hook in which the request can be modified.

Example

        FlowiseAiChatBot.init({
            chatflowid: "...",
            apiHost: "/api/ai/",
            chatflowConfig: {
                // topK: 2
            },
            onRequest: async (request) => {
                const cred = await myIdentityApi.getCredentials();
                const headers = new Headers(request.headers);
                headers.append("Authorization", `Bearer ${cred.token}`);
                request.headers = headers;
            },
           ...
        });