Corpus API Examples: Working with Corpora
This page provides examples for how to use the Corpus API to work with corpora. Most if not all of what is covered here can also be accomplished by using the Fixie Console. Examples are provided in four flavors with each of those corresponding with the method of calling the Corpus API: via curl, using the Fixie CLI via the terminal, using the Fixie client in JavaScript, and using the Corpus REST API in Python.
Calling the Corpus API requires a Fixie account. For the examples using curl or the REST API (in JS or Python), you will
need to provide your Fixie API key. The examples use <TOKEN>
to denote where you need to provide your key. You can find
your API key (AKA "API token") on your profile page.
When you use the Fixie CLI, you will need to use the auth
command. See the docs for more
information.
Create Corpus
Create a new corpus that will contain information about Fixie.ai. Name the corpus "Fixie.ai Corpus" and give it a description of "Fixie.ai info including the company website, blog, and product documentation."
See the Corpus API docs for more information.
- curl
- Fixie CLI
- JavaScript
- Python
curl -L -X POST 'https://api.fixie.ai/api/v1/corpora' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
-d '{
"corpus": {
"displayName": "Fixie.ai Corpus",
"description": "Fixie.ai info including the company website, blog, and product documentation."
}
}'
npx fixie@latest corpus create "Fixie.ai Corpus" "Fixie.ai info including the company website, blog, and product documentation."
// Import the Fixie client
import { IsomorphicFixieClient } from "fixie";
// Set the API key and Create the Fixie client
const API_KEY = "<TOKEN>";
const fixieClient = new FixieClient({ apiKey: API_KEY });
// Set our variables for the corpus we want to create
const DISPLAY_NAME = "Fixie.ai Corpus";
const DESCRIPTION = "Fixie.ai info including the company website, blog, and product documentation.";
// Create the corpus
fixieClient.createCorpus({ name: DISPLAY_NAME, description: DESCRIPTION }).then((corpus) => {
console.log(JSON.stringify(corpus));
});
import requests
import json
url = "https://api.fixie.ai/api/v1/corpora"
payload = json.dumps({
"corpus": {
"displayName": "Fixie.ai Corpus",
"description": "Fixie.ai info including the company website, blog, and product documentation.",
}
})
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': 'Bearer <TOKEN>'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Delete Corpus
Delete corpus with ID 74e5bc4c-c2d9-4296-a2de-9c448d4bc307
.
See the Corpus API docs for more information.
- curl
- Fixie CLI
- JavaScript
- Python
curl -L -X DELETE 'https://api.fixie.ai/api/v1/corpora/74e5bc4c-c2d9-4296-a2de-9c448d4bc307' \
-H 'Authorization: Bearer <TOKEN>'
TODO: Not yet implemented
// Import the Fixie client
import { FixieClient } from "fixie";
// Set the API key and Create the Fixie client
const API_KEY = "<TOKEN>";
const fixieClient = new FixieClient({ apiKey: API_KEY });
// Set our ID for the corpus we want to delete
const CORPUS_ID = "74e5bc4c-c2d9-4296-a2de-9c448d4bc307";
// Delete the corpus
fixieClient.deleteCorpus({ corpusId: CORPUS_ID }).then((corpus) => {
console.log(JSON.stringify(corpus));
});
import requests
url = "https://api.fixie.ai/api/v1/corpora/74e5bc4c-c2d9-4296-a2de-9c448d4bc307"
payload={}
headers = {
'Authorization': 'Bearer <TOKEN>'
}
response = requests.request("DELETE", url, headers=headers, data=payload)
print(response.text)