Spaces:
Sleeping
Sleeping
comment
Browse files
app.py
CHANGED
|
@@ -56,53 +56,93 @@ def start_ladder_match(username: str = "MCPTrainer") -> dict:
|
|
| 56 |
"message": f"Failed to start ladder battle: {str(e)}"
|
| 57 |
}
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
@mcp.tool()
|
| 60 |
-
|
| 61 |
"""
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
agent_type (str): Type of agent ('openai', 'gemini', 'mistral', 'maxdamage', 'random')
|
| 65 |
-
username (str): Username for the MCP-controlled player
|
| 66 |
-
api_key (str, optional): API key for AI agents (required for openai, gemini, mistral)
|
| 67 |
-
model (str, optional): Specific model to use (will use default if not specified)
|
| 68 |
Returns:
|
| 69 |
-
dict:
|
| 70 |
"""
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
"
|
| 77 |
-
"
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
"status"
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
"
|
| 97 |
-
"
|
| 98 |
-
"
|
| 99 |
-
"
|
| 100 |
-
}
|
| 101 |
-
except Exception as e:
|
| 102 |
-
return {
|
| 103 |
-
"status": "error",
|
| 104 |
-
"message": f"Failed to start battle against agent: {str(e)}"
|
| 105 |
}
|
|
|
|
| 106 |
|
| 107 |
@mcp.tool()
|
| 108 |
def battle_player(opponent_username: str, username: str = "MCPTrainer") -> dict:
|
|
|
|
| 56 |
"message": f"Failed to start ladder battle: {str(e)}"
|
| 57 |
}
|
| 58 |
|
| 59 |
+
# @mcp.tool()
|
| 60 |
+
# async def battle_agent(agent_type: str, username: str = "MCPTrainer", api_key: str = None, model: str = None) -> dict:
|
| 61 |
+
# """
|
| 62 |
+
# Start a battle against an AI agent.
|
| 63 |
+
# Args:
|
| 64 |
+
# agent_type (str): Type of agent ('openai', 'gemini', 'mistral', 'maxdamage', 'random')
|
| 65 |
+
# username (str): Username for the MCP-controlled player
|
| 66 |
+
# api_key (str, optional): API key for AI agents (required for openai, gemini, mistral)
|
| 67 |
+
# model (str, optional): Specific model to use (will use default if not specified)
|
| 68 |
+
# Returns:
|
| 69 |
+
# dict: Battle information including battle ID and initial state
|
| 70 |
+
# """
|
| 71 |
+
# global current_session
|
| 72 |
+
# try:
|
| 73 |
+
# # Validate agent type
|
| 74 |
+
# if agent_type.lower() not in get_supported_agent_types():
|
| 75 |
+
# return {
|
| 76 |
+
# "status": "error",
|
| 77 |
+
# "message": f"Unsupported agent type. Supported types: {get_supported_agent_types()}"
|
| 78 |
+
# }
|
| 79 |
+
#
|
| 80 |
+
# # Create opponent agent
|
| 81 |
+
# opponent = create_agent(agent_type, api_key=api_key, model=model)
|
| 82 |
+
#
|
| 83 |
+
# # Start battle
|
| 84 |
+
# battle_id = await start_battle_against_agent(username, opponent)
|
| 85 |
+
#
|
| 86 |
+
# current_session['username'] = username
|
| 87 |
+
# current_session['active_battle_id'] = battle_id
|
| 88 |
+
#
|
| 89 |
+
# # Get initial battle state
|
| 90 |
+
# battle_info = get_battle_state(battle_id)
|
| 91 |
+
#
|
| 92 |
+
# return {
|
| 93 |
+
# "status": "success",
|
| 94 |
+
# "battle_id": battle_id,
|
| 95 |
+
# "message": f"Battle started against {agent_type} agent",
|
| 96 |
+
# "opponent": opponent.username,
|
| 97 |
+
# "battle_url": battle_info.get('battle_url', f"https://jofthomas.com/play.pokemonshowdown.com/testclient.html#battle-{battle_id}"),
|
| 98 |
+
# "battle_state": battle_info['battle_state'],
|
| 99 |
+
# "waiting_for_move": battle_info['waiting_for_move']
|
| 100 |
+
# }
|
| 101 |
+
# except Exception as e:
|
| 102 |
+
# return {
|
| 103 |
+
# "status": "error",
|
| 104 |
+
# "message": f"Failed to start battle against agent: {str(e)}"
|
| 105 |
+
# }
|
| 106 |
+
|
| 107 |
@mcp.tool()
|
| 108 |
+
def setup_battle() -> dict:
|
| 109 |
"""
|
| 110 |
+
Get setup information for playing Pokemon battles.
|
| 111 |
+
Provides instructions on how to join and play battles on the platform.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
Returns:
|
| 113 |
+
dict: Setup instructions and platform information
|
| 114 |
"""
|
| 115 |
+
return {
|
| 116 |
+
"status": "success",
|
| 117 |
+
"message": "Pokemon Battle Setup Information",
|
| 118 |
+
"instructions": {
|
| 119 |
+
"how_to_play": [
|
| 120 |
+
"1. Visit the Pokemon Showdown platform at: https://huggingface.co/spaces/Jofthomas/Pokemon_showdown",
|
| 121 |
+
"2. Choose a random username for yourself",
|
| 122 |
+
"3. Use the MCP tools to start battles, make moves, and interact with the game",
|
| 123 |
+
"4. You can start ladder matches, challenge specific players, or join existing battles"
|
| 124 |
+
],
|
| 125 |
+
"platform_url": "https://huggingface.co/spaces/Jofthomas/Pokemon_showdown",
|
| 126 |
+
"username_tip": "Choose any random username you like - it will be your identity in the Pokemon battle arena",
|
| 127 |
+
"available_battle_types": [
|
| 128 |
+
"Ladder battles (automatic matchmaking)",
|
| 129 |
+
"Player vs Player challenges",
|
| 130 |
+
"Spectate ongoing battles"
|
| 131 |
+
]
|
| 132 |
+
},
|
| 133 |
+
"next_steps": [
|
| 134 |
+
"Visit the platform and choose your username",
|
| 135 |
+
"Use start_ladder_match() to find a random opponent",
|
| 136 |
+
"Use battle_player() to challenge a specific player",
|
| 137 |
+
"Use get_current_battle_state() to see your battle status"
|
| 138 |
+
],
|
| 139 |
+
"platform_info": {
|
| 140 |
+
"name": "Pokemon Showdown on Hugging Face",
|
| 141 |
+
"url": "https://huggingface.co/spaces/Jofthomas/Pokemon_showdown",
|
| 142 |
+
"type": "Web-based Pokemon battle simulator",
|
| 143 |
+
"access": "Free and open to all users"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
}
|
| 145 |
+
}
|
| 146 |
|
| 147 |
@mcp.tool()
|
| 148 |
def battle_player(opponent_username: str, username: str = "MCPTrainer") -> dict:
|