|
|
from smolagents import tool |
|
|
import requests |
|
|
|
|
|
STOCKFISH_API_URL = "https://stockfish.online/api/s/v2.php" |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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() |