Model API guide

Model Guide for you to implement FLock model

Pre-requirement

Manual creation via website

Technology Stack

  • TypeScript

  • JavaScript

API Call example

How it Works

Setup

Package installation

npm install --save axios dotenv
# or
yarn add axios dotenv
# or 
pnpm add axios dotenv

.env

  • Create an .env file in the root directory or in your existing env file, add the followings:

// Some code
FLOCK_BOT_API_KEY= "<your_wallet_address_from_api_generation>"
FLOCK_BOT_ENDPOINT="https://rag-chat-ml-backend-prod.flock.io"

Step by Step guide

  • Create a flockModel.ts

  • Create a async/await function flockModel wrapping the API call

    • use axios.post method for request

    • We will pass two parameters

      • question

      • knowledge_source_id

    • get the response of the call

    • We chose to use try/catch to handle any error during the call to debug the process.

import axios from "axios";
import * as dotenv from "dotenv";

// Load environment variables from .env file
dotenv.config({ path: "./.env" }); // Make sure the path is correct

async function main(prompt: string) {
  console.log("Prompt:", prompt);

  try {
    // Construct the request payload
    const payload = {
      question: prompt,
      chat_history: [],
      knowledge_source_id: "<model_id>", // replace with your model id
    };

    // Set the headers
    const headers = {
      "x-api-key": process.env.FLOCK_BOT_API_KEY, // Ensure API key is set in .env
    };

    // Send POST request using axios
    const response = await axios.post(
      `${endpoint}/chat/conversational_rag_chat`,
      payload,
      {
        headers,
      }
    );


    // Output the response data
    console.log(response.data);
  } catch (error) {
    console.error("Error:", error);
  }
}

// Example call to the main function
main("Can you figure out how to make a chatbot?");

Last updated