kaggle-environments 1.14.9__py2.py3-none-any.whl → 1.14.12__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kaggle-environments might be problematic. Click here for more details.
- kaggle_environments/__init__.py +1 -1
- kaggle_environments/envs/llm_20_questions/llm_20_questions.js +10 -2
- kaggle_environments/envs/llm_20_questions/llm_20_questions.py +74 -59
- kaggle_environments/envs/llm_20_questions/test_llm_20_questions.py +68 -0
- {kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/METADATA +1 -1
- {kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/RECORD +10 -9
- {kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/LICENSE +0 -0
- {kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/WHEEL +0 -0
- {kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/entry_points.txt +0 -0
- {kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/top_level.txt +0 -0
kaggle_environments/__init__.py
CHANGED
|
@@ -21,7 +21,7 @@ from .main import http_request
|
|
|
21
21
|
from . import errors
|
|
22
22
|
from . import utils
|
|
23
23
|
|
|
24
|
-
__version__ = "1.14.
|
|
24
|
+
__version__ = "1.14.12"
|
|
25
25
|
|
|
26
26
|
__all__ = ["Agent", "environments", "errors", "evaluate", "http_request",
|
|
27
27
|
"make", "register", "utils", "__version__",
|
|
@@ -89,8 +89,10 @@ async function renderer(context) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const info = environment.info;
|
|
92
|
-
const team1_text = info?.TeamNames?.[0] || "Team 1";
|
|
93
|
-
const
|
|
92
|
+
const team1_text = info?.TeamNames?.[0] || "Team 1 Agent 1";
|
|
93
|
+
const team1_text_two = info?.TeamNames?.[1] || "Team 1 Agent 2";
|
|
94
|
+
const team2_text = info?.TeamNames?.[2] || "Team 2 Agent 1";
|
|
95
|
+
const team2_text_two = info?.TeamNames?.[3] || "Team 2 Agent 2";
|
|
94
96
|
|
|
95
97
|
const ctx = canvas.getContext("2d");
|
|
96
98
|
const padding = 20;
|
|
@@ -122,6 +124,12 @@ async function renderer(context) {
|
|
|
122
124
|
|
|
123
125
|
line++;
|
|
124
126
|
|
|
127
|
+
// Team Row
|
|
128
|
+
ctx.fillText(team1_text_two, team1_x, line_height * line);
|
|
129
|
+
ctx.fillText(team2_text_two, team2_x, line_height * line);
|
|
130
|
+
|
|
131
|
+
line++;
|
|
132
|
+
|
|
125
133
|
// Question Row
|
|
126
134
|
ctx.fillText("Question:", label_x, question_y);
|
|
127
135
|
let wrappedText1 = wrapText(ctx, team1_question, team1_x, question_y, row_width, line_height);
|
|
@@ -8,7 +8,7 @@ import torch
|
|
|
8
8
|
from .keywords import KEYWORDS_JSON
|
|
9
9
|
from os import path
|
|
10
10
|
from pathlib import Path
|
|
11
|
-
from random import choice
|
|
11
|
+
from random import choice
|
|
12
12
|
from string import Template
|
|
13
13
|
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
|
14
14
|
|
|
@@ -29,8 +29,9 @@ TIMEOUT = "TIMEOUT"
|
|
|
29
29
|
GUESS = "guess"
|
|
30
30
|
ASK = "ask"
|
|
31
31
|
GUESSER = "guesser"
|
|
32
|
-
RANDOM_GUESSER = "random_guesser"
|
|
33
32
|
ANSWERER = "answerer"
|
|
33
|
+
|
|
34
|
+
RANDOM_GUESSER = "random_guesser"
|
|
34
35
|
RANDOM_ANSWERER = "random_answerer"
|
|
35
36
|
|
|
36
37
|
keywords_list = json.loads(KEYWORDS_JSON)
|
|
@@ -41,6 +42,21 @@ keyword = keyword_obj["keyword"]
|
|
|
41
42
|
alts = keyword_obj["alts"]
|
|
42
43
|
|
|
43
44
|
|
|
45
|
+
def random_guesser(obs):
|
|
46
|
+
if obs.turnType == GUESS:
|
|
47
|
+
return "banana"
|
|
48
|
+
if random.random() < .5:
|
|
49
|
+
return "Is is a person?"
|
|
50
|
+
if random.random() < .5:
|
|
51
|
+
return "Is it a place?"
|
|
52
|
+
return "Is it a thing?"
|
|
53
|
+
|
|
54
|
+
def random_answerer():
|
|
55
|
+
if random.random() > .5:
|
|
56
|
+
return "yes"
|
|
57
|
+
return "no"
|
|
58
|
+
|
|
59
|
+
|
|
44
60
|
def guesser_agent(obs):
|
|
45
61
|
info_prompt = """You are playing a game of 20 questions where you ask the questions and try to figure out the keyword, which will be a real or fictional person, place, or thing. \nHere is what you know so far:\n{q_a_thread}"""
|
|
46
62
|
questions_prompt = """Ask one yes or no question."""
|
|
@@ -70,19 +86,6 @@ def guesser_agent(obs):
|
|
|
70
86
|
|
|
71
87
|
return call_llm(prompt)
|
|
72
88
|
|
|
73
|
-
def random_guesser(obs):
|
|
74
|
-
if obs.turnType == GUESS:
|
|
75
|
-
return "banana"
|
|
76
|
-
if random() < .5:
|
|
77
|
-
return "Is is a person?"
|
|
78
|
-
if random() < .5:
|
|
79
|
-
return "Is it a place?"
|
|
80
|
-
return "Is it a thing?"
|
|
81
|
-
|
|
82
|
-
def random_answerer():
|
|
83
|
-
if random() > .5:
|
|
84
|
-
return "yes"
|
|
85
|
-
return "no"
|
|
86
89
|
|
|
87
90
|
|
|
88
91
|
def answerer_agent(obs):
|
|
@@ -105,8 +108,10 @@ def guesser_action(active, inactive, step):
|
|
|
105
108
|
inactive.observation.keyword = keyword
|
|
106
109
|
inactive.observation.category = category
|
|
107
110
|
guessed = False
|
|
111
|
+
bad_guess = False
|
|
108
112
|
if not active.action:
|
|
109
113
|
active.status = ERROR
|
|
114
|
+
bad_guess = True
|
|
110
115
|
elif active.observation.turnType == ASK:
|
|
111
116
|
question = active.action[:2000]
|
|
112
117
|
active.observation.questions.append(question)
|
|
@@ -118,40 +123,43 @@ def guesser_action(active, inactive, step):
|
|
|
118
123
|
if active.action and keyword_guessed(active.action):
|
|
119
124
|
guessed = True
|
|
120
125
|
score = 20 - int(step / 3)
|
|
121
|
-
end_game(active,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def end_game(active, inactive, reward, status, inactive_status):
|
|
125
|
-
active.observation.keyword = keyword
|
|
126
|
-
active.observation.category = category
|
|
127
|
-
inactive.observation.keyword = keyword
|
|
128
|
-
inactive.observation.category = category
|
|
129
|
-
active.reward = reward
|
|
130
|
-
inactive.reward = reward
|
|
131
|
-
active.status = status
|
|
132
|
-
inactive.status = inactive_status
|
|
126
|
+
end_game(active, score, DONE)
|
|
127
|
+
end_game(inactive, score, DONE)
|
|
128
|
+
return [guessed, bad_guess]
|
|
133
129
|
|
|
130
|
+
def end_game(agent, reward, status):
|
|
131
|
+
agent.observation.keyword = keyword
|
|
132
|
+
agent.observation.category = category
|
|
133
|
+
agent.reward = reward
|
|
134
|
+
agent.status = status
|
|
134
135
|
|
|
135
136
|
def answerer_action(active, inactive):
|
|
136
137
|
active.observation.keyword = keyword
|
|
137
138
|
active.observation.category = category
|
|
138
139
|
response = active.action
|
|
140
|
+
bad_response = False
|
|
139
141
|
if not response:
|
|
140
142
|
response = "none"
|
|
141
|
-
end_game(active,
|
|
143
|
+
end_game(active, -1, ERROR)
|
|
144
|
+
end_game(inactive, 1, DONE)
|
|
145
|
+
bad_response = True
|
|
142
146
|
elif "yes" in response.lower():
|
|
143
147
|
response = "yes"
|
|
144
148
|
elif "no" in response.lower():
|
|
145
149
|
response = "no"
|
|
146
150
|
else:
|
|
147
151
|
response = "maybe"
|
|
148
|
-
end_game(active,
|
|
152
|
+
end_game(active, -1, ERROR)
|
|
153
|
+
end_game(inactive, 1, DONE)
|
|
154
|
+
bad_response = True
|
|
149
155
|
active.observation.answers.append(response)
|
|
150
156
|
inactive.observation.answers.append(response)
|
|
157
|
+
return bad_response
|
|
151
158
|
|
|
152
159
|
def increment_turn(active, inactive, step, guessed):
|
|
153
160
|
if step == 59 and not guessed:
|
|
154
|
-
end_game(active,
|
|
161
|
+
end_game(active, -1, DONE)
|
|
162
|
+
end_game(inactive, -1, DONE)
|
|
155
163
|
elif active.observation.turnType == "guess":
|
|
156
164
|
active.observation.turnType = "ask"
|
|
157
165
|
elif active.observation.turnType == "ask":
|
|
@@ -186,42 +194,49 @@ def interpreter(state, env):
|
|
|
186
194
|
end_early = (active1 and active1.status) in (TIMEOUT, ERROR) or (active2 and active2.status in (TIMEOUT, ERROR))
|
|
187
195
|
one_guessed = False
|
|
188
196
|
two_guessed = False
|
|
197
|
+
one_bad_guess = False
|
|
198
|
+
two_bad_guess = False
|
|
199
|
+
one_bad_response = False
|
|
200
|
+
two_bad_response = False
|
|
189
201
|
|
|
190
|
-
if active1 is
|
|
191
|
-
|
|
192
|
-
if active1.observation.role == GUESSER:
|
|
193
|
-
guessed = guesser_action(active1, inactive1, step)
|
|
194
|
-
one_guessed = guessed
|
|
195
|
-
else:
|
|
196
|
-
answerer_action(active1, inactive1)
|
|
202
|
+
if active1 is None or active2 is None:
|
|
203
|
+
raise ValueError
|
|
197
204
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
else:
|
|
203
|
-
increment_turn(active1, inactive1, step, guessed)
|
|
204
|
-
|
|
205
|
-
if active2 is not None:
|
|
206
|
-
guessed = False
|
|
207
|
-
if active2.observation.role == GUESSER:
|
|
208
|
-
guessed = guesser_action(active2, inactive2, step)
|
|
209
|
-
two_guessed = guessed
|
|
210
|
-
else:
|
|
211
|
-
answerer_action(active2, inactive2)
|
|
205
|
+
if active1.observation.role == GUESSER:
|
|
206
|
+
[one_guessed, one_bad_guess] = guesser_action(active1, inactive1, step)
|
|
207
|
+
else:
|
|
208
|
+
one_bad_response = answerer_action(active1, inactive1)
|
|
212
209
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
if active2.observation.role == GUESSER:
|
|
211
|
+
[two_guessed, two_bad_guess] = guesser_action(active2, inactive2, step)
|
|
212
|
+
else:
|
|
213
|
+
two_bad_response = answerer_action(active2, inactive2)
|
|
214
|
+
|
|
215
|
+
if active1.status in (TIMEOUT, ERROR) or one_bad_response or one_bad_guess:
|
|
216
|
+
end_game(active1, -1, active1.status)
|
|
217
|
+
end_game(inactive1, 1, DONE)
|
|
218
|
+
elif end_early or two_bad_response or two_bad_guess:
|
|
219
|
+
end_game(active1, 1, DONE)
|
|
220
|
+
end_game(inactive1, 1, DONE)
|
|
221
|
+
else:
|
|
222
|
+
increment_turn(active1, inactive1, step, one_guessed)
|
|
223
|
+
|
|
224
|
+
if active2.status in (TIMEOUT, ERROR) or two_bad_response or two_bad_guess:
|
|
225
|
+
end_game(active2, -1, active2.status)
|
|
226
|
+
end_game(inactive2, 1, DONE)
|
|
227
|
+
elif end_early or one_bad_response or one_bad_guess:
|
|
228
|
+
end_game(active2, 1, DONE)
|
|
229
|
+
end_game(inactive2, 1, DONE)
|
|
230
|
+
else:
|
|
231
|
+
increment_turn(active2, inactive2, step, two_guessed)
|
|
219
232
|
|
|
220
233
|
# make sure to end the game if only one team guessed correctly this round
|
|
221
234
|
if one_guessed and not two_guessed:
|
|
222
|
-
end_game(active2,
|
|
235
|
+
end_game(active2, 0, DONE)
|
|
236
|
+
end_game(inactive2, 0, DONE)
|
|
223
237
|
elif two_guessed and not one_guessed:
|
|
224
|
-
end_game(active1,
|
|
238
|
+
end_game(active1, 0, DONE)
|
|
239
|
+
end_game(inactive1, 0, DONE)
|
|
225
240
|
|
|
226
241
|
return state
|
|
227
242
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
|
|
2
|
+
from kaggle_environments import make
|
|
3
|
+
|
|
4
|
+
def custom_questioner(obs):
|
|
5
|
+
if obs.turnType == "guess":
|
|
6
|
+
return "banana"
|
|
7
|
+
return "Is it a banana?"
|
|
8
|
+
|
|
9
|
+
def last_round_guesser_error(obs):
|
|
10
|
+
if obs.turnType == "guess" and len(obs.questions) == 20:
|
|
11
|
+
a = 1
|
|
12
|
+
b = 0
|
|
13
|
+
return a / b
|
|
14
|
+
if obs.turnType == "guess":
|
|
15
|
+
return "banana"
|
|
16
|
+
return "Is it a banana?"
|
|
17
|
+
|
|
18
|
+
def custom_answerer():
|
|
19
|
+
return "no"
|
|
20
|
+
|
|
21
|
+
def bad_answerer():
|
|
22
|
+
return "maybe?"
|
|
23
|
+
|
|
24
|
+
def error_agent():
|
|
25
|
+
raise ValueError
|
|
26
|
+
|
|
27
|
+
def test_llm_20_q_completes():
|
|
28
|
+
env = make("llm_20_questions", debug=True)
|
|
29
|
+
env.run([custom_questioner, custom_answerer, custom_questioner, custom_answerer])
|
|
30
|
+
json = env.toJSON()
|
|
31
|
+
assert json["name"] == "llm_20_questions"
|
|
32
|
+
assert json["statuses"] == ["DONE", "DONE", "DONE", "DONE"]
|
|
33
|
+
|
|
34
|
+
def test_llm_20_q_errors_on_bad_answer():
|
|
35
|
+
env = make("llm_20_questions", debug=True)
|
|
36
|
+
env.run([custom_questioner, custom_answerer, custom_questioner, bad_answerer])
|
|
37
|
+
json = env.toJSON()
|
|
38
|
+
assert json["name"] == "llm_20_questions"
|
|
39
|
+
assert json["rewards"] == [1, 1, 1, None]
|
|
40
|
+
assert json["statuses"] == ["DONE", "DONE", "DONE", "ERROR"]
|
|
41
|
+
print(len(json["steps"]))
|
|
42
|
+
assert len(json["steps"]) == 3
|
|
43
|
+
|
|
44
|
+
def test_llm_20_q_errors_on_error_answer():
|
|
45
|
+
env = make("llm_20_questions", debug=True)
|
|
46
|
+
env.run([custom_questioner, custom_answerer, custom_questioner, error_agent])
|
|
47
|
+
json = env.toJSON()
|
|
48
|
+
assert json["name"] == "llm_20_questions"
|
|
49
|
+
assert json["rewards"] == [1, 1, 1, None]
|
|
50
|
+
assert json["statuses"] == ["DONE", "DONE", "DONE", "ERROR"]
|
|
51
|
+
assert len(json["steps"]) == 3
|
|
52
|
+
|
|
53
|
+
def test_llm_20_q_errors_on_error_question():
|
|
54
|
+
env = make("llm_20_questions", debug=True)
|
|
55
|
+
env.run([custom_questioner, custom_answerer, error_agent, custom_answerer])
|
|
56
|
+
json = env.toJSON()
|
|
57
|
+
assert json["name"] == "llm_20_questions"
|
|
58
|
+
assert json["rewards"] == [1, 1, None, 1]
|
|
59
|
+
assert json["statuses"] == ["DONE", "DONE", "ERROR", "DONE"]
|
|
60
|
+
assert len(json["steps"]) == 2
|
|
61
|
+
|
|
62
|
+
def test_llm_20_q_errors_on_error_last_guess():
|
|
63
|
+
env = make("llm_20_questions", debug=True)
|
|
64
|
+
env.run([custom_questioner, custom_answerer, last_round_guesser_error, custom_answerer])
|
|
65
|
+
json = env.toJSON()
|
|
66
|
+
assert json["name"] == "llm_20_questions"
|
|
67
|
+
assert json["rewards"] == [1, 1, None, 1]
|
|
68
|
+
assert json["statuses"] == ["DONE", "DONE", "ERROR", "DONE"]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
kaggle_environments/__init__.py,sha256
|
|
1
|
+
kaggle_environments/__init__.py,sha256=oU4_4nptOEcuW1zMtVey6bzd7GOtU50VuXXIwrqijK0,1703
|
|
2
2
|
kaggle_environments/agent.py,sha256=BpYrAC6EOhJF3Wzynq-CWg8l-z5uXW1Lq4qUsyOM0ik,6203
|
|
3
3
|
kaggle_environments/api.py,sha256=eLBKqr11Ku4tdsMUdUqy74FIVEA_hdV3_QUpX84x3Z8,798
|
|
4
4
|
kaggle_environments/core.py,sha256=IrEkN9cIA2djBAxI8Sz1GRpGNKjhqbnBdV6irAeTm8Q,27851
|
|
@@ -70,9 +70,10 @@ kaggle_environments/envs/kore_fleets/starter_bots/ts/test/configuration.json,sha
|
|
|
70
70
|
kaggle_environments/envs/kore_fleets/starter_bots/ts/test/fullob.json,sha256=lEWzlv1rqiDMRmLqiGIO3j6m2Uf7OMjXx0zXBplAz1M,6791
|
|
71
71
|
kaggle_environments/envs/kore_fleets/starter_bots/ts/test/observation.json,sha256=SIgLl8uTPmv2T_-g3gsFaibh_DWfvZNlZS7yPXL1Cnc,5998
|
|
72
72
|
kaggle_environments/envs/llm_20_questions/keywords.py,sha256=BnyVrV0_xbiDt_Td4YXSKae9hHndAo5YYfYVtyL4eS4,45282
|
|
73
|
-
kaggle_environments/envs/llm_20_questions/llm_20_questions.js,sha256=
|
|
73
|
+
kaggle_environments/envs/llm_20_questions/llm_20_questions.js,sha256=3y_5q9c7EMaDJAbOnebK9xnzOh2z0eH4orW6eP1PMOs,6319
|
|
74
74
|
kaggle_environments/envs/llm_20_questions/llm_20_questions.json,sha256=VYxgQEDCaJv910sQdE_FOtV2w1V83Y3C6nTjx4FFZyo,2101
|
|
75
|
-
kaggle_environments/envs/llm_20_questions/llm_20_questions.py,sha256=
|
|
75
|
+
kaggle_environments/envs/llm_20_questions/llm_20_questions.py,sha256=kXRQfYQWCPE1rqkcHz3luebBnDKDuoW-Wk9aB2KLjIs,10236
|
|
76
|
+
kaggle_environments/envs/llm_20_questions/test_llm_20_questions.py,sha256=GxVurD9rO8H78xFmG15HpqbyEFj4yoRd79MNX8UtxHo,2375
|
|
76
77
|
kaggle_environments/envs/lux_ai_2021/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
77
78
|
kaggle_environments/envs/lux_ai_2021/agents.py,sha256=bDqsY17Jxrk69a8HXb96ex2U1ipKkQPVJuXxmiA5hMA,421
|
|
78
79
|
kaggle_environments/envs/lux_ai_2021/index.html,sha256=4Ec1FuHuuH1EvkvlLOpNUUFYLovnS_IA-rOOHEUjcGY,1550
|
|
@@ -176,9 +177,9 @@ kaggle_environments/envs/tictactoe/tictactoe.js,sha256=NZDT-oSG0a6a-rso9Ldh9qkJw
|
|
|
176
177
|
kaggle_environments/envs/tictactoe/tictactoe.json,sha256=zMXZ8-fpT7FBhzz2FFBvRLn4XwtngjEqOieMvI6cCj8,1121
|
|
177
178
|
kaggle_environments/envs/tictactoe/tictactoe.py,sha256=iLNU5V-lz7Xab-d1vpPMfU5jDM3QtgBUH63Y_SU7I9Y,3639
|
|
178
179
|
kaggle_environments/static/player.html,sha256=HH8qvFfTIDw8eZvw5W88jcCu58Lo4_eUQ1ak46KWVGQ,22945
|
|
179
|
-
kaggle_environments-1.14.
|
|
180
|
-
kaggle_environments-1.14.
|
|
181
|
-
kaggle_environments-1.14.
|
|
182
|
-
kaggle_environments-1.14.
|
|
183
|
-
kaggle_environments-1.14.
|
|
184
|
-
kaggle_environments-1.14.
|
|
180
|
+
kaggle_environments-1.14.12.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
181
|
+
kaggle_environments-1.14.12.dist-info/METADATA,sha256=nPl33KIBUPk78LAv-6FWRvFRRzSEdoqp5a5AUezMs4M,10701
|
|
182
|
+
kaggle_environments-1.14.12.dist-info/WHEEL,sha256=m9WAupmBd2JGDsXWQGJgMGXIWbQY3F5c2xBJbBhq0nY,110
|
|
183
|
+
kaggle_environments-1.14.12.dist-info/entry_points.txt,sha256=HbVC-LKGQFV6lEEYBYyDTtrkHgdHJUWQ8_qt9KHGqz4,70
|
|
184
|
+
kaggle_environments-1.14.12.dist-info/top_level.txt,sha256=v3MMWIPMQFcI-WuF_dJngHWe9Bb2yH_6p4wat1x4gAc,20
|
|
185
|
+
kaggle_environments-1.14.12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{kaggle_environments-1.14.9.dist-info → kaggle_environments-1.14.12.dist-info}/top_level.txt
RENAMED
|
File without changes
|