File size: 939 Bytes
726d2d9 70fdc68 726d2d9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from smolagents import tool
import requests
STOCKFISH_API_URL = "https://stockfish.online/api/s/v2.php"
#@tool
def get_fen(file_path:str) -> str:
"""
Extract Chess Board Image file content and return a string representing the board in FEN notation. Supported file extensions: .png
Args:
file_path: the path to the chess board image file.
"""
fen = None
try:
fen = file_path
except Exception as e:
return f"Error decoding image file: {str(e)}"
return fen
#@tool
def get_best_chess_move(fen: str) -> str:
"""
Return the best chess move provided the FEN notation of the board.
Args:
fen: FEN string to analyze.
"""
data = None
try:
response = requests.get(STOCKFISH_API_URL, {"fen":fen, "depth":8})
response.raise_for_status()
data = response.json()
except Exception as e:
return f"Error fetching best move: {str(e)}"
return data.get('bestmove').split(' ')[1].strip() |