I’m trying to utilize the code from the dev docs, but I constantly get “Document ID and file are required”.
I’ve tried a lot of combinations, but here is the current version of my code:
with open(tempfilename, ‘r’) as file: #upload file to Convai #file_name = ‘kb_update_temp.txt’
logging.info(“document_id:”+str(document_id))
logging.info(“filename”+filename)
def updateKBContent(document_id,filename, content):
response = None
logging.info("document_id"+document_id)
logging.info("filename"+filename)
temp_dir = tempfile.gettempdir()
#create a temp txt document and write the content to it.
tempfilename = os.path.join(temp_dir,filename+".txt")
with open(tempfilename, 'w') as write_file:
write_file.write(content)
write_file.flush()
#open the file so we can send it forward to update the existing document.
with open(tempfilename, 'r') as file:
#upload file to Convai
#file_name = 'kb_update_temp.txt'
form_data = {
"document_id":document_id,
"file": file,
}
response = requests.post(ConvaiTools.CONVAIBASEURL + "/character/knowledge-bank/update", headers=ConvaiTools.requestHeaders(), files=form_data)
logging.info("upload response:"+str(response.text))
logging.info("response: "+str(response.text))
os.remove(tempfilename)
return response.data