Introduction
- playgroundโ You can see the demo code on the playground.
Set up a fully functional Reddit Agent powered by OpenAIโs GPT model quickly using the Agentica CLI.
Quick CLI Setup
Launch the Agentica Setup Wizard with a single command:
npx agentica start reddit-agent
The wizard guides you through:
- Installing required packages (e.g., [email protected])
- Choosing your package manager and project type
- Selecting the REDDIT controller
- Entering your
OPENAI_API_KEY
Once complete, Agentica automatically generates your code, creates a .env
file, and installs all dependencies.
Generated Code Overview
The generated code looks like this:
import { Agentica } from "@agentica/core";
import typia from "typia";
import dotenv from "dotenv";
import { OpenAI } from "openai";
import { RedditService } from "@wrtnlabs/connector-reddit";
dotenv.config();
const agent: Agentica<"chatgpt"> = new Agentica({
model: "chatgpt",
vendor: {
api: new OpenAI({ apiKey: process.env.OPENAI_API_KEY! }),
model: "gpt-4o-mini",
},
controllers: [
{
name: "Reddit Connector",
protocol: "class",
application: typia.llm.application<RedditService, "chatgpt">(),
execute: new RedditService({
secret: process.env.REDDIT_SECRET!,
clientSecret: process.env.REDDIT_CLIENT_SECRET!,
clientId: process.env.REDDIT_CLIENT_ID!,
}),
},
],
});
const main = async () => {
console.log(await agent.conversate("What can you do?"));
};
main();
This code instantly sets up your Reddit Agent, ready to intelligently interact with Reddit.
What This Does
Your Reddit Agent will:
-
Interact with Reddit using the
Reddit
connector. -
getHotPosts
- Fetch the most popular posts. -
getNewPosts
- Retrieve the latest posts. -
getTopPosts
- Get top-ranked posts. -
flatComments
- Fetch comments for a specific Reddit post. -
getComments
- Retrieve comments for a specific Reddit post. -
getUserAbout
- Fetch user information. -
getUserSubmitted
- Retrieve posts submitted by a user. -
getUserComments
- Get comments made by a user. -
searchSubreddits
- Search for subreddits. -
getSubredditAbout
- Retrieve subreddit details. -
getPopularSubreddits
- Fetch a list of popular subreddits. -
getBaseContent
- Retrieve base content. -
Leverage OpenAIโs GPT model for intelligent Reddit queries.
-
Ensure type safety with
typia
. -
Securely manage credentials using
dotenv
.
Just set up your environment variables in a .env
file:
OPENAI_API_KEY=your_openai_api_key
REDDIT_SECRET=your_reddit_refresh_token
REDDIT_CLIENT_SECRET=your_reddit_client_secret
REDDIT_CLIENT_ID=your_reddit_client_id
To get these credentials:
- Create a Reddit App:
- Visit this linkโ to create a Reddit App.
- Create a Reddit App to get your
REDDIT_CLIENT_ID
andREDDIT_CLIENT_SECRET
.
- Obtain Refresh Token:
- Generate a refresh token to get your
REDDIT_SECRET
.
Use Case Example
Imagine you want to create a Reddit Agent that can:
โFind the top posts in the r/Programming subreddit.โ
Your Reddit Agent can easily handle this request and provide you with the most upvoted posts in the r/Programming subreddit.
Available Functions
For a complete list of available functions in RedditService
, check out the source code:
๐ wrtnlabs/connectors - RedditService.tsโ
Your AI-powered Reddit Agent is ready to go! ๐