Using Converse with the AI Hub SDK
With the AI Hub software development kit (SDK), you can integrate the ability to chat with documents into your workflow. You can create a new Converse conversation, upload files to the conversation, and converse with your uploaded files. This guide includes a complete script you can reference to create your own complete workflow.
Review the developer quickstart and install the AI Hub SDK.
Creating a conversation with your files
To start, create a Converse conversation and upload files using the client.conversations.create
method.
Define the following values in the script:
See the Conversations endpoint for more supported parameters and information, including how to enable object detection.
When uploading files to a conversation, note these limitations:
-
Files can be up to 50 MB or 800 pages.
-
You can upload up to 100 MB per request.
-
You can have up to 100 documents per conversation.
-
Certain file types are supported.
When run, the method performs the following tasks:
-
Creates the conversation in your personal workspace.
-
Uploads the listed files to the conversation.
-
Processes the files, digitizing and indexing them for the conversation.
-
Returns the conversation ID, conversation name, and upload status in JSON format. For example:
Checking conversation status
After creating a conversation, use the client.conversations.status
method to fet`ch the status of the conversation. This step lets you check if the document processing stage is complete. When complete, you can start conversing with your documents.
The response is a status object, which contains information about the conversation and its processing status, according to the following schema:
For example:
Conversing with a document
When all documents are finished processing and the conversation state is COMPLETE
, you can start conversing with an uploaded document using the client.conversations.converse
method. You can converse with one document at a time by API.
User-defined parameters in this request include:
document_id
value. See the Conversations endpoint for details.When run, the example script queries the document with your question and returns the answer, along with a prompt ID. For example:
Complete workflow
This example Python script shows a complete, end-to-end workflow based on calls to AI Hub API using the AI Hub SDK. When run, this script performs the following tasks:
-
Creates a conversation and uploads files to the conversation.
-
Checks the processing status of the uploaded files.
-
When processing is complete, queries a document with the provided question.
-
Returns the answer to the question in JSON format.
User-defined values
To recap, this tables outlines all values in the complete script that can or must be defined.