fixes: tic tae toe
This commit is contained in:
parent
b7a21406b1
commit
5d7bd1b4e1
2 changed files with 68 additions and 12 deletions
|
|
@ -23,7 +23,7 @@ This example shows how to build an interactive Tic Tac Toe game where AI agents
|
||||||
```bash
|
```bash
|
||||||
# Clone the repository
|
# Clone the repository
|
||||||
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git
|
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
|
# Install dependencies
|
||||||
pip install -r requirements.txt
|
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
|
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
|
1. **Create a `.env` file:**
|
||||||
# Required for OpenAI models
|
```bash
|
||||||
export OPENAI_API_KEY=***
|
# In the ai_tic_tac_toe_agent directory
|
||||||
|
touch .env
|
||||||
|
```
|
||||||
|
|
||||||
# Optional - for additional models
|
2. **Add your API keys to the `.env` file:**
|
||||||
export ANTHROPIC_API_KEY=*** # For Claude models
|
```env
|
||||||
export GOOGLE_API_KEY=*** # For Gemini models
|
# Required for OpenAI models (gpt-4o, o3-mini)
|
||||||
export GROQ_API_KEY=*** # For Groq models
|
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
|
### 4. Run the Game
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
import nest_asyncio
|
import nest_asyncio
|
||||||
import streamlit as st
|
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 agents import get_tic_tac_toe_players
|
||||||
from agno.utils.log import logger
|
from agno.utils.log import logger
|
||||||
from utils import (
|
from utils import (
|
||||||
|
|
@ -25,6 +31,20 @@ st.markdown(CUSTOM_CSS, unsafe_allow_html=True)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
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
|
# App header
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
@ -69,13 +89,40 @@ def main():
|
||||||
key="model_p2",
|
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
|
# Game controls
|
||||||
################################################################
|
################################################################
|
||||||
col1, col2 = st.columns(2)
|
col1, col2 = st.columns(2)
|
||||||
with col1:
|
with col1:
|
||||||
if not st.session_state.game_started:
|
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 = (
|
st.session_state.player_x, st.session_state.player_o = (
|
||||||
get_tic_tac_toe_players(
|
get_tic_tac_toe_players(
|
||||||
model_x=model_options[selected_p_x],
|
model_x=model_options[selected_p_x],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue