Cookie Consent by Free Privacy Policy Generator Aktuallisiere deine Cookie Einstellungen ๐Ÿ“Œ User Story EP1 : How Alex Built His First GPT Action from Scratch๐ŸŽ‰


๐Ÿ“š User Story EP1 : How Alex Built His First GPT Action from Scratch๐ŸŽ‰


๐Ÿ’ก Newskategorie: Programmierung
๐Ÿ”— Quelle: dev.to

This article comes from User @ Alex Liu,big shoutout to ALEX for an incredible share! ๐ŸŒŸ
Calling all users to join in and share your stories too! ๐Ÿ“š
We have awesome gifts worth up to $200 waiting for those with amazing tales to tell! ๐ŸŽ

Recently, with some free time on my hands, I developed a cool GPT Action using MarsCode. It allows querying of information on popular GitHub projects. It's been quite enjoyable, so I thought I'd share my development process and insights.

(how it worksโ†‘)

About GPT Actions: You can think of them as handy little helpers powered by AI, capable of fetching all sorts of information for you. For more details, check out "Actions in GPTs."
Developing GPT actions may require an IDE, deployment platform, and API testing tools, among others. That's why I opted for MarsCode โ€“ it offers a one-stop solution, allowing me to quickly create a development project and streamline the development of GPT Actions.

Alright, let's take a look at my entire development process

Step1: Designing GPT Actions

This is where you get to brainstorm what you want your GPT to do. For mine, I wanted it to scour GitHub Trending for hot projects based on programming language and time frame. Here's what I came up with for inputs and outputs:

  • Inputs: the programming language to search for the time frame for the search (e.g., daily, weekly, monthly)
  • Outputs: Project list, including project name, author, link, star count, and recent star increments.

Step2: Setting Up the Project

MarsCode makes this part a breeze. With its variety of ready-to-use development frameworks and templates, I was spoilt for choice. Since I'm more comfortable with Node.js, I opted for the Node.js for AI Plugin template.

Image description

(Clicking on "Create," I swiftly entered the project spaceโ†‘)

