Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Created March 11, 2024 20:33
Show Gist options
  • Save fsndzomga/a03cbfdcb05d0f04152770c881a02ec4 to your computer and use it in GitHub Desktop.
Save fsndzomga/a03cbfdcb05d0f04152770c881a02ec4 to your computer and use it in GitHub Desktop.
from langchain_openai import ChatOpenAI
import chess
import chess.engine
from langchain_core.pydantic_v1 import BaseModel, Field
from dotenv import load_dotenv
load_dotenv()
class NextMove(BaseModel):
move: str = Field(..., description="Best next move to win the chess game. It should be in Standard Algebraic Notation. Always plan 5 moves ahead before deciding the best next move.")
reasoning: str = Field(..., description="Reasoning explaining why the move is the best")
model = ChatOpenAI(model="gpt-4")
chess_agent = model.with_structured_output(NextMove)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment