-
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.
* chore: add mastra ai example * small tweaks
- Loading branch information
Showing
16 changed files
with
3,297 additions
and
9 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
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
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 Mastr AI SDK | ||
|
||
This examples shows how to integrate an Agent built with the [Mastra AI SDK](https://mastra.ai/docs/guide) and PokerEval. | ||
|
||
## How to use | ||
1. Install dependencies | ||
``` | ||
npm install | ||
``` | ||
2. Update environment variables and rename `.env.example` to `.env` | ||
3. Run evaluation | ||
``` | ||
npm run start | ||
``` |
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,65 @@ | ||
import { config } from "dotenv"; | ||
import { PlayerAction, TableState } from "@superagent-ai/poker-eval/dist/types"; | ||
import { Agent } from "@mastra/core"; | ||
|
||
config(); | ||
|
||
const pokerAgent = new Agent({ | ||
name: "PokerAgent", | ||
instructions: "You are an AI Assistant playing No Limit Texas Holdem.", | ||
model: { | ||
provider: "OPEN_AI", | ||
name: "gpt-4o", | ||
toolChoice: "auto", | ||
}, | ||
}); | ||
|
||
export const generateAction = async ( | ||
state: TableState | ||
): Promise<PlayerAction> => { | ||
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 { object } = await pokerAgent.textObject({ | ||
messages: [prompt], | ||
structuredOutput: { | ||
action: { | ||
type: "string", | ||
}, | ||
bet: { | ||
type: "number", | ||
}, | ||
}, | ||
}); | ||
|
||
const { action, bet } = object; | ||
|
||
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.