ChatChess
v1.1.9
ChatGptでチェスを再生するためのシンプルなPythonパッケージ
pip install chatchess
パッケージをインポートします:
from ChatChess import ChatChess最初に、 Gameオブジェクトは次のようにデカラードする必要があります。
bot = ChatChess . Game ( "OPENAI_API_KEY" )self.model = "gpt-3.5-turbo" :chatgptモデルを使用します。 3.5ターボ推奨、モデルと価格設定を参照してください:https://openai.com/pricingbot.maxTokens = 10 :max_tokensを設定するたびに、各動きでchatgptに渡されますbot.maxFails = 5 :無効な動きが返されたときにchatgptに送信プロンプトを再試行する回数bot.maxTime = 5 :タイミングを出す前にchatgptの回答を待つために最大秒数bot.prompt = {"normal" : "", "failed" : "", "start" : ""} :各ゲーム状態でchatgptに送信するプロンプトbot.board = chess.Board() :チェスボードオブジェクトbot.printDebug = False :プリントデバッグ情報 - 機会に便利move = bot.move["ChatGPT"]["uci"] :指定された形式(uci / san)の指定プレイヤー(chatgpt / input)の最後の動きを返しますmessage = bot.message :各gpt移動後に移動を返します主な関数
move = bot.play("e4") :プレイヤーの動きを再生してから、chatgptの応答 - chatgptの動きを返しますmove = getGPTMove() :現在の位置でchatgptの動きを再生 - chatgptの動きを返しますその他の機能
bot.pushPlayerMove("e4") :chatgpt応答せずに動きを押しますprompt = bot.createPrompt() :現在の位置と以前の失敗に基づいてCHATGPTに送信するプロンプトを作成します - プロンプトを返しますresponse = bot.askGPT(prompt) :setパラメーターに基づいてchatgptプロンプトbot.maxTimeクエリmove = bot.handleResponse(response, player) :チェスの検索弦で動きます - それをself.moveに追加します。MoveLimitError :移動障害制限に到達しましたBadInputMoveError :入力された移動は再生できません 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 bot.boardのボードを設定するときは、ボードが単に設定された位置からではなく、PGN形式の動きがあることを確認して、CHATGPTの移動成功率を上げる