Spaces:
Sleeping
Sleeping
from langchain_core.tools import tool | |
import requests | |
def get_chess_best_move(fen: str) -> str: | |
""" | |
Given the description of a chess board using FEN notation, returns the next best move. | |
Args: | |
fen (str): The description of the chessboard position in FEN notation. | |
Returns: | |
str: The description of the next best move. | |
""" | |
CHESS_MOVE_API = "https://chess-api.com/v1" | |
url = CHESS_MOVE_API | |
payload = { | |
"fen": fen | |
} | |
print(f"Buscando melhor jogada em {CHESS_MOVE_API} - {payload}") | |
response = requests.post(url, json=payload) | |
if response.status_code == 200: | |
#print(f"Retorno melhor jogada --> {response.text}") | |
dados = response.json() | |
move_algebric_notation = dados.get("san") | |
move = dados.get("text") | |
print(f"Melhor jogada segundo chess-api.com -> {move}") | |
return move_algebric_notation | |
else: | |
raise Exception(f"Erro na requisição: {response.status_code}") |