
How We Built The Model Brawl League: A Chat Bot Arena for LLMs
Learn how we built a video game to benchmark LLMs
Once the game state data is captured in the global configuration, we access this data using JavaScript and construct our prompt. This prompt is then sent to a Lambda function, which acts as an intermediary between our game and Amazon Bedrock.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
prompt = `Your name is {name} and you are a fighter in a fighting combat game. You are allowed to do the following regular moves which generates energy:
- Rush Forward: Get closer to your opponent very quickly,
- Rush backward: Get away from your opponent very quickly - this is a defensive move,
- Get closer: Move at a normal pace towards your opponent,
....
Your current life is {current_life}% and your opponent life is {oppenent_life}%.\n\nIf your life reaches 0 % then you die.
You have {current_energy} % of energy for special attacks. Your opponent has {opponent_energy} % of energy for special attacks. You generate energy when you hit your opponent. {energy_recommendation}
You are currently {distance}. Keep in mind that when you hit your opponent, he will be pushed backward and most likely be un-reachable, so make sure to get closer after a couple of hits.
Your fighting style is : {fighting_style}.
Your persona is : {persona}.
Using the following JSON structure to respond:
{"explanation": "I selected the following moves because it will quickly disable my opponent and allow me to win this battle in a few moves.", "moves": ["Move Forward", "High Kick", "Medium Kick", "Move Forward"]}
Your answer must only contain the JSON list of at least 10 moves that you should do in order to win the game along with a very short explanation of why you chose those moves. The explanation should be less than two sentences. I need to parse your response as a JSON so don't add anything else to your answer than the JSON list.`
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def generate_conversation(model_id, system_prompts, messages):
"""
Sends messages to a model.
Args:
model_id (str): The model ID to use.
system_prompts (JSON) : The system prompts for the model to use.
messages (JSON) : The messages to send to the model.
Returns:
response (JSON): The conversation that the model generated.
"""
print(f"Generating message with model {model_id}")
# Inference parameters to use.
temperature = 0.7
# Base inference parameters to use.
inference_config = {"temperature": temperature}
# Send the message.
response = bedrock_runtime.converse(
modelId=model_id,
messages=messages,
system=system_prompts,
inferenceConfig=inference_config,
)
# Log token usage.
token_usage = response["usage"]
print(f"Input tokens: {token_usage['inputTokens']}")
print(f"Output tokens: {token_usage['outputTokens']}")
print(f"Total tokens: {token_usage['totalTokens']}")
print(f"Stop reason: {response['stopReason']}")
text_response = response["output"]["message"]["content"][0]["text"]
return text_response
- Receives the game state prompt from the JavaScript front-end
- Formats the prompt if necessary
- Calls the appropriate LLM through Amazon Bedrock's API
- Processes the LLM's response
- Returns the processed response back to the game
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
async startGameLoop() {
while (this.gameInProgress) {
this.moves = [];
await this.getNextMoves();
if (!this.gameInProgress) {
return;
}
if (this.moves.length > 0) {
for (var i = 0; i < this.moves.length; i++) {
this._currentMove = this.moves[i];
let actions = this.getActions(this.moves[i]);
switch (this._currentMove) {
case 'Rush Forward':
case 'Get closer':
case 'Jump Forward':
++this.totalOffensiveMove;
break;
....
case 'Fireball':
++this.totalAttemptSpecialAttacks;
break;
}
Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.