Skip to content

About

Tavern Platform is developing API access to most of the features within the platform to allow users to access the platform programmatically. These features are in active development and subject to change and shift quickly. It is our goal to build API endpoints for all of the core features in the platform.

We have an OpenAPI site in order to test and develop against endpoints.

Quick Start

Below is sample code in order to get you started with our API.

Search Library Documents

import requests
import dotenv   
import os

dotenv.load_dotenv()
# set my api key
API_KEY = "Tavern_API_KEY" # or os.environ['Tavern_API_Key'] if you save your API key to your local environment

prompt_text = f"""what does the evidence say about decay effects of tv ads?"""
url = "https://platform.tavernresearch.com/api/library/search"
params = {
    "query": prompt_text, 
    "library_id": "[YOUR_LIBRARY_ID]" # Set your library id to retrieve from
    "k": 1 # Set the number of chunks of documents to retrieve.
}
headers = {
    "accept": "application/json",
    "X-API-KEY": API_KEY
}

response = requests.get(url, headers=headers, params=params)

# To handle the response
if response.status_code == 200:
    data = response.json()
    page_content = data['documents'][0]['page_content']
    print(page_content)
else:
    print(f"Request failed with status code {response.status_code}")

Load Multiple Websites to the Library

import requests
import dotenv   
import os

dotenv.load_dotenv()
API_KEY = os.getenv("Tavern_API_KEY")

animals = ["cat", "dog", "bird", "rabbit"]
websites = [f"https://en.wikipedia.org/wiki/{name}" for name in animals]
library_name = "Wikipedia Animals"
url = "https://platform.tavernresearch.com/api/library/add/website"

params = {
    "name": library_name, 
    "url": websites
}
headers = {
    "accept": "application/json",
    "X-API-KEY": API_KEY
}

response = requests.post(url, headers=headers, params=params)

# To handle the response
if response.status_code == 201:
    print(f"Library {library_name} created.")
else:
    print(f"Request failed with status code {response.status_code}")

Create a Research Assistant

import requests
import dotenv   
import os

dotenv.load_dotenv()
API_KEY = os.getenv("Tavern_API_KEY")

# First see what libraries are available
url = "https://platform.tavernresearch.com/api/library/list"
headers = {
    "accept": "application/json",
    "X-API-KEY": API_KEY
}

response = requests.get(url, headers=headers)
if response.status_code == 200:
    print(response.json()['libraries'])
else:
    print(f"Request failed with status code {response.status_code}")

# If successful above, plan for your Research Assistant
name = "Kamala Research Assistant"
params = {
    "name": name, 
    "library_ids": ['96350f0b-fdf5-44e5-a4de-f04c76bb26ad'], # grabbed from printing the earlier response
    "org_share": True
}


url = "https://platform.tavernresearch.com/api/research_assistant/create"
headers = {
    "accept": "application/json",
    "X-API-KEY": API_KEY
}

response = requests.post(url, headers=headers, params=params)
if response.status_code == 201:
    print(f"Research Assistant {name} created.")
else:
    print(f"Request failed with status code {response.status_code}")