ChatChess
v1.1.9
Un simple paquete de Python para jugar al ajedrez con chatgpt
pip install chatchess
Importar el paquete:
from ChatChess import ChatChess Primero, un objeto Game debe ser decalord de la siguiente manera:
bot = ChatChess . Game ( "OPENAI_API_KEY" )self.model = "gpt-3.5-turbo" : Modelo CHATGPT para ser utilizado. 3.5-Turbo recomendado, vea modelos y precios aquí: https://openai.com/picingbot.maxTokens = 10 : Establecer max_tokens pasó a chatgpt en cada movimientobot.maxFails = 5 : cantidad de veces para volver a intentar el envío de envío a chatgpt cuando se devuelve un movimiento no válidobot.maxTime = 5 : cantidad máxima de segundos para esperar la respuesta de chatgpt antes de salir tiempobot.prompt = {"normal" : "", "failed" : "", "start" : ""} : las indicaciones para enviar a chatgpt en cada estado de juegobot.board = chess.Board() : objeto de tablero de ajedrezbot.printDebug = False : información de depuración impresa - ocasionalmente útilmove = bot.move["ChatGPT"]["uci"] : Devuelve el último movimiento del reproductor dado (chatgpt / input) en el formato dado (UCI / SAN)message = bot.message : Devuelve el movimiento después de cada movimiento GPTFunciones principales
move = bot.play("e4") : reproduce el movimiento del jugador, luego la respuesta de ChatGPT - Devuelve el movimiento de Chatgptmove = getGPTMove() : reproduce el movimiento de chatgpt en la posición actual - devuelve el movimiento de chatgptOtras funciones
bot.pushPlayerMove("e4") : presione un movimiento sin chatgpt respondiendoprompt = bot.createPrompt() : crea un indicador para enviar a ChatGPT según la posición actual y los fracasos anteriores - Devuelve el avisoresponse = bot.askGPT(prompt) : consultas chatgpt indicador basado en parámetros establecidos, tiempos después de bot.maxTime segundosmove = bot.handleResponse(response, player) : busca el ajedrez Move en la cadena - lo agrega a uno mismo. Move como jugadorMoveLimitError : Límite de fallas de movimiento alcanzadoBadInputMoveError : Move Inputed no se puede jugar from ChatChess import ChatChess
bot = ChatChess . Game ( "OPENAI_API_KEY" ) # Set API key
while True :
print ( bot . board ) # Print the board
bot . play ( input ( "Make a move: " )) # Ask player to make a move, then ChatGPT responds
if bot . board . is_game_over (): # Break if game over
break from ChatChess import ChatChess
import chess . pgn
from datetime import date
bot = ChatChess . Game ( "OPENAI_API_KEY" ) # Set API key
while True :
bot . getGPTMove () # Ask ChatGPT to make a move
print ( bot . message ) # Print move and info
if bot . board . is_game_over (): # Break if game over
game = chess . pgn . Game . from_board ( bot . board ) # Create PGN from game
game . headers [ "Event" ] = "ChatChess test"
game . headers [ "Date" ] = date . today (). strftime ( "%d.%m.%Y" )
game . headers [ "White" ] = "ChatGPT"
game . headers [ "Black" ] = "ChatGPT"
print ( game )
break from ChatChess import ChatChess
import chess
bot = ChatChess . Game ( "OPENAI_API_KEY" ) # Set API key
def getGPTMove ():
bot . board = chess . Board () # Pass board to ChatChess
bot . getGPTMove () # Ask ChatGPT to make a move
return bot . move [ "ChatGPT" ][ "FEN" ]. fen () # Return FEN move Al configurar el tablero para bot.board .