Skip to content

Instantly share code, notes, and snippets.

@fsndzomga
Created March 11, 2024 02:07
Show Gist options
  • Save fsndzomga/eb3e745e8f3a5c2f2df21a03e8a2f0db to your computer and use it in GitHub Desktop.
Save fsndzomga/eb3e745e8f3a5c2f2df21a03e8a2f0db to your computer and use it in GitHub Desktop.
from langchain_openai import ChatOpenAI
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")
reasoning: str = Field(..., description="Reasoning explaining why the move is the best")
model = ChatOpenAI()
model_with_structure = model.with_structured_output(NextMove)
print(model_with_structure.invoke("Generate a chess move"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment