The World's First fully free chatbot API

API Documentation

API Documentation

Xylaria API


Choose a language to see the code snippets for interacting with the API.

  1. Install the python client (docs) if you don't already have it installed.
  2. $ pip install gradio_client
  3. Find the API endpoint below corresponding to your desired function in the app. Copy the code snippet, replacing the placeholder values with your own input data. If this is a private Space, you may need to pass your Hugging Face token as well (read more). Or use the API Recorder to automatically generate your API requests.
  4. api_name: /chat

    from gradio_client import Client
    
    client = Client("Lap1official/API")
    result = client.predict(
            message="Hello!!",
            system_message="You are a friendly Chatbot who always responds in English unless the user specifically uses another language.",
            max_tokens=512,
            temperature=0.7,
            top_p=0.95,
            api_name="/chat"
    )
    print(result)
            

    Accepts 5 parameters:

    • message str Required

      The input value that is provided in the "Message" Textbox component.

    • system_message str Default: "You are a friendly Chatbot who always responds in English unless the user specifically uses another language."

      The input value that is provided in the "System message" Textbox component.

    • max_tokens float Default: 512

      The input value that is provided in the "Max new tokens" Slider component.

    • temperature float Default: 0.7

      The input value that is provided in the "Temperature" Slider component.

    • top_p float Default: 0.95

      The input value that is provided in the "Top-p (nucleus sampling)" Slider component.

    Returns 1 element

    • str

      The output value that appears in the "Response" Textbox component.

  1. Install the javascript client (docs) if you don't already have it installed.
  2. $ npm i -D https://cdn.jsdelivr.net/npm/@gradio/client@latest/dist/index.min.js
  3. Find the API endpoint below corresponding to your desired function in the app. Copy the code snippet, replacing the placeholder values with your own input data. If this is a private Space, you may need to pass your Hugging Face token as well (read more). Or use the API Recorder to automatically generate your API requests.
  4. api_name: /chat

    import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@latest/dist/index.min.js";
    
    const client = await Client.connect("Lap1official/API");
    const result = await client.predict("/chat", { 		
    		message: "Hello!!", 		
    		system_message: "Hello!!", 		
    		max_tokens: 1, 		
    		temperature: 0.1, 		
    		top_p: 0.1, 
    });
    
    console.log(result.data);
            

    Accepts 5 parameters:

    • message string Required

      The input value that is provided in the "Message" Textbox component.

    • system_message any Default: "You are a friendly Chatbot who always responds in English unless the user specifically uses another language."

      The input value that is provided in the "System message" Textbox component.

    • max_tokens string Default: 512

      The input value that is provided in the "Max new tokens" Slider component.

    • temperature number Default: 0.7

      The input value that is provided in the "Temperature" Slider component.

    • top_p number Default: 0.95

      The input value that is provided in the "Top-p (nucleus sampling)" Slider component.

    Returns 1 element

    • string

      The output value that appears in the "Response" Textbox component.

  1. Confirm that you have cURL installed on your system.
  2. $ curl --version
  3. Find the API endpoint below corresponding to your desired function in the app. Copy the code snippet, replacing the placeholder values with your own input data. If this is a private Space, you may need to pass your Hugging Face token as well (read more). Or use the API Recorder to automatically generate your API requests.
  4. api_name: /chat

    Making a prediction and getting a result requires 2 requests: a POST and a GET request. The POST request returns an EVENT_ID, which is used in the second GET request to fetch the results. In these snippets, we've used awk and read to parse the results, combining these two requests into one command for ease of use. See curl docs.

    curl -X POST https://lap1official-api.hf.space/gradio_api/call/chat -s -H "Content-Type: application/json" -d '{
      "data": [
    							"Hello!!",
    							"Hello!!",
    							1,
    							0.1,
    							0.1
    ]}' \
      | awk -F'"' '{ print $4}'  \
      | read EVENT_ID; curl -N https://lap1official-api.hf.space/gradio_api/call/chat/$EVENT_ID
            

    Accepts 5 parameters:

    • [0] string Required

      The input value that is provided in the "Message" Textbox component.

    • [1] any Required

      The input value that is provided in the "System message" Textbox component.

    • [2] string Required

      The input value that is provided in the "Max new tokens" Slider component.

    • [3] number Required

      The input value that is provided in the "Temperature" Slider component.

    • [4] number Required

      The input value that is provided in the "Top-p (nucleus sampling)" Slider component.

    Returns 1 element

    • string

      The output value that appears in the "Response" Textbox component.

Comments

Popular posts from this blog

OpenAI and Project Strawberry