Skip to content
Snippets Groups Projects
Commit 5a4748ce authored by Maxime Morge's avatar Maxime Morge :construction_worker:
Browse files

PyGAAMAS: Add Qwen3 in the dictator game

parent dfd60129
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,7 @@ is set to $0.7$.
Newt Figure presents a violin plot illustrating the share of the
total amount (\$100) that the dictator allocates to themselves for each model.
The median share taken by <tt>GPT-4.5</tt>, <tt>Llama3</tt>,
<tt>Mistral-Small</tt>, and <tt>DeepSeek-R1</tt> through one-shot decisions is
<tt>Mistral-Small</tt>, <tt>DeepSeek-R1</tt> and <tt>Qwen3</tt> through one-shot decisions is
\$50, likely due to a corpus-based biases like term frequency.
The median share taken by <tt>mixtral:8x7b</tt>, <tt>Llama3.3:latest</tt>,
is \$60. When we ask the
......
......@@ -209,3 +209,33 @@ iteration,model,temperature,amount,my_share,other_share,motivation
28,deepseek-r1:7b,0.7,100,50,50,"I chose to split the points equally because fairness often leads to mutual satisfaction in such situations. By allocating 50% each, we ensure that neither party feels exploited or undervalued."
29,deepseek-r1:7b,0.7,100,50,50,"Equal allocation promotes fairness and mutual satisfaction."
30,deepseek-r1:7b,0.7,100,50,50,"The decision to allocate equally was made as a fair choice without knowledge of specific returns, aiming for balance and avoiding strategic advantage."
1,qwen3,0.7,100,50,50,"I believe in fair distribution, so I choose to split the points equally."
2,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and maximize overall returns."
3,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and maximize overall returns."
4,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and mutual benefit."
5,qwen3,0.7,100,50,50,"I want to split the points evenly to ensure fairness and mutual benefit."
6,qwen3,0.7,100,50,50,"I want to split the points equally to show fairness and ensure both parties benefit."
7,qwen3,0.7,100,60,40,"I aim to be fair but also consider my own needs."
8,qwen3,0.7,100,50,50,"I want to split the points equally because fairness is important to me."
9,qwen3,0.7,100,50,50,"I want to split the points equally because fairness is important to me."
10,qwen3,0.7,100,50,50,"I want to split the points equally to be fair."
11,qwen3,0.7,100,50,50,"I want to be fair and ensure both parties get equal returns."
12,qwen3,0.7,100,60,40,"I want to allocate 60 points to myself and 40 to the other person. My motivation is to ensure a fair split while also maximizing my own benefit."
13,qwen3,0.7,100,60,40,"I want to be fair but also ensure I get a reasonable share."
14,qwen3,0.7,100,50,50,"I want to split the points equally to show fairness and maximize the total return."
15,qwen3,0.7,100,70,30,"I want to allocate 70 points to myself and 30 points to the other person. My motivation is to ensure a fair split while also taking a larger share since I believe in contributing more."
16,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and mutual benefit."
17,qwen3,0.7,100,50,50,"I want to split the points evenly to ensure fairness and maximize mutual benefit."
18,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and mutual benefit."
19,qwen3,0.7,100,50,50,"I want to be fair and allocate equal points to both myself and the other person."
20,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness."
21,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and maximize overall return."
22,qwen3,0.7,100,50,50,"splitting equally seems fair"
23,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and mutual benefit."
24,qwen3,0.7,100,50,50,"I want to be fair and ensure both parties receive equal returns."
25,qwen3,0.7,100,50,50,"I want to split the points equally to show fairness and ensure both parties benefit."
26,qwen3,0.7,100,50,50,"I want to be fair and distribute the points equally between myself and the other person."
27,qwen3,0.7,100,50,50,"I want to split the points equally to be fair."
28,qwen3,0.7,100,50,50,"I want to be fair and ensure both parties get equal returns."
29,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and maintain a balanced outcome for both parties."
30,qwen3,0.7,100,50,50,"I want to split the points equally to ensure fairness and mutual benefit."
This diff is collapsed.
......@@ -71,6 +71,7 @@ class Dictator:
response_format=AgentResponse
)
async def run(self) -> Dict:
"""Runs the model if strategy is False, otherwise uses a classical method."""
if self.strategy:
......@@ -104,30 +105,35 @@ class Dictator:
)
try:
# Debug: print the raw response to check if fields are missing or named differently
print(f"Raw response (Attempt {attempt + 1}): {response}")
# Extract the JSON portion from the response string using regex
response_json_str = re.search(r'```json\n(.*?)\n```', response['response'], re.DOTALL)
if response_json_str:
# Parse the extracted JSON string into a dictionary
response_json = json.loads(response_json_str.group(1))
# Correct: get the content from the chat message
raw_text = response.chat_message.content
# Debug: show the raw content
print(f"Raw content (Attempt {attempt + 1}): {raw_text}")
# Try to load JSON directly
try:
response_json = json.loads(raw_text)
except json.JSONDecodeError:
# If it's wrapped in ```json ... ```, extract it
match = re.search(r'```json\s*(.*?)\s*```', raw_text, re.DOTALL)
if match:
response_json = json.loads(match.group(1))
else:
print(f"Could not parse JSON from response (Attempt {attempt + 1})")
continue
# Create the AgentResponse object from the parsed response JSON
agent_response = AgentResponse(**response_json)
my_share, other_share = agent_response.my_share, agent_response.other_share
agent_response = AgentResponse(**response_json)
my_share, other_share = agent_response.my_share, agent_response.other_share
# Validate the response
if 0 <= my_share <= self.amount and 0 <= other_share <= self.amount and my_share + other_share <= self.amount:
return agent_response.dict()
else:
print(f"Invalid response detected (Attempt {attempt + 1}): {response_json}")
# Validate shares
if 0 <= my_share <= self.amount and 0 <= other_share <= self.amount and my_share + other_share <= self.amount:
return agent_response.dict()
else:
print(f"JSON not found in response (Attempt {attempt + 1})")
print(f"Invalid values in response (Attempt {attempt + 1}): {response_json}")
except Exception as e:
print(f"Error in OpenAI request (Attempt {attempt + 1}): {e}")
print(f"Error in OpenAI response handling (Attempt {attempt + 1}): {e}")
raise ValueError("Model failed to provide a valid response after multiple attempts.")
......@@ -253,6 +259,6 @@ class Dictator:
# Run the async function and return the response
if __name__ == "__main__":
agent = Dictator(amount=100, model="deepseek-r1:7b", temperature=0.7, strategy=False) # "llama3.3:latest", "mixtral:8x7b"
agent = Dictator(amount=100, model="qwen3", temperature=0.7, strategy=False) # "llama3.3:latest", "mixtral:8x7b"
response_json = asyncio.run(agent.run())
print(response_json)
\ No newline at end of file
......@@ -4,13 +4,15 @@ import seaborn as sns
# Definition of the color palette
color_palette = {
'random': '#333333', # Black
'gpt-4.5-preview-2025-02-27': '#7abaff', # BlueEscape
'llama3': '#32a68c', # GreenFuture
'llama3.3:latest': '#4b9f7d', # GreenLlama3.3
'mistral-small': '#ff6941', # WarmOrange
'mixtral:8x7b': '#f1a61a', # YellowMixtral
'deepseek-r1': '#5862ed', # InclusiveIndigo
'deepseek-r1:7b': '#9a7bff' # PurpleDeepseek-r1:7b
'deepseek-r1:7b': '#9a7bff', # PurpleDeepseek-r1:7b
'qwen3': '#c02942'
}
# Load the data
......@@ -21,7 +23,8 @@ model_order = [
'gpt-4.5-preview-2025-02-27',
'llama3', 'llama3.3:latest', # Place llama3 and llama3.3:latest together
'mistral-small', 'mixtral:8x7b', # Bring mistral-small and mixtral:8x7b closer
'deepseek-r1', 'deepseek-r1:7b'
'deepseek-r1', 'deepseek-r1:7b',
'qwen3'
]
# Create the violin plot
......
......@@ -41,7 +41,7 @@ class DictatorExperiment:
# Running the experiment
if __name__ == "__main__":
models = ["mixtral:8x7b", "llama3.3:latest", "deepseek-r1:7b"] # "gpt-4.5-preview-2025-02-27" "llama3", "mistral-small", "deepseek-r1"
models = ["qwen3"] # "gpt-4.5-preview-2025-02-27" "llama3", "mistral-small", "deepseek-r1", "mixtral:8x7b", "llama3.3:latest", "deepseek-r1:7b"
temperature = 0.7
amount = 100
iterations = 30
......
......@@ -281,6 +281,6 @@ class Investment:
# Run the async function and return the response
if __name__ == "__main__":
game_agent = Investment(model="mistral-small", temperature=0.0)
game_agent = Investment(model="deepseek-r1", temperature=0.0)
response = asyncio.run(game_agent.run_rounds(30))
print(response)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment