Python

Upload a document

The following script uploads a markdown file, showing the successful response returned by the web service.

import requests

files = {
    "file1": ("README.md", open("README.md", "rb")),
}

data = {
    "documentId": "doc01",
}

response = requests.post("http://127.0.0.1:9001/upload", files=files, data=data)

print(response.text)

Query

The following sends a question to the web service, printing the resulting answer generated by Kernel Memory.

import requests
import json

data = {"question": "Name one tool that I can use from command line"}

response = requests.post(
    "http://127.0.0.1:9001/ask",
    headers={"Content-Type": "application/json"},
    data=json.dumps(data),
).json()

if "text" in response:
    print(response["text"])
else:
    print("Response does not contain a 'text' property.")

If you run the scripts, the output will look similar to:

You can use the “upload-file.sh”, “ask.sh”, and “search.sh” tools from the command line.