Skip to main content

Functions

A Function accepts the following parameters:
  • name (str): The name of the function
  • description (str): A description of what the function does
  • input_schema (dict): Schema defining the expected input parameters
  • output_schema (dict): Schema defining the expected output format
  • prompt (str): The prompt template used by the function
  • api_key (str): The API key for model access
  • model (str): The name of the model to use
  • base_url (str): Optional base URL for custom LiteLLM server deployments
Example of how to create a function:
import requests
import json

BASE_URL = "https://orch.zenbase.ai/api"
API_KEY = "YOUR ZENBASE API KEY"

def api_call(method, endpoint, data=None):
    url = f"{BASE_URL}/{endpoint}"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Api-Key {API_KEY}"
    }
    response = requests.request(method, url, headers=headers, data=json.dumps(data) if data else None)
    return response


function_data = {
    "name": "Sentiment Analysis",
    "description": "Analyze the sentiment of a given text.",
    "input_schema": {
        "properties": {"text": {"title": "Text", "type": "string"}},
        "required": ["text"],
        "title": "SentimentInput",
        "type": "object",
    },
    "output_schema": {
        "properties": {
            "sentiment": {"enum": ["positive", "negative", "neutral"], "title": "Sentiment", "type": "string"}
        },
        "required": ["sentiment"],
        "title": "SentimentOutput",
        "type": "object",
    },
    "prompt": """Analyze the sentiment of the given text.
            Determine if the sentiment is positive, negative, or neutral.""",
    "api_key": "MODEL API KEY",
    "model": "MODEL NAME",  # for example gpt-4o-mini
    "base_url": "",  # Optional: URL for custom LiteLLM server
}

function = api_call("POST", "functions/", function_data)
function_id = function.json()['id']