The Pokémon Battle Advisor is a web application designed to help Pokémon trainers strategize their battles by providing detailed and realistic battle recommendations. Users can specify their Pokémon team or randomize a team, and then receive tailored battle strategies based on their team and the opponent's Pokémon. The application leverages the CEREBRAS API to generate these recommendations, ensuring they adhere to official Pokémon game mechanics.
- Specify Your Pokémon Team: Users can enter the names of up to three Pokémon to include in their team.
- Randomize Pokémon Team: Users can opt to randomize their Pokémon team, fetching three random Pokémon from the PokéAPI.
- Challenger Pokémon Input: Users can enter the name of the opponent's Pokémon to receive a battle recommendation.
- Battle Recommendations: The app provides detailed battle strategies, including recommended Pokémon, strategies, and type advantages.
- Data Validation: Ensures that only valid Pokémon names are accepted, preventing random or incorrect names from being processed.
- Caching Mechanism: Uses in-memory caching to store fetched Pokémon data, reducing redundant API calls and improving performance.
- Responsive Design: The app is designed to be responsive, ensuring usability across various devices and screen sizes.
- Deno: This project is built using Deno, a secure runtime for JavaScript and TypeScript.
- Install Deno by following the instructions on the official website.
-
Fork the Repository:
-
Set Up Environment Variables: Create a
.env
file in the root directory and add your Cerebras API key:Note: Ensure that your Cerebras API key is kept secure and not exposed publicly.
-
Run the Application: Execute the following command to start the server:
deno run --allow-net --allow-env cerebras_try.ts--allow-net
: Grants network access needed for API calls.--allow-env
: Grants access to environment variables for the API key.
-
Access the Application: Open your browser and navigate to
http://localhost:8000
to view the Pokémon Battle Advisor.
- Enter the names of up to three Pokémon in the input fields provided.
- Click the "🎯 Load Specified Pokémon" button to fetch and display the specified Pokémon.
- Click the "🔀 Randomize Pokémon" button to fetch and display three random Pokémon.
- Enter the name of the opponent's Pokémon in the input field provided.
- Click the "🤖 Get Battle Recommendation" button to generate a battle strategy.
- The app will display a detailed battle recommendation, including recommended Pokémon, strategies, and type advantages.
-
cerebras_try.ts: The main TypeScript file that serves both the server and client-side code.
- Handles HTTP requests.
- Serves the HTML page containing the React application.
- Provides an API endpoint (
/api/cerebras-key
) to securely retrieve the Cerebras API key.
- Built using React.
- Manages the user interface, state management, and interactions.
- Fetches Pokémon data from the PokéAPI.
- Communicates with the OpenAI API but uses the CEREBRAS API to generate battle recommendations.
- App Component: The main React component that manages the state and logic for the application.
- validatePokemonData Function: Validates the structure and types of fetched Pokémon data.
- loadUserPokemons Function: Fetches and validates user-specified Pokémon.
- fetchRandomPokemon Function: Fetches and validates random Pokémon.
- generateBattleRecommendation Function: Generates battle recommendations using the OpenAI API.
- formatRecommendation Function: Formats the recommendation text into structured sections.
- Invalid Pokémon Names: If a user enters an invalid Pokémon name, an error message is displayed prompting the user to enter a valid name.
- API Errors: Any network or unexpected errors during API calls are caught, and corresponding error messages are displayed to the user.
- Missing API Key: The application checks for the presence of the Cerebras API key and notifies the user if it's missing or invalid.
- Deno: A secure runtime for JavaScript and TypeScript.
- React: For building the user interface.
- OpenAI API: For generating battle recommendations.
- PokéAPI: For fetching Pokémon data.
- TypeScript: For type safety and improved developer experience.
Contributions are welcome! Please follow these steps to contribute:
Relevant when I move it to github.
-
Fork the Repository: Click the "Fork" button at the top right of the repository page to create a copy of the repository under your GitHub account.
-
Clone Your Fork:
git clone https://github.com/yourusername/pokemon-battle-advisor.git cd pokemon-battle-advisor -
Create a New Branch:
git checkout -b feature/your-feature-name -
Make Your Changes: Implement your feature or bug fix.
-
Commit Your Changes:
git commit -m "Add your commit message here" -
Push to Your Fork:
-
Submit a Pull Request: Go to the original repository on GitHub and create a pull request from your forked repository.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or feedback, please contact cusp-aloft-brim@duck.com