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

[BUG] File upload via API does not work #3299

Open
bendadaniel opened this issue Oct 2, 2024 · 2 comments
Open

[BUG] File upload via API does not work #3299

bendadaniel opened this issue Oct 2, 2024 · 2 comments
Labels
bug Something isn't working in-work Issue in work

Comments

@bendadaniel
Copy link

Problem:
Hello,
I have a chatflow with Retrieval Agent + Pinecone + File loader. When user uploads file via chat embed, everything works fine. File is uploaded, loaded by File loader, auto upsert to Pinecone and then Agent knows context of file.

However, in my case, I need to upload file to conversation via API first. When I call send message and upload base64, it does not work, Pinecone is not updated and Agent does not know anything about the document. There is no error in response on this API call or in LangSmith. I used the upload code from the Flowise docs example so it should work.

My general goal for context:
In our system, we have a lot of dynamic files and I want to make Agent than can retriavel from specific one file that user select. So I cant use some batch upsert of all files at one or something like that. So my idea is that when user want to "chat with file", embed is loaded and inicialised chat and my component send API call with this file automatically, with file I send same info like sessionId, chatId same as embed component. File is uploaded via API and then user can talk to agent about this specific file freshly loaded in Pinecone. I think there is alternative solution to create some other upsert flow where I can upsert single file with some metadata and then connect it to this my original flow, but Idea with api seems more clean and more compact for me.

Code
Api call:

const sendMessage = async (data: any) => {
    const response = await fetch(
        `${apiHost}/api/v1/prediction/${chatflowid}`,
        {
            method: "POST",
            headers: {"Content-Type": "application/json"},
            body: JSON.stringify(data)
        }
    );
    const result = await response.json();
    return result;
}
  sendMessage({
          "question": "",
          "chatId": chatId,
          "overrideConfig": {
            "sessionId": sessionId,
          },
          "uploads": [
              {
                  "data": "data:application/pdf;base64,JVBERi0xLjcNCiW1tbW1DQoxIDAgb2J........."
                  "type": 'file',
                  "name": 'VOP_EN_2023-06-26.pdf',
                  "mime": 'application/pdf'
              }
          ]
      }).then((response) => {
          console.log(response);
      });

React embed:

<FullPageChat
    chatflowid={chatflowid}
     apiHost={apiHost}
     chatflowConfig={
     { 
        sessionId: sessionId,
           vars: {
              customerId: chatId
            }
          }
     }
/> 

Expected behavior
Works same as manual user upload.

Screenshots
Screenshot 2024-10-02 at 18 25 16

Setup

  • Render instance
  • Flowise Version 2.1.1

Thank you for your time.

@bendadaniel
Copy link
Author

I found out, that when user manually upload file via UI then there are 2 api calls in background, first call is 'upsert api' call and then "my" prediction api call. So my problem would be solved if I replicate it, right?

Screenshot 2024-10-04 at 10 59 35

@bendadaniel
Copy link
Author

Okey it is also not posible because I found out that internal chatId in embed is generated as:

FlowiseAI/FlowiseChatEmbed:Bot.tsx::260

const [chatId, setChatId] = createSignal(
  (props.chatflowConfig?.vars as any)?.customerId ? `${(props.chatflowConfig?.vars as any).customerId.toString()}+${uuidv4()}` : uuidv4(),
);

So there is no way how to get the chatId of the current conversation outside of embed. So I cant programmatically write/upload/upsert anything to this specific conversation via direct API call.

Do you have any idea how I can achieve my goal?

@HenryHengZJ HenryHengZJ added bug Something isn't working in-work Issue in work labels Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in-work Issue in work
Projects
None yet
Development

No branches or pull requests

2 participants