Model API guide
Model Guide for you to implement FLock model
Pre-requirement
Manual creation via website
Generate API Key via Acquiring the API Key
Create Model via Model Customisation
Technology Stack
TypeScript
JavaScript
API Call example
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"
}
How it Works
Setup
Package installation
npm install --save axios dotenv
# or
yarn add axios dotenv
# or
pnpm add axios dotenv
.env
.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
functionflockModel
wrapping the API calluse
axios.post
method for requestWe 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
Was this helpful?