FLock
Developer GuideGithub
  • What is FLock
    • Introduction to FLock.io
    • The Centralisation Problem
    • Architectural Breakdown
      • System Design
      • Blockchain Layer
      • AI Layer
  • ❤️‍🔥FLock Products
    • AI Arena
      • Participants
      • Quickstart
        • Pre-requisites
          • WSL installation
        • gmFLOCK
        • Delegator Guide
        • Training Node Guide
        • Validator Guide
      • Task Lifecycle Deep-dive
      • Smart Contracts Deep-dive
    • FL Alliance
      • Participants
      • Components
      • Task Lifecycle Deep-dive
        • 1. Staking and Role Assignment
        • 2. FL Training
        • 3. FL Aggregation and Evaluation
        • 4. Rewards
      • Smart Contracts Deep-dive
      • FL Client
        • Pre-Requsites
        • Steps to Quickstart
      • FLocKit
    • AI Marketplace
      • Quickstart
        • Getting started Manual creation
        • Guideline Manual
        • Model API guide
        • Tutorials
          • Create a discord bot with Model API
          • Farcaster Frames with Model API
      • Participants
      • Deep-dive
        • Function breakdown
        • RAG
        • Contribution Mechanism
        • Roadmap
    • 2025 Roadmap
  • 💰FLOCK TOKENOMICS
    • Overview
      • Incentivising open source model development
      • Security
    • Token Utility
      • Supply
      • Demand
    • Network Participation
      • AI Arena
        • Task Creator
        • Data Provider
        • Training Node
        • Validator
        • Delegator
        • Delegation Pool Rewards Explainer
      • FL Alliance
        • Task Creator
        • FL Nodes
      • AI Marketplace
        • Model Host
    • Token Allocations
    • Airdrop
    • Contract Details
  • 💻FLock Use-Cases
    • AI-assisted Coding - FLock x Aptos LLM (outperforms ChatGPT-4o!)
    • AI Assistants - Farcaster GPT, Scroll GPT and many more to come!
    • AI Companions - Professor Grump w/ Akash
    • Web3 Agents - Text2SQL Agent
    • Privacy-preserving Healthcare
  • 📃Resources
    • Litepaper
    • Whitepaper
    • Publications
    • Glossary
    • FAQ
    • Social Media
    • Careers
    • Terms Of Use
    • Privacy Policy
    • FLock.io-Verified Developers
    • FLOCK Token Airdrop Terms and Conditions
Powered by GitBook
On this page

Was this helpful?

  1. FLock Products
  2. AI Marketplace
  3. Quickstart

Model API guide

Model Guide for you to implement FLock model

PreviousGuideline ManualNextTutorials

Last updated 1 year ago

Was this helpful?

Pre-requirement

Manual creation via website

  • Generate API Key via

  • Create Model via

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?");
❤️‍🔥
Acquiring the API Key
  • Pre-requirement
  • Manual creation via website
  • Technology Stack
  • API Call example
  • POSTConversational Rag Chat
  • How it Works
  • Setup
  • .env
  • Step by Step guide

Conversational Rag Chat

post

RAG chat with a conversation history.

Authorizations
Body
questionstringRequired
chat_historyany ofOptionalDefault: []
or
knowledge_source_idstringRequired
Responses
200
Successful Response
application/json
422
Validation Error
application/json
post
POST /chat/conversational_rag_chat HTTP/1.1
Host: 
x-api-key: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 74

{
  "question": "text",
  "chat_history": [
    [
      "text"
    ]
  ],
  "knowledge_source_id": "text"
}
{
  "answer": "text",
  "source_docs": [
    []
  ],
  "generated_question": "text"
}
Model Customisation