Make LLM fight each other in real time in Street Fighter III.
Which LLM will be the best fighter ?
They need to be:
- Fast: It is a real time game, fast decisions are key
- Smart: A good fighter thinks 50 moves ahead
- Out of the box thinking: Outsmart your opponent with unexpected moves
- Adaptable: Learn from your mistakes and adapt your strategy
- Resilient: Keep your RPS high for an entire game
slow-v1.mp4
6v6-fast.mp4
Street Fighter III assesses the ability of LLMs to understand their environment and take actions based on a specific context. As opposed to RL models, which blindly take actions based on the reward function, LLMs are fully aware of the context and act accordingly.
Our experimentations (342 fights so far) led to the following leaderboard. Each LLM has an ELO score based on its results
Model | Rating |
---|---|
š„openai:gpt-3.5-turbo-0125 | 1776.11 |
š„mistral:mistral-small-latest | 1586.16 |
š„openai:gpt-4-1106-preview | 1584.78 |
openai:gpt-4 | 1517.2 |
openai:gpt-4-turbo-preview | 1509.28 |
openai:gpt-4-0125-preview | 1438.92 |
mistral:mistral-medium-latest | 1356.19 |
mistral:mistral-large-latest | 1231.36 |
Each player is controlled by an LLM. We send to the LLM a text description of the screen. The LLM decide on the next moves its character will make. The next moves depends on its previous moves, the moves of its opponents, its power and health bars.
- Follow instructions in https://docs.diambra.ai/#installation
- Download the ROM and put it in
~/.diambra/roms
- (Optional) Create and activate a new python venv
- Install dependencies with
make install
orpip install -r requirements.txt
- Create a
.env
file and fill it with the content like in the.env.example
file - Run with
make run
You can also run the application using Docker.
To build the Docker image, use the following command:
docker build -t diambra-app .
To run the Docker container, use the following command:
docker run --name diambra-container -v ~/.diambra/roms:/app/roms diambra-app
- If you encounter a conflict with an existing container name, you can remove the existing container with:
docker rm diambra-container
To start the services, use the following command:
docker-compose up
To stop the services, use:
docker-compose down
To disable the LLM calls, set DISABLE_LLM
to True
in the .env
file.
It will choose the actions randomly.
Change the logging level in the script.py
file.
You can run the arena with local models using Ollama.
-
Make sure you have ollama installed, running, and with a model downloaded (run
ollama serve mistral
in the terminal for example) -
Run
make local
to start the fight.
By default, it runs mistral against mistral. To use other models, you need to change the parameter model in local.py
.
from eval.game import Game, Player1, Player2
def main():
game = Game(
render=True,
save_game=True,
player_1=Player1(
nickname="Baby",
model="ollama:mistral", #Ā change this
),
player_2=Player2(
nickname="Daddy",
model="ollama:mistral", # change this
),
)
game.run()
return 0
The convention we use is model_provider:model_name
. If you want to use another local model than Mistral, you can do ollama:some_other_model
The LLM is called in Robot.call_llm()
method of the agent/robot.py
file.
def call_llm(
self,
temperature: float = 0.7,
max_tokens: int = 50,
top_p: float = 1.0,
) -> str:
"""
Make an API call to the language model.
Edit this method to change the behavior of the robot!
"""
#Ā self.model is a slug like mistral:mistral-small-latest or ollama:mistral
provider_name, model_name = get_provider_and_model(self.model)
client = get_sync_client(provider_name) #Ā OpenAI client
# Generate the prompts
move_list = "- " "\n - ".join([move for move in META_INSTRUCTIONS])
system_prompt = f"""You are the best and most aggressive Street Fighter III 3rd strike player in the world.
Your character is {self.character}. Your goal is to beat the other opponent. You respond with a bullet point list of moves.
{self.context_prompt()}
The moves you can use are:
{move_list}
----
Reply with a bullet point list of moves. The format should be: `- <name of the move>` separated by a new line.
Example if the opponent is close:
- Move closer
- Medium Punch
Example if the opponent is far:
- Fireball
- Move closer"""
#Ā Call the LLM
completion = client.chat.completions.create(
model=model_name,
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": "Your next moves are:"},
],
temperature=temperature,
max_tokens=max_tokens,
top_p=top_p,
)
#Ā Return the string to be parsed with regex
llm_response = completion.choices[0].message.content.strip()
return llm_response
To use another model or other prompts, make a call to another client in this function, change the system prompt, or make any fancy stuff.
Create a new class herited from Robot
that has the changes you want to make and open a PR.
We'll do our best to add it to the ranking!
Made with ā¤ļø by the OpenGenerativeAI team from phospho (@oulianov @Pierre-LouisBJT @Platinn) and Quivr (@StanGirard) during Mistral Hackathon 2024 in San Francisco