Dev.to chatbot! 🤖
Tags: cozechallenge, devchallenge, ai, machinelearning
Published: 2024-04-28 20:50:58

*This is a submission for the [Coze AI Bot Challenge](https://dev.to/devteam/join-us-for-the-coze-ai-bot-challenge-3000-in-prizes-4dp7): Bot Innovator.*

## What I Built

I built dev.to chatbot! 🤓

The bot is able to search the content of our beloved website and answer our questions.

For example, you can ask him to send you an article on a specific topic, and he can also analyze the found content in terms of the information I am looking for! 🤓

I see that it has potential as an advanced search engine for website content!

To create the robot, I wrote a plugin for integration with the search engine and the dev.to API 🤗, more information in the journey section 🚂

## Demo

Link to bot: https://www.coze.com/store/bot/7358908091464794117

<!-- Share a link to your bot in the Coze Bot Store and include screenshots or recordings showcasing a user's chat interface with your bot. -->


## Your Configuration



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mt001rme7r38vem1ms95.png)



## Journey

It was an interesting task, initially it seemed much simpler, but in practice I got a little tired 😅

First of all, I want to mention that the coze.com platform is great! I had a lot of fun creating a bot or plugin is easy. I really like the built-in IDE for building the plugin, bravo! 👏

I was wondering about the use case for using the robot. Why would it be of value to anyone. I had a problem with this, but I decided to build a prototype to see how the AI ​​would use what I prepared. 🧑‍💻

At first I started using the "Browser" and "Google web search" plugins. However, the bot is unable to use the search engine on the dev.to website 😭 (it probably has problems with dynamically loaded content)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/appx4qunuahc06k5wkbl.png)

So I thought there must be some other way 🫰, I started searching for the API and found it 🥳

https://developers.forem.com/api/v1

The great joy was quickly extinguished by the fact that the API does not have a search engine 😭, there is an end for downloading published articles, but the results are completely different, and that's what I wanted. 🙋

Still looking for a solution, I started analyzing how the search engine works, guess what? I found that the search engine queries the endpoint underneath! 🥳 (not in the documentation 🫣)

```
https://dev.to/search/feed_content
```

Best of all, you can search not only articles but also users, podcasts, organizations, tags and comments! 🚀

At this point I already had the integration tool, but how do I integrate it with the chatbot? 🤖

The answer is a plugin! At the very beginning, I knew that I would need to prepare a simpler interface for the chatbot, so I immediately started working on a plugin built in the IDE. 🧑‍💻

Ultimately, it turned out that I would need:

- content search tools
- a tool to download article details (content), so that the chat bot can analyze the content in terms of the content I am looking for

However, along the way I created more tools, but these two remained as the most sensible ones.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8iqkjwvq5w9br2iwle05.png)

I needed to add some of my own code, for example to build an appropriate query to the search engine endpoint:


```js
const buildSearchQuery = async (input: Args<Input>['input']) => {
  let data: Record<string, string>  = {
    "class_name": objectTypeVales[input.object],
    "per_page": '60', // it's default value on dev.to. We want chatbot to use search like a user.
    "page": '0', // default value
    "search_fields": input.phrase
  };

  if (input.sort_by === 'newest') {
    data = {
      ...data,
      "sort_by": "published_at",
      "sort_direction": "desc",
    };
  }

  if (input.sort_by === 'oldest') {
    data = {
      ...data,
      "sort_by": "published_at",
      "sort_direction": "asc",
    };
  }
  
  const params = new URLSearchParams(data);
  const query = params.toString();

  return query;
}
```

After writing the code, a plugin for dev.to was created 🤓 -> https://www.coze.com/store/plugin/7362263649500741638

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e6c899u6z2z3mehqwoeb.png)

With connecting the plugin to my bot, I got an answer to a question that the previous bot was unable to answer. 🥳

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2n7vkjhp5ohm9hyl1y0f.png)

The last thing left to decide was which model to connect to the test:

- ChatGPT 3.5 -> quick replies, but unfortunately not very accurate
- ChatGPT 4 -> slower, responses much better. Unfortunately, there is too little context to analyze more content
- ChatGPT 4 turbo -> even slower, but gives the best results.

Finally, I set ChatGPT 4 Turbo, after testing it is the most practical for a chatbot.

I'm curious about your chatbot use! Is it practical for you? How can it be developed?

See you in the next challenge!