Farcaster Frames with Model API
Video Tutorial
Welcome to this tutorial where we will walk you through the process of creating a Farcaster Frame and communicating with a FLock.io RAG API. This is a comprehensive guide that will give you the confidence to create, modify, and enhance your Farcaster Frames with FLock API.
What you will learn:
How to create a Farcaster Frame
Communicate with FLock RAG API.
Technology Stack
TypeScript
Frog framework
What is Frame?
A Frame is a tool for creating interactive, authenticated apps on Farcaster, allowing features like polls, live feeds, or galleries within Warpcast and other FC clients. Frames enhance the OpenGraph standard, transforming static embeds into interactive experiences.
What is Frog framework?
Frog is a framework built on top of Hono for building Farcaster Frames.
The documentation: Getting started
How it Works
Setup
Install Frog Framework
Create a Bot from the AI Co-Creation platform, where you can follow the guide.
Install the API related package.
We will be using the
default
template, feel free to export other ones in the future.
File structure
Pages will stay in our router
FLock API will stay in the utils
Logic flow
We will have one page
Default page - react on user’s input
This is a very simple and general approach of how we can use frame with FLock Chat Bot.
API
Now create a folder under src
called api
within the utils
folder create a file called flock-api.ts
this is the place where your api will sit. And here is the code you can use directly.
Next create a .env
file in the root directory of the project, and add following
Useful tools for OG image
I personally think that the Vercel OG image playground is a convenient tool to quickly check up on your OG image. So, do utilise it!
Page Structure
Before diving in, let's first understand the structure of a ‘frame’. A frame consists of two components: the image and the intents.
The image is where your visuals are displayed
The intents handle interactions, including text input, button reactions, and the new transaction operations.
Image
Here we use status condition to show the content, if status is response, we will show the question and answer. Otherwise, the user will only see “Lets chat about FLock”
Intent
Here we have created three intents
TextInput
- for questions to be asked to the botButton
- for the interactionButton
- for reset after receiving the response
Main logic flow
In this section, we establish the logic to respond to both user input and an API call.
Initially, we extract values from the object c
(representing context), which provides the current state or frame:
buttonValue
- the value assigned to a button,inputText
- the text entered by the user,status
- the status of the context within its lifecycle.
Next, we initialise two constants, prompt
and modelId
, using the extracted inputText
and buttonValue
respectively. This sets up the parameters we need for the subsequent API call.
We then employ an if
statement to check whether either prompt
or modelId
is undefined. This validation is crucial as it ensures that we have the necessary data before proceeding.
Finally, we use a try-catch
structure to manage the asynchronous function chatFlockBot
. This function is called with prompt
and modelId
as arguments. The try
block executes the function, and should any errors occur during the API call, the catch
block captures these exceptions and sets an error message.
Run the test
Now you have completed the setup of the frame. Let’s test it in the local environment.
Go to http://localhost:5137/dev
You will see the following page
The history of access
URL tab - similar to web browser URL tab
Metadata of current frame
Live frame interact
Request/Context/Metadata information
Request/Context/Metadata information
Now you can start typing the questions and chat with the frame!
Deploy your frame
I recommend deploying your project using Vercel. You can easily deploy it by connecting your GitHub account and pushing your project to a repository.
Next, all you need to do is copy your deployed link and post it in any Farcaster Client.
Please tag us when you post the cast! “/flock-io”
Lastly here is the GitHub Repository!
https://github.com/FLock-io/FLock-AI-Demo/tree/main/FLOCK-RAG-FRAME-React
Reach out to us by Website: https://flock.io/ Twitter: https://twitter.com/flock_io Telegram: https://t.me/flock_io_community Discord: https://discord.gg/ay8MnJCg2W Farcaster: https://warpcast.com/~/channel/flock-io
Last updated