Add file to agent
Adding File
The add_file_to_agent() function allows you to upload a file to an agent in Blipper. This function requires the following parameters:
- agent_id (type: str): The ID of the agent to which the file will be added, provided as a string.
- filename (type: str): The name of the file to be uploaded, provided as a string.
- file (type: file object): The file object representing the content of the file to be uploaded.
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
In this example, the file is opened using the open() function with the mode "rb" (read binary). Then, the add_file_to_agent() function is called with the opened file passed as the file parameter. Finally, the file is closed using the close() method.
Response: The file_id variable will contain the ID of the uploaded file as a string.
More:
If you are using Python there is a shortly way to open a and close a file using with(), This way is generally considered more concise and safer as it automatically closes the file when it's done
1 2 3 4 5 6 | |
FastAPI example
If you are using FastAPI, you can upload the file using the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | |
And in the client side:
<form action="localhost:8080/upload-file-to-agent/" enctype="multipart/form-data" method="post">
<input name="file" type="file" required="required">
<input type="submit">
</form>