Updating KB Articles

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)

        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))

Hello @chris.raasch,

Could you please share the code?

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

Could you share the code you’re using in Unity? This post is under the Unity category. Or are you using a different platform?

Sorry, you are correct this code is from my python project trying to update KB articles.

Are there any updates for this?

I’m not able to get the sample code to work, can someone verify that the demo code works from the documentation?

I’m working in python.

Hello @chris.raasch,

We have updated the documentation. Could you please try again?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.