Dust Community Icon

Uploading PDF Files via API to Dustt Agent: SSL Error Troubleshooting

·
·

Hi, In a use case at Aramisauto, I'm trying to upload a PDF file via the API to then use it with a Dustt Agent. I have no problem obtaining an upload URL:

import requests
import os

# 1. Upload the file
file_size_in_bytes = int(os.path.getsize(filename))
upload_response = requests.post(
    f"https://dust.tt/api/v1/w/{wId_dust}/files",
    headers={"Authorization": f"Bearer {api_key_dust}"},
    json={
        "contentType": "application/pdf",
        "fileName": os.path.basename(filename),
        "fileSize": file_size_in_bytes,
        "useCase": "conversation",
    },
)
print(upload_response.status_code)
B

However, when uploading the file to this upload URL, I encounter an SSL URL error:

requests.exceptions.SSLError: HTTPSConnectionPool(host='dust.tt', port=443): Max retries exceeded with url: /api/v1/w/8ee268e693/files/fil_gXHmJOIvCGbz (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2426)')))
o

I don't see this part in the Dustt API documentation. Could you please indicate what the problem might be?

upload_url = upload_response.json()["file"]["uploadUrl"]
sess = requests.Session()
with open(filename, 'rb') as f:
    resp = sess.post(
        upload_url, 
        data=f.read(),
        headers={"Authorization": f"Bearer {api_key_dust}"},  # Do not include additional headers here
    )
print(resp.text)
n

  • Avatar of Alban
    Alban
    ·
    ·

    Hi, looks like an SSL error, do you have a proxy or anything that could block on your connection?

  • Avatar of Fabrice
    Fabrice
    ·
    ·

    Yes, I was using a VPN. Without the VPN, it seems to be working better.

  • Avatar of Fabrice
    Fabrice
    ·
    ·

    I just forger to specify content-type afterward "Content-Type": "application/octet-stream"

  • Avatar of Fabrice
    Fabrice
    ·
    ·

    Alban I wanted to use the API to start a conversation with an assistant and a PDF file. I successfully uploaded the PDF and received the following response:

    {"file":{"contentType":"application/pdf","fileName":"xxx-xxxx.pdf","fileSize":1959724,"id":"fil_123456789","status":"ready","useCase":"conversation","downloadUrl":"https://dust.tt/api/w/8ee268e693/files/fil_123456789"}}

    However, when trying to use this file to start a new conversation with the example payload, I don't get an error, but the file is not included in the conversation. When I open the conversation on the Dustt interface, I see that the file is not attached, and the assistant's response confirms this by indicating that I haven't associated any files...

    url = f"https://dust.tt/api/v1/w/{wId_dust}/assistant/conversations"
    payload = {
        "blocking": False,
        "visibility": "unlisted",
        "title": "Company Analysis",
        "message": {
            "content": "Give me the result of the analysis in MARKDOWN format so it can be displayed on a web page. Do not generate any graphs. I only want text in Markdown.",
            "mentions": [{"configurationId": "Qe9DOmxCUK"}],
            "context": {
                "origin": "api",
                "timezone": "Europe/Paris",
                "username": "johndoe",
                "fullName": "John Doe",
                "profilePictureUrl": "https://example.com/profile_picture.jpg",
                "email": "jonhdo@example.com",
                "content": "mention[BilanBuddy]{sId=Qe9DOmxCUK} test",
            },
            "contentFragments": {"fileId": upload_response.json()["file"]["id"]},  # Changed from contentFragments
        }
    }

  • Avatar of Fabrice
    Fabrice
    ·
    ·
  • Avatar of Alban
    Alban
    ·
    ·

    Ok, that's interesting - I haven't played too much with the file upload API, will relay to the people who built it to see if there's an issue there

  • Avatar of Fabrice
    Fabrice
    ·
    ·

    ok, thank you for you help

  • Avatar of Alban
    Alban
    ·
    ·

    Can you try uploading the contentFragment to the conversation through this API ? https://docs.dust.tt/reference/post_api-v1-w-wid-assistant-conversations-cid-content-fragments

  • Avatar of Fabrice
    Fabrice
    ·
    ·

    ok i'll try.

  • Avatar of Fabrice
    Fabrice
    ·
    ·

    So, it works using the content_fragments endpoints, not very elegant but working solution because I create a conversation > attach the content_fragments and send a new message to have the answer with the document.

  • Avatar of Fabrice
    Fabrice
    ·
    ·

    Thank you for you help

  • Avatar of Alban
    Alban
    ·
    ·

    Hi, After a bit more investigation looks like your first call is missing something: "contentFragments": {"fileId": upload_response.json()["file"]["id"]}, is missing a "title". (required) Also, contentFragments should be an array and not an object 👍