Image description
(The overall layout of MarsCode is quite similar to VS Code, so there wasn't much of a learning curve for me, as someone accustomed to using VS Code. BTW, I have to mention its theme โ€“ I really like it! It's a pity it's not open-source.๐Ÿ˜„โ†‘)

Step3 Development

For anyone diving into this template for the first time, it's a smart move to give the README a thorough read. Since it's a template project, sticking to the presets is the way to go.

In this template, each function file needs to export a function called handler that conforms to the following TypeScript definition:

export async function handler({ input, logger }: Args<Input>): Promise<Output> {
  const name = input.name || 'world';

  logger.info(`user name is ${name}`);

  return {
    message: `hello ${name}`
  };
}

When an HTTP request comes in, MarsCode executes this function and passes in input and logger. The logic for the action is written within the handler function, which provides several predefined TypeScript types:

  • Args: The arguments passed to MarsCode when executing the handler, including input and logger.
  • Input: The input of the HTTP request.
  • logger: This logs information, including methods like logger.info, logger.error, and logger.debug. These logs appear in the Runtime logs panel of the deployment dashboard and in the API Test's log panel.
  • Output: The output of the function.

After grasping all that, I jumped right into coding. I created github/searchTrending.ts under the api directory to fetch GitHub Trending data. Here's how I broke it down into 2 steps:

  1. Fetching GitHub Trending Page: I started by making a fetch request to https://github.com/trending to grab the page's HTML. Since MarsCode's Node.js version is v20.12.2, I could directly use fetch for network requests.
  2. Parsing HTML with cheerio: I had the HTML, I used cheerio to parse it and extract repo data like names, descriptions, and star counts.

Image description
(During the coding process, MarsCode AI Assistants were super helpful. They provided features like code auto-completion and generating code based on comments. The fields for the GitHubRepo interface were automatically inferred, making the whole process incredibly convenient. ๐Ÿ˜Žโ†‘)

Once the dependencies are installed, we can dive into writing the core logic of the plugin:

async function searchTrending(input: Input): Promise<GitHubRepo[]> {
  let url = 'https://github.com/trending';
  // You can filter by language and time period
  if (input.language) {
    url += `/${input.language}`;
  }
  if (input.since) {
    url += `?since=${input.since}`;
  }

  try {
    // Fetch the HTML from GitHub Trending.
    const response = await fetch(url);
    const body = await response.text();
    // Parse the HTML with cheerio to extract project information.
    const $ = cheerio.load(body);
    // Initialize the list for repository info.
    let repositoriesInfo = [];

    // Iterate over all <article class="Box-row"> elements on the page.
    $('article.Box-row').each(function () {
      const article = $(this);
      // Extract data.
      const name = article.find('h2.h3 a').text().trim();
      const url = 'https://github.com' + article.find('h2.h3 a').attr('href');
      const author = article.find('span.text-normal').text().trim().replace(' /', '');
      const stars = article.find('a[href*="/stargazers"]').last().text().trim().replace(/,/g, ''); // Remove commas from numbers.
      const todayStarsText = article.find('.d-inline-block.float-sm-right').text().trim();
      const todayStarsMatch = todayStarsText.match(/(\d+)/);
      const todayStars = todayStarsMatch ? parseInt(todayStarsMatch[0], 10) : 0;
      const language = article.find('[itemprop="programmingLanguage"]').text().trim();
      const description = article.find('p.color-fg-muted').text().trim();  Extract repo description

      repositoriesInfo.push({
        description,
        language,
        name,
        url,
        author,
        stars,
        todayStars
      });
    });

    return repositoriesInfo;
  } catch (error) {
    console.error('Error fetching data:', error);
  }
  return [];
}

Call the searchTrending function in the handler:
typescript
/**
 * Search the GitHub trending repos
 */
export async function handler({ input, logger }: Args<Input>): Promise<Output> {
  const projects = await searchTrending(input);

  return {
    projects,
  };
}

Now that we've wrapped up the main coding part, we can move on to testing this action. ๐Ÿš€

Step4: API test

(MarsCode offers a testing tool: API Test. In the API Test panel, you can input the parameters for the interface. Click "Send," and you can check the logs through the Output panel. ๐Ÿ”โ†‘)

Step5: Deployment

(Click the "Deploy" button at the top, enter the Changelog, and then click "Start." Your project will begin deploying, and you can monitor the deployment process through the logs. ๐Ÿš€โ†‘)

(After a successful deployment, you can view the service details through Service Detail. This includes the OpenAPI Schema, Bearer token, domain name, and more.โ†‘)

Final Step

For details on how to add the action to your ChatGPT, there's a document from MarsCode team Add an action to your ChatGPT. I won't go into it here, but you can refer to that for a step-by-step guide. ๐Ÿ“„๐Ÿค–

Some of my ideas

Even though this was my first time developing a GPT Action, I found MarsCode's custom solution pretty impressive overall. The process was smooth with hardly any hiccups. Moving forward, I'm considering developing more AI Bots to cover various other scenarios. If anyone has ideas, feel free to join in and let's create something awesome together! ๐Ÿš€

FYI : https://github.com/L-mofeng/marscode-github-trending-action

...



๐Ÿ“Œ User Story EP1 : How Alex Built His First GPT Action from Scratch๐ŸŽ‰


๐Ÿ“ˆ 110.39 Punkte

๐Ÿ“Œ 45sec scratch game vs 1min scratch game vs 10min scratch game


๐Ÿ“ˆ 39.11 Punkte

๐Ÿ“Œ โ€žWatching You โ€“ Die Welt von Palantir und Alex Karpโ€œ im Kino: Alex, bist du da?


๐Ÿ“ˆ 29.39 Punkte

๐Ÿ“Œ โ€žWatching You โ€“ Die Welt von Palantir und Alex Karpโ€œ im Kino: Alex, bist du da?


๐Ÿ“ˆ 29.39 Punkte

๐Ÿ“Œ 10 Secret GPT-4 Tips And Tricks (How To Use GPT-4)(GPT-4 Tutorial)


๐Ÿ“ˆ 28.03 Punkte

๐Ÿ“Œ Updates fรผr GPT-3 und GPT-4: GPT im Geschwindigkeitsrausch


๐Ÿ“ˆ 28.03 Punkte

๐Ÿ“Œ What does GPT stand for? Understanding GPT 3.5, GPT 4, and more


๐Ÿ“ˆ 28.03 Punkte

๐Ÿ“Œ GPT-6 SHOCKS Everyone With NEW ABILITIES! (GPT5, GPT-6, GPT-7) Document Reveals ALL!


๐Ÿ“ˆ 28.03 Punkte

๐Ÿ“Œ OpenAI: Keine Suche, kein GPT-5, aber GPT-4o fรผr ChatGPT und GPT-4


๐Ÿ“ˆ 28.03 Punkte

๐Ÿ“Œ The Evolution of the GPT Series: A Deep Dive into Technical Insights and Performance Metrics From GPT-1 to GPT-4o


๐Ÿ“ˆ 28.03 Punkte

๐Ÿ“Œ S2 Ep1: FaceApp, logic bombs and stranger danger โ€“ Naked Security Podcast


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ Installing Metasploitable 2 in VMware Player - Penetration Testing Lab ep1


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ Cybertalk - EP1 - Secure Coding, HackTheBox & Web App Penetration Testing


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ O.MG DemonSeed EDU - Ep1 - Intro


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ Motion Tags Ep1 - MotionLayout + MotionScene


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ S3 Ep1: Ransomware โ€“ is it really OK to pay? โ€“ Naked Security Podcast


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ Learn Git: Introduction to Git (Ep1)


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ Learn Microsoft Identity: Getting started with Microsoft Identity (Ep1)


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ A breakthrough unfolds - DeepMind: The Podcast (S2, Ep1)


๐Ÿ“ˆ 26.75 Punkte

๐Ÿ“Œ Medium CVE-2020-15164: Scratch-wiki Scratch login


๐Ÿ“ˆ 26.07 Punkte

๐Ÿ“Œ MIT Lifelong Kindergarten Scratch scratch-vm prior 0.2.0-prerelease.20200714185213 serialization/sb3.js deserialization


๐Ÿ“ˆ 26.07 Punkte

๐Ÿ“Œ Linux from scratch vs docker scratch?


๐Ÿ“ˆ 26.07 Punkte

๐Ÿ“Œ How Alex Rombak Uses His Hospitality Background to Provide Top Tier Technical Support


๐Ÿ“ˆ 25.03 Punkte

๐Ÿ“Œ How Alex Rombak Uses His Hospitality Background to Provide Top Tier Technical Support


๐Ÿ“ˆ 25.03 Punkte

๐Ÿ“Œ Doom Eternal: "Story"-Trailer ohne viel Story, dafรผr mit viel Action


๐Ÿ“ˆ 23.94 Punkte

๐Ÿ“Œ Iron Man Started His Journey From Scratch & Your Security Awareness Program Can Too


๐Ÿ“ˆ 23.37 Punkte

๐Ÿ“Œ Thunderbird's Alex Castellani: An Origin Story


๐Ÿ“ˆ 22.93 Punkte

๐Ÿ“Œ FIFA 19: Alex Hunter wechselt im Story-Modus The Journey zu diesem Topklub


๐Ÿ“ˆ 22.93 Punkte

๐Ÿ“Œ Void Linux: Built From Scratch for Full Independence


๐Ÿ“ˆ 22.66 Punkte

๐Ÿ“Œ A highly optimized and extremely lightweight Linux distribution built from scratch


๐Ÿ“ˆ 22.66 Punkte

๐Ÿ“Œ Finally built my own Linux from Scratch!


๐Ÿ“ˆ 22.66 Punkte











matomo