Run this API to receive ability stats from PokeAPI, feed them into ChatGPT and let it tell you who would win Pokemon combat!

Name Variables

The default template assigns Charizard and Dragonite for the Pokemon A Nameand Pokemon B Name variable. Those variables will later be used in the HTTP request and ChatGPT input.

Change those name inputs to let other Pokemons to participate in combat.

HTTP Request

The HTTP action sends a request to a RESTful API of https://pokeapi.co/, returning information about Pokemon, their characteristics and abilities. The default template sends a request to:

https://pokeapi.co/api/v2/pokemon/{{steps.pokemon-a-name.value}}

We are placing {{steps.pokemon-a-name.value}} at the end of the request URL, which is the Variable we assigned in the previous step. This way, we will receive information about Charizardfrom the PokeAPI in the default template. To receive information about other Pokemon, we simply change the input in the variable Pokemon Name A.

In the second HTTP request we repeat the same process to receive information about Pokemon B.

Ability Variables

The HTTP request returns data about the Pokemon we provide it with. More specifically, it will provide an array with information of two of its abilities. We will assign a variable for that arraw in the following way:

We are interested in its abilities and will assign a Variable for it. We will put:

{{steps.pokemon-a.outputs.Body.abilities}} = Pokemon A Abilities.

An example for that array would be:

{
  "steps.pokemon-a-abilities.value": [
    {
      "ability": {
        "name": "blaze",
        "url": "https://pokeapi.co/api/v2/ability/66/"
      },
      "is_hidden": false,
      "slot": 1
    },
    {
      "ability": {
        "name": "solar-power",
        "url": "https://pokeapi.co/api/v2/ability/94/"
      },
      "is_hidden": true,
      "slot": 3
    }
  ]
}

We repeat the same process for Pokemon B Abilities.

ChatGPT

Since we assigned variables to the Pokemon names and abilities, we can provide ChatGPT with a standardized text input which will work for all Pokemon pairings.

We provide ChatGPT with the following:

Answer this question with the pokemon name and give a one sentence explanation:

Which Pokemon Would win in a battle of abilities between {{steps.pokemon-a-name.value}} with {{steps.pokemon-a-abilities.value.[0].ability.name}} , {{steps.pokemon-a-abilities.value.[1].ability.name}} VS {{steps.pokemon-b-name.value}} with {{steps.pokemon-b-abilities.value.[0].ability.name}},{{steps.pokemon-b-abilities.value.[1].ability.name}}?

Result

In the default version of the template, we display ChatGPTs answer in a success response:

{
  "winner": "{{steps.battle-simulator-gpt.outputs}}"
}

An example answer of ChatGPT could be:

{
  "winner": {
    "Content": "This battle could go either way depending on the circumstances, but under neutral conditions, Dragonite would likely win due to its Multiscale ability, which effectively halves the damage it takes when it’s at full health, giving it a significant initial advantage in battle."
  }
}

We have a lot of flexibility on what we do with this result eventually. We can turn it into a little app and display the result in a Frontend or send the result via Slack.

Modification

One modification you can apply to this template is to delete the Variables Pokemon Name A and Pokemon Name B from the route and rather provide those inputs through a request you send to this endpoint.

How to do it:

  1. Delete the name variable in the Fastgen route

  2. Change the ending of the request URL you send to PokeAPI, for example:

https://pokeapi.co/api/v2/pokemon/{{inputs.body.pokemona}}

and

https://pokeapi.co/api/v2/pokemon/{{inputs.body.pokemonb}}
  1. Change the ChatGPT name variable from

{{steps.pokemon-a-name.value}} and {{steps.pokemon-b-name.value}} to {{inputs.body.pokemona}} and {{inputs.body.pokemonb}}

  1. Now you can send a request to your Fastgen Pokemon endpoint with a body like:
{
 "pokemona": "Pikachu",
 "pokemonb": "Squirtle"
}

to execute the endpoint without manual changes of Pokemon names within the Fastgen route