bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 16쪽 중 4쪽
ocal validation score, which functions as a criterion for assessing the model’s performance. These individual validation scores
are then submitted to a smart contract for aggregation. Following the aggregation, the aggregated score is compared with the previous round’s score, to assess progress or decline in model performance. The smart contract then determines the next steps for the aggregated model based on these scores: if there is an improvement in performance score, the system will proceed to the next phase of training; if there is a decline, another round of training, aggregation and evaluation will begin using the validated model from the previous round. 
After receiving all reported voting results from the voters, the aggregator (any participant can call the function through the smart contract) will calculate the aggregated voting result.
<br>
# 4. Rewards
At each round, the aggregated voting result will also determine the rewards distribution for participants in a FL Alliance task. At any given round, if the aggregated vote is non-negative, all proposers will receive rewards (the reward amount depends on their stake amount). Conversely, if the aggregated vote is negative, staked tokens of all proposers for that round will be slashed. 
As for voters, if the aggregate vote is non-negative, those who voted with a non-negative score will be rewarded (again, the reward amount depends on their stake amount), and those who voted with a negative score will be slashed. Conversely, if the score is negative, those who voted with negative will be rewarded, or slashed otherwise. 
<br>
# Smart Contracts Deep-dive
This page gives detailed explanation of FL Alliance's smart contracts.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FCnuXpd82O6ifzSBw9Pp1%2FFL_Alliance_v3.png?alt=media&token=9955b273-7ec2-45ff-aaed-b67f467e0066" alt=""><figcaption><p>FL Alliance Smart Contract Interactions.</p></figcaption></figure>
## Core Contracts
### `FlockTaskManager.sol`
**Role:** Factory and lifecycle controller for all `FlockTask` instances.
* **Task Creation**: Deploys new `FlockTask` contracts, passing in initial parameters like `_totalNumberOfRounds`, `_minStakeThreshold`, `_initialRewardPoolSize`, etc.
* **Task Management**: Maintains a list (via `EnumerableSet`) of active or unfinished `FlockTask` addresses.
* **Finish Task**: The owner can mark a task as `finished` if necessary (`finishTask(...)`), removing it from the active set.
### `FlockTask.sol`
**Role:** This contract implements a decentralized and scalable model for round-based federated learning (“FL tasks”).
* **Staking & Roles**: Participants stake tokens to become eligible to join rounds, where they are randomly assigned roles (proposers, voters).
* **Proposal & Voting Rounds**: Each round, selected proposers submit model updates, and voters commit/reveal votes that determine the most popular model via stake-weighted voting.
* **Rewards & Slashing**: Well-behaved participants (correct contributions/votes) receive rewards; dishonest behaviors can be “slashed,” losing a percentage of their stake.
## Libraries
### `LibABDKMathQuad.sol`
**Role**: Quadruple-precision (128-bit) math operations.
* Implements IEEE 754–style floating-point arithmetic for `bytes16` values.
* Provides precision far beyond typical fixed-point or 256-bit integer math.
* Useful for advanced computations like logarithms, exponentials, or rational approximations.
### `LibFlockTask.sol`
Role: Provides specialized numeric and utility functions for federated-learning tasks. Key Functions include:
* **`mulDiv`(uint256 x, uint256 y, uint256 z)**
* Combines multiplication and division with quadruple precision by leveraging `LibABDKMathQuad`.
* `rand`()
* Generates a pseudo-random number by hashing block and transaction properties.
# FL Client
This page gives instructions for running a FL client node.
<br>
# Pre-Requsites
1. Python version >= 3.11
2. Docker
3. Anaconda
4. Make
5. FLOCK - FLock’s native token is required for staking. You can check out the contract [here](https://sepolia.basescan.org/address/0xeF39985160FEdd389B46E6dB14d6aEa26cb5981A).
6. Base Sepolia ETH - our testnet is deployed on Base Sepolia. You need Base Sepolia ETH to cover gas costs. If you don’t have Base Sepolia ETH, you can get some from the [Alchemy Faucet](https://www.alchemy.com/faucets/base-sepolia).
Note that dependant on the task, there is specific hardware requirements. For LLM fine-tuning tasks, you need at least `GPU` with at least `12GB` memory.
# Steps to Quickstart
1. Download the client
```bash
git clone https://github.com/FLock-io/FL-Alliance-Client.git
```
2. Prepare Docker
```bash
sudo groupadd docker
sudo usermod -aG docker $USER
```
3. Initialise and activiate a new conda environment
```bash
conda create -n flock_client python==3.11
source activate flock_client
```
4. Install dependencies
```
cd FL-Alliance-Client
pip install -r requirements.txt
```
5. Prepare the Makefile
* Navigate to Makefile at the root folder
* Replace `TASK_ADDRESS` with the address of the task that you intend to join.
* Replace `YOUR_ALCHEMY_API_KEY` with your Alchemy API key.
* Replace `YOUR_PRIVATE_KEY` with your private key. Ensure that this wallet contains $FML as well as Base Sepolia ETH. Please protect your private key and do not publish it to Github for instance.
* Put the data you intent to train with to this repo. Then, replace `YOUR_PATH_TO_DATA` with the path to your datasets.
6. Build and run the client
```bash
make build
make start
```
# FLocKit
Coming soon :smile:
# AI Marketplace
Guide to beta.flock.io, where AI models can easily be co-created by the community
AI Marketplace is a space where people come together to build, improve, and use models.
It focuses on spreading the work out (decentralisation) and getting everyone stuck in (community engagement). It allows users to propose models, contribute data, and utilise these models in various applications.
FLock invites you to propose models, contribute data and idle resources, evaluate models, refine data, and utilise these models in various applications.
FLock’s library ranges from intelligent agents to sophisticated trading and confluence bots. It enables external database integration, and RAG enhances domain-specific accuracy.
One use case is BTC-GPT, which has reached 10k model calls.
# Quickstart
Follow the steps in the following sections to participate in AI Marketplace. 
# Getting started Manual creation
Guide to API Key and Model Creation for Hackathons
{% hint style="success" %}
Try out our Beta: [This way](https://beta.flock.io)!
{% endhint %}
## Acquiring the API Key
To embark on model creation, the initial step involves generating an API Key. Follow the OpenAPI standard command below:
* Generate API Key
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FA60fM6z9iB8mvh82Rm7P%2FScreenshot%202024-03-08%20at%209.24.22%E2%80%AFPM.png?alt=media&token=e61892be-8feb-4392-805c-95483deb77a2" alt=""><figcaption></figcaption></figure>
* Click the "Generate the API Key"
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FVex7WIgGurZXPBnbBMOI%2FScreenshot%202024-03-08%20at%209.32.57%E2%80%AFPM.png?alt=media&token=a99d7d67-0c4b-4574-8a69-e0c7648c2c24" alt=""><figcaption></figcaption></figure>
* You can copy your API key now
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FUfpu66N7xI25azNlvnro%2FScreenshot%202024-03-08%20at%209.35.15%E2%80%AFPM.png?alt=media&token=50640bb3-c6b7-4791-868d-e451a1bf851d" alt=""><figcaption></figcaption></figure>
# Guideline Manual
Our step-by-step guide will walk you through each function of the platform, including model customisation, knowledge contribution, quality assurance, and model evaluation.
## Model Customisation
Create your own chatbot by following these steps:
* Connect your Wallet
* Go to the co-creation page.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FY5cMTYD8vL2LCTSQiklv%2FScreenshot%202024-03-08%20at%209.27.09%E2%80%AFPM.png?alt=media&token=c356513f-ac93-4836-acef-55d09ee7020a" alt=""><figcaption></figcaption></figure>
* In the top right corner, you will find a button labeled "Create new model." Click on the button, and a pop-up will appear.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2F6jeftElaGuaLT999NpgJ%2FScreenshot%202024-01-15%20at%203.01.23%20PM.png?alt=media&token=8a265c9d-3774-47d4-a65b-5534464abab2" alt=""><figcaption></figcaption></figure>
* When you open the pop-up, you'll see an example of how the data is organized. It's important to have documents that are closely related to each other to improve the accuracy of the model. Make sure to review and adjust the documents to ensure they are relevant and coherent, which will help enhance the AI model's performance and effectiveness.
```
Model Name: flock test
Description: This is a test flock chat bot enables efficient explain on what is flock doing
Data Required: FLock related documentation
Example knowledge: Data for fine-tuning
```
| Parameter Name | Description |
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Model Name | The name for you Chat bot |
| Description | Tell us what is your chat bot going to do |
| Data Required | What data do you want |
| Example Knowledge | <p>The preset training document can be one of the following options. Users must contribute at least three verified knowledge documents in order to create a model:</p><ul><li>PDF, TXT</li><li>Raw text</li><li>Website links</li></ul> |
* PDF and TXT upload
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FSxsn1Scq2f9benAd8XYW%2FScreenshot%202024-01-15%20at%203.03.57%20PM.png?alt=media&token=5736d53c-d68b-4922-837f-343dadafb282" alt=""><figcaption></figcaption></figure>
* Raw text upload
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FfvhJpJV2dSKy3CGdJbyr%2FScreenshot%202023-12-21%20at%207.06.46%20PM.png?alt=media&token=19dad3b6-b9c9-4c47-aca5-4e2043ad4e26" alt=""><figcaption></figcaption></figure>
* Link upload
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FSjDDSwlzbtDtjVluH28X%2FScreenshot%202023-12-21%20at%207.07.30%20PM.png?alt=media&token=2cadfdd5-7e27-4e4c-867c-7f806fd280e9" alt=""><figcaption></figcaption></figure>
* After the clicking the “Create” we will validate the data you submitted.After clicking the "Create" button, we will validate the data you submitted.
* The success page
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FilYJQ0p2KSnr8xOqIHeJ%2FScreenshot%202024-01-15%20at%203.05.59%20PM.png?alt=media&token=a88e9d46-c356-4f61-b5ae-36af9f24e2a5" alt=""><figcaption></figcaption></figure>
* To check the model status, you can go to “My models” for more status.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2F92228sAX9QMFPEjPmG0b%2FScreenshot%202024-01-19%20at%204.54.25%20PM.png?alt=media&token=4e8b12fa-7ba0-4c2b-9e50-01a91535b916" alt=""><figcaption></figcaption></figure>
### Knowledge Contribution
This interaction allows the user to continuously provide information to the model for accuracy and improvement of the knowledge base. Here, you can truly experience how co-creation can be achieved!
* Select a model and click the "Contribute Knowledge" button.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2Fy8zJ79HrcqLhlIBdwMTp%2FScreenshot%202024-01-15%20at%203.09.08%20PM.png?alt=media&token=1b47b513-1223-4cce-a9cc-315cc3bff53a" alt=""><figcaption></figcaption></figure>
* Before contributing knowledge, please carefully read the "Data Required" field.
* Each person can contribute documents in any of the following formats:
* PDF,TXT
* Raw text
* Website links
* After selecting the document, click "Complete" to proceed.
* The data validation process will approximately take 1 minute to complete.
* You can always check the progress of your data contribution in the "My Model" section.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2F8Oit8YDi75k5dXyRElh0%2FScreenshot%202024-01-15%20at%203.13.28%20PM.png?alt=media&token=3d6fb8e1-7f97-4e84-9d90-5970532b1932" alt=""><figcaption></figcaption></figure>
* Similarly, you can go to "My Models" and check the points allocation.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FjqZU587VJQp3olMhZdvO%2FScreenshot%202024-01-15%20at%203.06.06%20PM.png?alt=media&token=6d1dc30e-12b3-4176-a5bf-0fb14fb43124" alt=""><figcaption></figcaption></figure>
### Quality Assurance
Quality assurance is crucial in evaluating and refining the knowledge base to ensure its alignment with specific use cases. To recognize their valuable contributions, we have implemented a reward system to incentivize and appreciate their efforts. By voting on the data sources, we can assess and acknowledge their contributions, ensuring they are duly recognized and rewarded.
* Click on the Preview button; here, we will list out all the data sources contributed to the chatbot.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FXTtLB6FpgE2ePIT71yYY%2FScreenshot%202024-01-19%20at%204.49.58%20PM.png?alt=media&token=27c2fc99-7151-490a-8b18-30b8d6c96429" alt=""><figcaption></figcaption></figure>
* You can preview the data source to validate the data.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FF0a9uLx84rco4emZOc2f%2FScreenshot%202024-01-19%20at%204.50.06%20PM.png?alt=media&token=9c23090c-61ac-4274-b76f-686ffea3c9b4" alt=""><figcaption></figcaption></figure>
* You can then vote the data source in terms of the quality
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2F7lyKgAev25Grfkkmx6l2%2FScreenshot%202024-01-19%20at%204.49.48%20PM.png?alt=media&token=ea9f6c70-77dc-4b78-a683-f21f6d3467db" alt=""><figcaption></figcaption></figure>
### Model Evaluation
Evaluate the model and interact with the AI agent to assess the performance and accuracy of the RAG-enhanced LLM by chatting with the chatbot. You can test if the bot has learnt all the data we contributed or not. Each user can chat with the bot **10** **times per day** free of charge. 
* Simply click on the Chat button
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FMgtt6rfQR1Ghx1jDGoIo%2FScreenshot%202024-01-19%20at%204.52.30%20PM.png?alt=media&token=4e0a20a1-7c3d-4bb9-820f-d8b09a73311d" alt=""><figcaption></figcaption></figure>
<div data-full-width="true"><figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2FXoYUnEiFBOEBs8uS3yXb%2FScreenshot%202024-01-15%20at%203.14.06%20PM.png?alt=media&token=4181be70-399c-4124-b5a6-040dadfd06da" alt=""><figcaption></figcaption></figure></div>
Feel free to ask any questions or seek information about the data provided. For instance, the bot has been trained on a wide range of information concerning FLock. So, don't hesitate to ask anything related to FLock and its associated topics.
<figure><img src="https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2F7PZle7l5eCl1tkIn1d21%2FScreenshot%202024-01-15%20at%203.14.23%20PM.png?alt=media&token=b2fbf9da-a93c-4098-b232-146203b9af1f" alt=""><figcaption></figcaption></figure>
# Model API guide
Model Guide for you to implement FLock model
## Pre-requirement
### Manual creation via website
* Generate API Key via [Getting started Manual creation](/flock-products/ai-marketplace/quickstart/getting-started-manual-creation#acquiring-the-api-key)
* Create Model via [Guideline Manual](/flock-products/ai-marketplace/quickstart/guideline-manual#model-customisation)
## Technology Stack
* TypeScript
* JavaScript
### API Call example
{% openapi src="/files/HzQjrXbSg6zuB7V3ac3M" path="/chat/conversational\_rag\_chat" method="post" %}
[openapi.json](https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2Fd7duzxHXRu3ZnLBllCJP%2Fopenapi.json?alt=media\&token=3e2b3b87-7de2-4e11-9ce6-021eac3a97e2)
{% endopenapi %}
## How it Works
### Setup
#### Package installation
```bash
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.
<pre class="language-tsx"><code class="lang-tsx">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
<strong> const response = await axios.post(
</strong> `${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?");
</code></pre>
# Tutorials
In the following sections, you can follow our tutotirals to participate in AI Marketplace. 
# Create a discord bot with Model API
## Introduction
This tutorial guides you through the process of creating a Discord bot powered by the FLockRAG model. The bot can respond intelligently to user queries and automate tasks within the server. 
### What You Will Learn
* Learn how to create a chatbot on FLock’s AI Co-Creation platform
* How to create a simple chat bot on discord
* 프로젝트로 돌아가기