Spaces:
Sleeping
Sleeping
File size: 1,014 Bytes
25859e7 30003b4 c623f30 c976573 30003b4 c5a32ea 30003b4 3cd4870 30003b4 7514a27 99ae9bc 7514a27 c976573 7514a27 30003b4 7514a27 30003b4 7514a27 30003b4 7514a27 30003b4 7514a27 |
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 |
from langchain_core.tools import tool
import requests
@tool
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}") |