From 5d7bd1b4e1f1a44d716748e88fdbdde1ca9e1b60 Mon Sep 17 00:00:00 2001 From: Madhu Date: Wed, 2 Jul 2025 21:12:50 +0530 Subject: [PATCH] fixes: tic tae toe --- .../ai_tic_tac_toe_agent/README.md | 31 +++++++----- .../ai_tic_tac_toe_agent/app.py | 49 ++++++++++++++++++- 2 files changed, 68 insertions(+), 12 deletions(-) diff --git a/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/README.md b/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/README.md index 8ba563e..42f4a7f 100644 --- a/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/README.md +++ b/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/README.md @@ -23,7 +23,7 @@ This example shows how to build an interactive Tic Tac Toe game where AI agents ```bash # Clone the repository git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git - cd ai_agent_tutorials/ai_tic_tac_toe_agent + cd advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent # Install dependencies pip install -r requirements.txt @@ -35,19 +35,28 @@ This example shows how to build an interactive Tic Tac Toe game where AI agents pip install -r requirements.txt ``` -### 3. Export API Keys +### 3. Setup API Keys -The game supports multiple AI models. Export the API keys for the models you want to use: +The game supports multiple AI models. Create a `.env` file in this directory and add your API keys: -```shell -# Required for OpenAI models -export OPENAI_API_KEY=*** +1. **Create a `.env` file:** + ```bash + # In the ai_tic_tac_toe_agent directory + touch .env + ``` -# Optional - for additional models -export ANTHROPIC_API_KEY=*** # For Claude models -export GOOGLE_API_KEY=*** # For Gemini models -export GROQ_API_KEY=*** # For Groq models -``` +2. **Add your API keys to the `.env` file:** + ```env + # Required for OpenAI models (gpt-4o, o3-mini) + OPENAI_API_KEY=your_actual_openai_api_key_here + + # Optional - for additional models + ANTHROPIC_API_KEY=your_actual_anthropic_api_key_here # For Claude models + GOOGLE_API_KEY=your_actual_google_api_key_here # For Gemini models + GROQ_API_KEY=your_actual_groq_api_key_here # For Groq models + ``` + + > **Note:** Replace the placeholder values with your actual API keys. The app will show helpful error messages if required keys are missing. ### 4. Run the Game diff --git a/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/app.py b/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/app.py index 17faeff..32e0429 100644 --- a/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/app.py +++ b/advanced_ai_agents/autonomous_game_playing_agent_apps/ai_tic_tac_toe_agent/app.py @@ -1,5 +1,11 @@ import nest_asyncio import streamlit as st +from dotenv import load_dotenv +import os + +# Load environment variables from .env file +load_dotenv() + from agents import get_tic_tac_toe_players from agno.utils.log import logger from utils import ( @@ -25,6 +31,20 @@ st.markdown(CUSTOM_CSS, unsafe_allow_html=True) def main(): + #################################################################### + # Check for required API keys + #################################################################### + required_keys_info = { + "gpt-4o": "OPENAI_API_KEY", + "o3-mini": "OPENAI_API_KEY", + "claude-3.5": "ANTHROPIC_API_KEY", + "claude-3.7": "ANTHROPIC_API_KEY", + "claude-3.7-thinking": "ANTHROPIC_API_KEY", + "gemini-flash": "GOOGLE_API_KEY", + "gemini-pro": "GOOGLE_API_KEY", + "llama-3.3": "GROQ_API_KEY", + } + #################################################################### # App header #################################################################### @@ -69,13 +89,40 @@ def main(): key="model_p2", ) + ################################################################ + # API Key validation + ################################################################ + missing_keys = [] + for model in [selected_p_x, selected_p_o]: + required_key = required_keys_info.get(model) + if required_key and not os.getenv(required_key): + missing_keys.append(f"**{model}** requires `{required_key}`") + + if missing_keys: + st.error(f""" + 🔑 **Missing API Keys:** + + {chr(10).join(f"• {key}" for key in missing_keys)} + + **To fix this:** + 1. Create a `.env` file in this directory + 2. Add your API keys: + ``` + OPENAI_API_KEY=your_key_here + ANTHROPIC_API_KEY=your_key_here + GOOGLE_API_KEY=your_key_here + GROQ_API_KEY=your_key_here + ``` + 3. Restart the app + """) + ################################################################ # Game controls ################################################################ col1, col2 = st.columns(2) with col1: if not st.session_state.game_started: - if st.button("▶️ Start Game"): + if st.button("▶️ Start Game", disabled=bool(missing_keys)): st.session_state.player_x, st.session_state.player_o = ( get_tic_tac_toe_players( model_x=model_options[selected_p_x],