-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: bump dependencies and readme * add citation cff * small tweaks * small tweaks to readme * feat: minor tweaks * small tweaks
- Loading branch information
Showing
10 changed files
with
465 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
OPENAI_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# PokerEval and Vercel AI SDK | ||
|
||
This examples shows how to integrate an Agent built with the [Vercel AI SDK](https://github.com/vercel/ai) and PokerEval. | ||
|
||
## How to use | ||
1. Install dependencies | ||
``` | ||
npm install | ||
``` | ||
2. Update environment variables and rename `.env.example` to `.env` | ||
3. Run evaluation | ||
``` | ||
ts-node index.ts | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { config } from "dotenv"; | ||
import OpenAI from "openai"; | ||
import { z } from "zod"; | ||
import { zodResponseFormat } from "openai/helpers/zod"; | ||
import { PlayerAction, TableState } from "@superagent-ai/poker-eval/dist/types"; | ||
|
||
config(); | ||
|
||
const openai = new OpenAI({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
|
||
const ActionEnum = z | ||
.enum(["bet", "fold", "call", "check", "raise"]) | ||
.describe("The action to take"); | ||
|
||
const responseSchema = z.object({ | ||
action: ActionEnum, | ||
bet: z | ||
.number() | ||
.describe("The amount to bet, call, raise, or check") | ||
.optional(), | ||
}); | ||
|
||
export const generateAction = async ( | ||
state: TableState | ||
): Promise<PlayerAction> => { | ||
const ActionEnum = z | ||
.enum(["bet", "fold", "call", "check", "raise"] as const) | ||
.describe("The action to take"); | ||
|
||
const prompt = ` | ||
You are a poker assistant named ${state.playerName}. | ||
You are playing at a table with ${state.tableInfo.length} players. | ||
Act based on the information below. | ||
Players: | ||
${state.tableInfo | ||
.map( | ||
(player) => | ||
`${player.name}${player.hasButton ? " (Button)" : ""}, Stack: $${ | ||
player.stack | ||
}, Bet size: $${player.betSize}` | ||
) | ||
.join("\n")} | ||
Game stage: ${state.gameStage} | ||
Your cards: ${state.playerCards} | ||
Cards on the table: ${state.tableCards} | ||
Legal actions: ${state.legalActions.actions.join(", ")} | ||
Min bet: $${state.minRaise} | ||
Max bet: $${state.maxRaise} | ||
Considering the hand strength, potential opponent hands, and optimal strategy, what action should the player take? Explain your reasoning. | ||
Make sure to return the correct amount when calling, raising or bettings. | ||
`; | ||
|
||
const completion = await openai.beta.chat.completions.parse({ | ||
model: "gpt-4o", | ||
messages: [{ role: "user", content: prompt }], | ||
response_format: zodResponseFormat(responseSchema, "action"), | ||
}); | ||
|
||
const { action, bet } = completion.choices[0].message.parsed; | ||
|
||
return { | ||
action, | ||
bet: bet ?? 0, | ||
} as PlayerAction; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { generateAction } from "./agent"; | ||
|
||
import { PokerGame } from "@superagent-ai/poker-eval"; | ||
import { Player, PlayerAction } from "@superagent-ai/poker-eval/dist/types"; | ||
|
||
async function executeGameSimulation(numHands: number): Promise<void> { | ||
// Setup AI players | ||
const players: Player[] = [ | ||
{ | ||
name: "GPT 1", | ||
action: async (state): Promise<PlayerAction> => { | ||
const action = await generateAction(state); | ||
return action; | ||
}, | ||
}, | ||
{ | ||
name: "GPT 2", | ||
action: async (state): Promise<PlayerAction> => { | ||
const action = await generateAction(state); | ||
return action; | ||
}, | ||
}, | ||
]; | ||
|
||
// Setup a game | ||
const game = new PokerGame(players, { | ||
defaultChipSize: 1000, | ||
smallBlind: 1, | ||
bigBlind: 2, | ||
}); | ||
|
||
// Set the output director for stats collection | ||
const results = await game.runSimulation(numHands, { outputPath: "./stats" }); | ||
|
||
console.log(`Simulation completed for ${numHands} hands.`); | ||
console.log("Results:", results); | ||
} | ||
|
||
// Execute the function with ts-node index.ts | ||
executeGameSimulation(5).catch(console.error); |
Oops, something went wrong.