Users can upload a new KB file. Once the file is successfully uploaded, they can connect it to a character. Upon calling the API, the file will only be uploaded for processing and will not be available for use until the processing is complete. The upload API will return a unique ID assigned to the uploaded file, which must be used for all future interactions with the file.
Headers
Request Body
{"id":"<uuid of the uploaded file>","file_name":"<file_name>","is_available":false,"status":"inactive","timestamp":"2024-09-17 20:51:09.216522","file_size":"72374"}
{"API_ERROR":"Invalid API key provided.}
Here are some sample codes to demonstrate the request format for the endpoint -->
import requestsimport jsonurl ="https://api.convai.com/character/knowledge-bank/upload"headers ={'CONVAI-API-KEY':'<Your-API-Key>',}# Path to the file you want to uploadfile_path ="photosynthesis.txt"# Open the file in binary modewithopen(file_path, "rb")as file:# Create a dictionary for the form data form_data ={"file_name": file.name,"file": file}# Send the POST request with multipart/form-data response = requests.post(url, headers=headers, files=form_data)print(response.text)
List the status of KB files. Use this API to check the status of previously uploaded KB files. Once this API returns "is_available" as true for your UUID, you can confidently assume that the previously uploaded file is processed and ready to be connected to your character.
Please note that the list API requires the character_id as input. Accordingly, it returns a "status" field, which can either be "active" or "inactive." This field indicates whether a particular file is connected to a character. A file is considered connected if its "status" is "active" in the output.
Here are some sample codes to demonstrate the request format for the endpoint -->
import requestsimport jsonurl ="https://api.convai.com/character/knowledge-bank/list"headers ={'CONVAI-API-KEY':'<Your-API-Key>',}# Create a dictionary for the form dataform_data ={'character_id':'<Your-CharacterId>',}# Send the POST request with multipart/form-dataresponse = requests.post(url, headers=headers, data=form_data)print(response.text)
Update API can be used to attach (or remove) a KB file to your character. Once the file is successfully connected, all future interactions with the character will fetch knowledge from the attached KB as needed.
Headers
Request Body
{"STATUS":"SUCCESS"}
{"API_ERROR":"Invalid API key provided.}
Here are some sample codes to demonstrate the request format for the endpoint -->
import requestsimport jsonurl ="https://api.convai.com/character/update"headers ={'CONVAI-API-KEY':'<Your-API-Key>','Content-Type':'application/json'}# Create a dictionary for the JSON payloadpayload ={"charID":"<Your-Character-Id>","docs": [{"id":"<File-UUID>","status":"active"# or "inactive" depending on what you want to set} ] }# Convert the payload to JSONjson_payload = json.dumps(payload)response = requests.post(url, headers=headers, data=json_payload)print(response.text)
The knowledge bank delete API can be used to permanently remove documents from the user's account. Note that deleting a document will remove it from all characters it is associated with.
Headers
Request Body
{"Successfully deleted document"}
{
"API_ERROR": "Invalid API key provided.
}
Here are some sample codes to demonstrate the request format for the endpoint -->
import requestsimport jsonurl ="https://api.convai.com/character/knowledge-bank/delete"headers ={'CONVAI-API-KEY':'<Your-API-Key>','Content-Type':'application/json'}# Create a dictionary for the JSON payloadpayload ={"document_id":"<File-UUID>"}# Convert the payload to JSONjson_payload = json.dumps(payload)response = requests.post(url, headers=headers, data=json_payload)print(response.text)