> For the complete documentation index, see [llms.txt](https://vity-toolkit.gitbook.io/vity-toolkit/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vity-toolkit.gitbook.io/vity-toolkit/examples/ai-bounty-finder.md).

# AI Bounty Finder

The AI Bounty Finder Agent, powered by Vity Toolkit and frameworks like Vercel AI, helps you to find bounty, projects, tasks, grants, etc from different platforms like Superteam Earn, Gibwork. It efficiently identifies and extracts bounty which falls under the user's interest and also even give more information about it.

## Prerequisites

You will need:

* Node JS v22.11.0 or higher
* OpenAI API Key

## Get Started

In this example, you will create your own Bounty Finder bot in less than 100 lines (it's true). It's really very to create it, just follow the tutorial properly.

{% stepper %}
{% step %}

### Create a folder and init your nodejs project

```bash
mkdir ai-bounty-finder && cd ai-bounty-finder
```

```bash
npm init -y
```

{% endstep %}

{% step %}

### Install the required packages

```bash
npm install vity-toolkit @ai-sdk/openai ai dotenv
```

{% endstep %}

{% step %}

### Environmental Variables

Paste your OpenAI API Key there.

<pre class="language-bash"><code class="lang-bash"><strong>export OPENAI_API_KEY=sk-**********
</strong></code></pre>

{% endstep %}

{% step %}

### Open the folder in vs code

```bash
code .
```

Open `index.ts`file and do as the below says.
{% endstep %}

{% step %}

### Importing required packages

```bash
import readline from "readline";
import { openai } from "@ai-sdk/openai";
import { streamText, type CoreMessage } from "ai";
import { App, VercelAIToolkit } from "vity-toolkit";
import { configDotenv } from "dotenv";

configDotenv();
```

{% endstep %}

{% step %}

### Initialize tools and define a variable for messages

```typescript
const toolKit = new VercelAIToolkit();
const messages: CoreMessage[] = []

// define the apps you want to use
const tools = toolKit.getTools({ apps: [App.EARN, App.GIBWORK] });
```

{% endstep %}

{% step %}

### Create the bot function

This function is responsible to take user prompt, pass it to agent and give the agent's response.

```typescript
const bot = async (prompt: string) => {
    try {

        messages.push({
            role: "user",
            content: prompt,
        })

        const result = streamText({
            model: openai("gpt-4o"),
            tools,
            maxSteps: 10,
            system: `Your name is Vity Bounty Finder. You have been made by Vity Toolkit. You are an AI agent responsible for taking actions on Superteam Earn and Gibwork on users' behalf. You need to take action on using their APIs. Use correct tools to run APIs from the given toolkit. Give them the bounties/grants/projects if it comes under there background or interest. Your response should be structured and look beatiful too as it will directly be shown to the user. Be concise and helpful with your responses.

            Note:
            - When you are giving links for bounties for Superteam Earn, make sure the link has: https://earn.superteam.fun/listings/bounty/*
            Usually it will not have '/bounty' slug but add it manually.
            `,
            messages,
        })

        let response = "";

        for await (const message of result.textStream) {
            console.clear();
            response += message;
            console.log("\nVity Bounty Finder: ", response);
        }

        const responseMessages = (await result.response).messages;
        responseMessages.forEach((msg: CoreMessage) => messages.push(msg));

    } catch (error) {
        throw error;
    }
}
```

{% endstep %}

{% step %}

### Create the main function

```typescript
const run = async () => {
    console.clear();

    console.log(`
    +----------------------------------------------+
    |          Welcome to Bounty Finder !          |
    +----------------------------------------------+
    `);

    try {
        const rl = readline.createInterface({
            input: process.stdin,
            output: process.stdout
        });
        const q = (prompt: string): Promise<string> =>
            new Promise((resolve) => rl.question(prompt, resolve));

        const userPrompt = (await q("What are your interests?\n> ")).trim();
        rl.close();
        await bot(userPrompt);

        while (true) {
            const rl2 = readline.createInterface({
                input: process.stdin,
                output: process.stdout
            });
            const q2 = (prompt: string): Promise<string> =>
                new Promise((resolve) => rl2.question(prompt, resolve));

            const userPrompt = (await q2("\nAnything else?\n> ")).trim();
            rl2.close();

            await bot(userPrompt);
        }

    } catch (error) {
        console.error("Failed to run the agent:", error);
        throw error;
    }

}
```

{% endstep %}

{% step %}

### Executing the Agent

```typescript
if (require.main === module) {
    run().catch((error) => {
        console.error("Fatal error:", error);
        process.exit(1);
    });
}
```

{% endstep %}

{% step %}

### Full code

```typescript
import readline from "readline";
import { openai } from "@ai-sdk/openai";
import { streamText, type CoreMessage } from "ai";
import { App, VercelAIToolkit } from "vity-toolkit";
import { configDotenv } from "dotenv";


configDotenv();

const toolKit = new VercelAIToolkit();
const messages: CoreMessage[] = []

// define the apps you want to use
const tools = toolKit.getTools({ apps: [App.EARN, App.GIBWORK] });


const bot = async (prompt: string) => {
    try {

        messages.push({
            role: "user",
            content: prompt,
        })

        const result = streamText({
            model: openai("gpt-4o"),
            tools,
            maxSteps: 10,
            system: `Your name is Vity Bounty Finder. You have been made by Vity Toolkit. You are an AI agent responsible for taking actions on Superteam Earn and Gibwork on users' behalf. You need to take action on using their APIs. Use correct tools to run APIs from the given toolkit. Give them the bounties/grants/projects if it comes under there background or interest. Your response should be structured and look beatiful too as it will directly be shown to the user. Be concise and helpful with your responses.

            Note:
            - When you are giving links for bounties for Superteam Earn, make sure the link has: https://earn.superteam.fun/listings/bounty/*
            Usually it will not have '/bounty' slug but add it manually.
            `,
            messages,
        })

        let response = "";

        for await (const message of result.textStream) {
            console.clear();
            response += message;
            console.log("\nVity Bounty Finder: ", response);
        }

        const responseMessages = (await result.response).messages;
        responseMessages.forEach((msg: CoreMessage) => messages.push(msg));

    } catch (error) {
        throw error;
    }
}


const run = async () => {
    console.clear();

    console.log(`
    +----------------------------------------------+
    |          Welcome to Bounty Finder !          |
    +----------------------------------------------+
    `);

    try {
        const rl = readline.createInterface({
            input: process.stdin,
            output: process.stdout
        });
        const q = (prompt: string): Promise<string> =>
            new Promise((resolve) => rl.question(prompt, resolve));

        const userPrompt = (await q("What are your interests?\n> ")).trim();
        rl.close();
        await bot(userPrompt);

        while (true) {
            const rl2 = readline.createInterface({
                input: process.stdin,
                output: process.stdout
            });
            const q2 = (prompt: string): Promise<string> =>
                new Promise((resolve) => rl2.question(prompt, resolve));

            const userPrompt = (await q2("\nAnything else?\n> ")).trim();
            rl2.close();

            await bot(userPrompt);
        }

    } catch (error) {
        console.error("Failed to run the agent:", error);
        throw error;
    }

}

if (require.main === module) {
    run().catch((error) => {
        console.error("Fatal error:", error);
        process.exit(1);
    });
}
```

{% endstep %}

{% step %}

### Run the program

```bash
npm run index.ts
```

{% endstep %}
{% endstepper %}

Congratulations :tada:, now you have your personal assistant to help you find your next winning opportunity. Start chatting with it :wink:.

{% embed url="<https://github.com/apneduniya/ai-bounty-finder>" %}
Full code
{% endembed %}

{% embed url="<https://youtu.be/NwmjiER3iNI>" %}
Demo video of AI Bounty Finder Agent
{% endembed %}
