edsl 0.1.38__py3-none-any.whl → 0.1.38.dev1__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.
- edsl/Base.py +34 -63
- edsl/BaseDiff.py +7 -7
- edsl/__init__.py +1 -2
- edsl/__version__.py +1 -1
- edsl/agents/Agent.py +11 -23
- edsl/agents/AgentList.py +23 -86
- edsl/agents/Invigilator.py +7 -18
- edsl/agents/InvigilatorBase.py +19 -0
- edsl/agents/PromptConstructor.py +4 -5
- edsl/auto/SurveyCreatorPipeline.py +1 -1
- edsl/auto/utilities.py +1 -1
- edsl/base/Base.py +13 -3
- edsl/config.py +0 -8
- edsl/conjure/AgentConstructionMixin.py +160 -0
- edsl/conjure/Conjure.py +62 -0
- edsl/conjure/InputData.py +659 -0
- edsl/conjure/InputDataCSV.py +48 -0
- edsl/conjure/InputDataMixinQuestionStats.py +182 -0
- edsl/conjure/InputDataPyRead.py +91 -0
- edsl/conjure/InputDataSPSS.py +8 -0
- edsl/conjure/InputDataStata.py +8 -0
- edsl/conjure/QuestionOptionMixin.py +76 -0
- edsl/conjure/QuestionTypeMixin.py +23 -0
- edsl/conjure/RawQuestion.py +65 -0
- edsl/conjure/SurveyResponses.py +7 -0
- edsl/conjure/__init__.py +9 -0
- edsl/conjure/examples/placeholder.txt +0 -0
- edsl/{utilities → conjure}/naming_utilities.py +1 -1
- edsl/conjure/utilities.py +201 -0
- edsl/coop/coop.py +7 -77
- edsl/data/Cache.py +17 -45
- edsl/data/CacheEntry.py +3 -8
- edsl/data/RemoteCacheSync.py +19 -0
- edsl/enums.py +0 -2
- edsl/exceptions/agents.py +0 -4
- edsl/inference_services/GoogleService.py +15 -7
- edsl/inference_services/registry.py +0 -2
- edsl/jobs/Jobs.py +559 -110
- edsl/jobs/buckets/TokenBucket.py +0 -3
- edsl/jobs/interviews/Interview.py +7 -7
- edsl/jobs/runners/JobsRunnerAsyncio.py +28 -156
- edsl/jobs/runners/JobsRunnerStatus.py +196 -194
- edsl/jobs/tasks/TaskHistory.py +19 -27
- edsl/language_models/LanguageModel.py +90 -52
- edsl/language_models/ModelList.py +14 -67
- edsl/language_models/registry.py +4 -57
- edsl/notebooks/Notebook.py +8 -7
- edsl/prompts/Prompt.py +3 -8
- edsl/questions/QuestionBase.py +30 -38
- edsl/questions/QuestionBaseGenMixin.py +1 -1
- edsl/questions/QuestionBasePromptsMixin.py +17 -0
- edsl/questions/QuestionExtract.py +4 -3
- edsl/questions/QuestionFunctional.py +3 -10
- edsl/questions/derived/QuestionTopK.py +0 -2
- edsl/questions/question_registry.py +6 -36
- edsl/results/Dataset.py +15 -146
- edsl/results/DatasetExportMixin.py +217 -231
- edsl/results/DatasetTree.py +4 -134
- edsl/results/Result.py +16 -31
- edsl/results/Results.py +65 -159
- edsl/scenarios/FileStore.py +13 -187
- edsl/scenarios/Scenario.py +18 -73
- edsl/scenarios/ScenarioList.py +76 -251
- edsl/surveys/MemoryPlan.py +1 -1
- edsl/surveys/Rule.py +5 -1
- edsl/surveys/RuleCollection.py +1 -1
- edsl/surveys/Survey.py +19 -25
- edsl/surveys/SurveyFlowVisualizationMixin.py +9 -67
- edsl/surveys/instructions/ChangeInstruction.py +7 -9
- edsl/surveys/instructions/Instruction.py +7 -21
- edsl/templates/error_reporting/interview_details.html +3 -3
- edsl/templates/error_reporting/interviews.html +9 -18
- edsl/utilities/utilities.py +0 -15
- {edsl-0.1.38.dist-info → edsl-0.1.38.dev1.dist-info}/METADATA +1 -2
- {edsl-0.1.38.dist-info → edsl-0.1.38.dev1.dist-info}/RECORD +77 -71
- edsl/exceptions/cache.py +0 -5
- edsl/inference_services/PerplexityService.py +0 -163
- edsl/jobs/JobsChecks.py +0 -147
- edsl/jobs/JobsPrompts.py +0 -268
- edsl/jobs/JobsRemoteInferenceHandler.py +0 -239
- edsl/results/CSSParameterizer.py +0 -108
- edsl/results/TableDisplay.py +0 -198
- edsl/results/table_display.css +0 -78
- edsl/scenarios/ScenarioJoin.py +0 -127
- {edsl-0.1.38.dist-info → edsl-0.1.38.dev1.dist-info}/LICENSE +0 -0
- {edsl-0.1.38.dist-info → edsl-0.1.38.dev1.dist-info}/WHEEL +0 -0
edsl/Base.py
CHANGED
@@ -9,46 +9,37 @@ from uuid import UUID
|
|
9
9
|
|
10
10
|
# from edsl.utilities.MethodSuggesterMixin import MethodSuggesterMixin
|
11
11
|
|
12
|
-
from edsl.utilities.utilities import is_notebook
|
13
|
-
|
14
12
|
|
15
13
|
class RichPrintingMixin:
|
16
|
-
|
17
|
-
|
18
|
-
# def print(self):
|
19
|
-
# print(self)
|
20
|
-
|
14
|
+
"""Mixin for rich printing and persistence of objects."""
|
21
15
|
|
22
|
-
|
16
|
+
def _for_console(self):
|
17
|
+
"""Return a string representation of the object for console printing."""
|
18
|
+
from rich.console import Console
|
23
19
|
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
with io.StringIO() as buf:
|
21
|
+
console = Console(file=buf, record=True)
|
22
|
+
table = self.rich_print()
|
23
|
+
console.print(table)
|
24
|
+
return console.export_text()
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# console.print(table)
|
32
|
-
# return console.export_text()
|
33
|
-
|
34
|
-
# def __str__(self):
|
35
|
-
# """Return a string representation of the object for console printing."""
|
36
|
-
# # return self._for_console()
|
37
|
-
# return self.__repr__()
|
26
|
+
def __str__(self):
|
27
|
+
"""Return a string representation of the object for console printing."""
|
28
|
+
return self._for_console()
|
38
29
|
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
def print(self):
|
31
|
+
"""Print the object to the console."""
|
32
|
+
from edsl.utilities.utilities import is_notebook
|
42
33
|
|
43
|
-
|
44
|
-
|
34
|
+
if is_notebook():
|
35
|
+
from IPython.display import display
|
45
36
|
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
display(self.rich_print())
|
38
|
+
else:
|
39
|
+
from rich.console import Console
|
49
40
|
|
50
|
-
|
51
|
-
|
41
|
+
console = Console()
|
42
|
+
console.print(self.rich_print())
|
52
43
|
|
53
44
|
|
54
45
|
class PersistenceMixin:
|
@@ -210,7 +201,7 @@ class DiffMethodsMixin:
|
|
210
201
|
|
211
202
|
|
212
203
|
class Base(
|
213
|
-
|
204
|
+
RichPrintingMixin,
|
214
205
|
PersistenceMixin,
|
215
206
|
DiffMethodsMixin,
|
216
207
|
ABC,
|
@@ -218,36 +209,16 @@ class Base(
|
|
218
209
|
):
|
219
210
|
"""Base class for all classes in the package."""
|
220
211
|
|
221
|
-
def
|
222
|
-
|
223
|
-
|
224
|
-
def print(self, **kwargs):
|
225
|
-
if "format" in kwargs:
|
226
|
-
if kwargs["format"] not in ["html", "markdown", "rich", "latex"]:
|
227
|
-
raise ValueError(f"Format '{kwargs['format']}' not supported.")
|
212
|
+
# def __getitem__(self, key):
|
213
|
+
# return getattr(self, key)
|
228
214
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
return self
|
215
|
+
# @abstractmethod
|
216
|
+
# def _repr_html_(self) -> str:
|
217
|
+
# raise NotImplementedError("This method is not implemented yet.")
|
233
218
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
def summary(self, format="table"):
|
238
|
-
from edsl import Scenario
|
239
|
-
|
240
|
-
d = self._summary()
|
241
|
-
if format == "table":
|
242
|
-
return Scenario(d).table()
|
243
|
-
if format == "dict":
|
244
|
-
return d
|
245
|
-
if format == "json":
|
246
|
-
return Scenario(d).json()
|
247
|
-
if format == "yaml":
|
248
|
-
return Scenario(d).yaml()
|
249
|
-
if format == "html":
|
250
|
-
return Scenario(d).table(tablefmt="html")
|
219
|
+
# @abstractmethod
|
220
|
+
# def _repr_(self) -> str:
|
221
|
+
# raise NotImplementedError("This method is not implemented yet.")
|
251
222
|
|
252
223
|
def keys(self):
|
253
224
|
"""Return the keys of the object."""
|
@@ -285,10 +256,10 @@ class Base(
|
|
285
256
|
|
286
257
|
if not isinstance(other, self.__class__):
|
287
258
|
return False
|
288
|
-
if "sort" in inspect.signature(self.
|
289
|
-
return self.
|
259
|
+
if "sort" in inspect.signature(self._to_dict).parameters:
|
260
|
+
return self._to_dict(sort=True) == other._to_dict(sort=True)
|
290
261
|
else:
|
291
|
-
return self.
|
262
|
+
return self._to_dict() == other._to_dict()
|
292
263
|
|
293
264
|
@abstractmethod
|
294
265
|
def example():
|
edsl/BaseDiff.py
CHANGED
@@ -25,7 +25,7 @@ class DummyObject:
|
|
25
25
|
def __init__(self, object_dict):
|
26
26
|
self.object_dict = object_dict
|
27
27
|
|
28
|
-
def
|
28
|
+
def _to_dict(self):
|
29
29
|
return self.object_dict
|
30
30
|
|
31
31
|
|
@@ -38,12 +38,12 @@ class BaseDiff:
|
|
38
38
|
self.obj1 = obj1
|
39
39
|
self.obj2 = obj2
|
40
40
|
|
41
|
-
if "sort" in inspect.signature(obj1.
|
42
|
-
self._dict1 = obj1.
|
43
|
-
self._dict2 = obj2.
|
41
|
+
if "sort" in inspect.signature(obj1._to_dict).parameters:
|
42
|
+
self._dict1 = obj1._to_dict(sort=True)
|
43
|
+
self._dict2 = obj2._to_dict(sort=True)
|
44
44
|
else:
|
45
|
-
self._dict1 = obj1.
|
46
|
-
self._dict2 = obj2.
|
45
|
+
self._dict1 = obj1._to_dict()
|
46
|
+
self._dict2 = obj2._to_dict()
|
47
47
|
self._obj_class = type(obj1)
|
48
48
|
|
49
49
|
self.added = added
|
@@ -139,7 +139,7 @@ class BaseDiff:
|
|
139
139
|
def apply(self, obj: Any):
|
140
140
|
"""Apply the diff to the object."""
|
141
141
|
|
142
|
-
new_obj_dict = obj.
|
142
|
+
new_obj_dict = obj._to_dict()
|
143
143
|
for k, v in self.added.items():
|
144
144
|
new_obj_dict[k] = v
|
145
145
|
for k in self.removed.keys():
|
edsl/__init__.py
CHANGED
@@ -41,8 +41,7 @@ from edsl.shared import shared_globals
|
|
41
41
|
from edsl.jobs.Jobs import Jobs
|
42
42
|
from edsl.notebooks.Notebook import Notebook
|
43
43
|
from edsl.study.Study import Study
|
44
|
-
|
45
|
-
# from edsl.conjure.Conjure import Conjure
|
44
|
+
from edsl.conjure.Conjure import Conjure
|
46
45
|
from edsl.coop.coop import Coop
|
47
46
|
|
48
47
|
from edsl.surveys.instructions.Instruction import Instruction
|
edsl/__version__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.38"
|
1
|
+
__version__ = "0.1.38.dev1"
|
edsl/agents/Agent.py
CHANGED
@@ -243,15 +243,6 @@ class Agent(Base):
|
|
243
243
|
else:
|
244
244
|
return self._traits
|
245
245
|
|
246
|
-
def _repr_html_(self):
|
247
|
-
# d = self.to_dict(add_edsl_version=False)
|
248
|
-
d = self.traits
|
249
|
-
data = [[k, v] for k, v in d.items()]
|
250
|
-
from tabulate import tabulate
|
251
|
-
|
252
|
-
table = str(tabulate(data, headers=["keys", "values"], tablefmt="html"))
|
253
|
-
return f"<pre>{table}</pre>"
|
254
|
-
|
255
246
|
def rename(
|
256
247
|
self, old_name_or_dict: Union[str, dict], new_name: Optional[str] = None
|
257
248
|
) -> Agent:
|
@@ -640,10 +631,10 @@ class Agent(Base):
|
|
640
631
|
]
|
641
632
|
return f"{class_name}({', '.join(items)})"
|
642
633
|
|
643
|
-
|
644
|
-
|
634
|
+
def _repr_html_(self):
|
635
|
+
from edsl.utilities.utilities import data_to_html
|
645
636
|
|
646
|
-
|
637
|
+
return data_to_html(self.to_dict())
|
647
638
|
|
648
639
|
#######################
|
649
640
|
# SERIALIZATION METHODS
|
@@ -703,10 +694,14 @@ class Agent(Base):
|
|
703
694
|
def __hash__(self) -> int:
|
704
695
|
from edsl.utilities.utilities import dict_hash
|
705
696
|
|
706
|
-
return dict_hash(self.
|
697
|
+
return dict_hash(self._to_dict())
|
707
698
|
|
708
|
-
|
709
|
-
|
699
|
+
def _to_dict(self) -> dict[str, Union[dict, bool]]:
|
700
|
+
"""Serialize to a dictionary without EDSL info"""
|
701
|
+
return self.data
|
702
|
+
|
703
|
+
@add_edsl_version
|
704
|
+
def to_dict(self) -> dict[str, Union[dict, bool]]:
|
710
705
|
"""Serialize to a dictionary with EDSL info.
|
711
706
|
|
712
707
|
Example usage:
|
@@ -715,14 +710,7 @@ class Agent(Base):
|
|
715
710
|
>>> a.to_dict()
|
716
711
|
{'name': 'Steve', 'traits': {'age': 10, 'hair': 'brown', 'height': 5.5}, 'edsl_version': '...', 'edsl_class_name': 'Agent'}
|
717
712
|
"""
|
718
|
-
|
719
|
-
if add_edsl_version:
|
720
|
-
from edsl import __version__
|
721
|
-
|
722
|
-
d["edsl_version"] = __version__
|
723
|
-
d["edsl_class_name"] = self.__class__.__name__
|
724
|
-
|
725
|
-
return d
|
713
|
+
return self._to_dict()
|
726
714
|
|
727
715
|
@classmethod
|
728
716
|
@remove_edsl_version
|
edsl/agents/AgentList.py
CHANGED
@@ -14,7 +14,7 @@ from __future__ import annotations
|
|
14
14
|
import csv
|
15
15
|
import json
|
16
16
|
from collections import UserList
|
17
|
-
from typing import Any, List, Optional, Union
|
17
|
+
from typing import Any, List, Optional, Union
|
18
18
|
from rich import print_json
|
19
19
|
from rich.table import Table
|
20
20
|
from simpleeval import EvalWithCompoundTypes
|
@@ -23,11 +23,6 @@ from edsl.utilities.decorators import add_edsl_version, remove_edsl_version
|
|
23
23
|
|
24
24
|
from collections.abc import Iterable
|
25
25
|
|
26
|
-
from edsl.exceptions.agents import AgentListError
|
27
|
-
|
28
|
-
if TYPE_CHECKING:
|
29
|
-
from edsl.scenarios.ScenarioList import ScenarioList
|
30
|
-
|
31
26
|
|
32
27
|
def is_iterable(obj):
|
33
28
|
return isinstance(obj, Iterable)
|
@@ -36,10 +31,6 @@ def is_iterable(obj):
|
|
36
31
|
class AgentList(UserList, Base):
|
37
32
|
"""A list of Agents."""
|
38
33
|
|
39
|
-
__documentation__ = (
|
40
|
-
"https://docs.expectedparrot.com/en/latest/agents.html#agentlist-class"
|
41
|
-
)
|
42
|
-
|
43
34
|
def __init__(self, data: Optional[list["Agent"]] = None):
|
44
35
|
"""Initialize a new AgentList.
|
45
36
|
|
@@ -61,7 +52,7 @@ class AgentList(UserList, Base):
|
|
61
52
|
random.shuffle(self.data)
|
62
53
|
return self
|
63
54
|
|
64
|
-
def sample(self, n: int, seed
|
55
|
+
def sample(self, n: int, seed="edsl") -> AgentList:
|
65
56
|
"""Return a random sample of agents.
|
66
57
|
|
67
58
|
:param n: The number of agents to sample.
|
@@ -69,17 +60,9 @@ class AgentList(UserList, Base):
|
|
69
60
|
"""
|
70
61
|
import random
|
71
62
|
|
72
|
-
|
73
|
-
random.seed(seed)
|
63
|
+
random.seed(seed)
|
74
64
|
return AgentList(random.sample(self.data, n))
|
75
65
|
|
76
|
-
def to_pandas(self):
|
77
|
-
"""Return a pandas DataFrame."""
|
78
|
-
return self.to_scenario_list().to_pandas()
|
79
|
-
|
80
|
-
def tally(self):
|
81
|
-
return self.to_scenario_list().tally()
|
82
|
-
|
83
66
|
def rename(self, old_name, new_name):
|
84
67
|
"""Rename a trait in the AgentList.
|
85
68
|
|
@@ -130,7 +113,7 @@ class AgentList(UserList, Base):
|
|
130
113
|
]
|
131
114
|
except Exception as e:
|
132
115
|
print(f"Exception:{e}")
|
133
|
-
raise
|
116
|
+
raise Exception(f"Error in filter. Exception:{e}")
|
134
117
|
|
135
118
|
return AgentList(new_data)
|
136
119
|
|
@@ -216,8 +199,7 @@ class AgentList(UserList, Base):
|
|
216
199
|
>>> al.add_trait('new_trait', [1, 2, 3])
|
217
200
|
Traceback (most recent call last):
|
218
201
|
...
|
219
|
-
|
220
|
-
...
|
202
|
+
ValueError: The passed values have to be the same length as the agent list.
|
221
203
|
"""
|
222
204
|
if not is_iterable(values):
|
223
205
|
value = values
|
@@ -226,7 +208,7 @@ class AgentList(UserList, Base):
|
|
226
208
|
return self
|
227
209
|
|
228
210
|
if len(values) != len(self):
|
229
|
-
raise
|
211
|
+
raise ValueError(
|
230
212
|
"The passed values have to be the same length as the agent list."
|
231
213
|
)
|
232
214
|
for agent, value in zip(self.data, values):
|
@@ -246,89 +228,47 @@ class AgentList(UserList, Base):
|
|
246
228
|
def __hash__(self) -> int:
|
247
229
|
from edsl.utilities.utilities import dict_hash
|
248
230
|
|
249
|
-
|
231
|
+
data = self.to_dict()
|
232
|
+
# data['agent_list'] = sorted(data['agent_list'], key=lambda x: dict_hash(x)
|
233
|
+
return dict_hash(self._to_dict(sorted=True))
|
250
234
|
|
251
|
-
def
|
252
|
-
"""Serialize the AgentList to a dictionary."""
|
235
|
+
def _to_dict(self, sorted=False):
|
253
236
|
if sorted:
|
254
237
|
data = self.data[:]
|
255
238
|
data.sort(key=lambda x: hash(x))
|
256
239
|
else:
|
257
240
|
data = self.data
|
258
241
|
|
259
|
-
|
260
|
-
"agent_list": [
|
261
|
-
agent.to_dict(add_edsl_version=add_edsl_version) for agent in data
|
262
|
-
]
|
263
|
-
}
|
264
|
-
if add_edsl_version:
|
265
|
-
from edsl import __version__
|
266
|
-
|
267
|
-
d["edsl_version"] = __version__
|
268
|
-
d["edsl_class_name"] = "AgentList"
|
269
|
-
|
270
|
-
return d
|
242
|
+
return {"agent_list": [agent.to_dict() for agent in data]}
|
271
243
|
|
272
244
|
def __eq__(self, other: AgentList) -> bool:
|
273
|
-
return self.
|
274
|
-
|
275
|
-
|
245
|
+
return self._to_dict(sorted=True) == other._to_dict(sorted=True)
|
246
|
+
|
247
|
+
@add_edsl_version
|
248
|
+
def to_dict(self):
|
249
|
+
"""Return dictionary of AgentList to serialization."""
|
250
|
+
return self._to_dict()
|
276
251
|
|
277
252
|
def __repr__(self):
|
278
253
|
return f"AgentList({self.data})"
|
279
254
|
|
280
|
-
def
|
281
|
-
|
282
|
-
|
283
|
-
"Number of agents": len(self),
|
284
|
-
"Agent trait fields": self.all_traits,
|
285
|
-
}
|
255
|
+
def print(self, format: Optional[str] = None):
|
256
|
+
"""Print the AgentList."""
|
257
|
+
print_json(json.dumps(self._to_dict()))
|
286
258
|
|
287
259
|
def _repr_html_(self):
|
288
260
|
"""Return an HTML representation of the AgentList."""
|
289
|
-
|
290
|
-
return str(self.summary(format="html")) + footer
|
291
|
-
|
292
|
-
def to_csv(self, file_path: str):
|
293
|
-
"""Save the AgentList to a CSV file.
|
261
|
+
from edsl.utilities.utilities import data_to_html
|
294
262
|
|
295
|
-
|
296
|
-
"""
|
297
|
-
self.to_scenario_list().to_csv(file_path)
|
263
|
+
return data_to_html(self.to_dict()["agent_list"])
|
298
264
|
|
299
|
-
def
|
300
|
-
"""Return a list of tuples."""
|
301
|
-
return self.to_scenario_list(include_agent_name).to_list()
|
302
|
-
|
303
|
-
def to_scenario_list(self, include_agent_name=False) -> ScenarioList:
|
265
|
+
def to_scenario_list(self) -> "ScenarioList":
|
304
266
|
"""Return a list of scenarios."""
|
305
267
|
from edsl.scenarios.ScenarioList import ScenarioList
|
306
268
|
from edsl.scenarios.Scenario import Scenario
|
307
269
|
|
308
|
-
if include_agent_name:
|
309
|
-
return ScenarioList(
|
310
|
-
[
|
311
|
-
Scenario(agent.traits | {"agent_name": agent.name})
|
312
|
-
for agent in self.data
|
313
|
-
]
|
314
|
-
)
|
315
270
|
return ScenarioList([Scenario(agent.traits) for agent in self.data])
|
316
271
|
|
317
|
-
def table(
|
318
|
-
self,
|
319
|
-
*fields,
|
320
|
-
tablefmt: Optional[str] = None,
|
321
|
-
pretty_labels: Optional[dict] = None,
|
322
|
-
) -> Table:
|
323
|
-
return (
|
324
|
-
self.to_scenario_list()
|
325
|
-
.to_dataset()
|
326
|
-
.table(*fields, tablefmt=tablefmt, pretty_labels=pretty_labels)
|
327
|
-
)
|
328
|
-
|
329
|
-
def tree(self, node_order: Optional[List[str]] = None):
|
330
|
-
return self.to_scenario_list().tree(node_order)
|
331
|
-
|
332
272
|
@classmethod
|
333
273
|
@remove_edsl_version
|
334
274
|
def from_dict(cls, data: dict) -> "AgentList":
|
@@ -363,9 +303,6 @@ class AgentList(UserList, Base):
|
|
363
303
|
|
364
304
|
:param trait_name: The name of the trait.
|
365
305
|
:param values: A list of values.
|
366
|
-
|
367
|
-
>>> AgentList.from_list('age', [22, 23])
|
368
|
-
AgentList([Agent(traits = {'age': 22}), Agent(traits = {'age': 23})])
|
369
306
|
"""
|
370
307
|
from edsl.agents.Agent import Agent
|
371
308
|
|
edsl/agents/Invigilator.py
CHANGED
@@ -45,10 +45,6 @@ class InvigilatorAI(InvigilatorBase):
|
|
45
45
|
|
46
46
|
params.update({"iteration": self.iteration, "cache": self.cache})
|
47
47
|
|
48
|
-
params.update({"invigilator": self})
|
49
|
-
# if hasattr(self.question, "answer_template"):
|
50
|
-
# breakpoint()
|
51
|
-
|
52
48
|
agent_response_dict: AgentResponseDict = await self.model.async_get_response(
|
53
49
|
**params
|
54
50
|
)
|
@@ -87,26 +83,19 @@ class InvigilatorAI(InvigilatorBase):
|
|
87
83
|
exception_occurred = None
|
88
84
|
validated = False
|
89
85
|
try:
|
90
|
-
# if the question has jinja parameters, it
|
86
|
+
# if the question has jinja parameters, it might be easier to make a new question
|
87
|
+
# with those all filled in & then validate that
|
88
|
+
# breakpoint()
|
91
89
|
if self.question.parameters:
|
92
90
|
prior_answers_dict = self.prompt_constructor.prior_answers_dict()
|
93
|
-
|
94
|
-
# question options have be treated differently because of dynamic question
|
95
|
-
# this logic is all in the prompt constructor
|
96
|
-
if "question_options" in self.question.data:
|
97
|
-
new_question_options = (
|
98
|
-
self.prompt_constructor._get_question_options(
|
99
|
-
self.question.data
|
100
|
-
)
|
101
|
-
)
|
102
|
-
if new_question_options != self.question.data["question_options"]:
|
103
|
-
# I don't love this direct writing but it seems to work
|
104
|
-
self.question.question_options = new_question_options
|
105
|
-
|
106
91
|
question_with_validators = self.question.render(
|
107
92
|
self.scenario | prior_answers_dict
|
108
93
|
)
|
109
94
|
question_with_validators.use_code = self.question.use_code
|
95
|
+
# if question_with_validators.parameters:
|
96
|
+
# raise ValueError(
|
97
|
+
# f"The question still has parameters after rendering: {question_with_validators}"
|
98
|
+
# )
|
110
99
|
else:
|
111
100
|
question_with_validators = self.question
|
112
101
|
|
edsl/agents/InvigilatorBase.py
CHANGED
@@ -172,6 +172,25 @@ class InvigilatorBase(ABC):
|
|
172
172
|
}
|
173
173
|
return EDSLResultObjectInput(**data)
|
174
174
|
|
175
|
+
# breakpoint()
|
176
|
+
# if hasattr(self, "augmented_model_response"):
|
177
|
+
# import json
|
178
|
+
|
179
|
+
# generated_tokens = json.loads(self.augmented_model_response)["answer"][
|
180
|
+
# "generated_tokens"
|
181
|
+
# ]
|
182
|
+
# else:
|
183
|
+
# generated_tokens = "Filled in by InvigilatorBase.get_failed_task_result"
|
184
|
+
# agent_response_dict = AgentResponseDict(
|
185
|
+
# answer=None,
|
186
|
+
# comment="Failed to get usable response",
|
187
|
+
# generated_tokens=generated_tokens,
|
188
|
+
# question_name=self.question.question_name,
|
189
|
+
# prompts=self.get_prompts(),
|
190
|
+
# )
|
191
|
+
# # breakpoint()
|
192
|
+
# return agent_response_dict
|
193
|
+
|
175
194
|
def get_prompts(self) -> Dict[str, Prompt]:
|
176
195
|
"""Return the prompt used."""
|
177
196
|
|
edsl/agents/PromptConstructor.py
CHANGED
@@ -169,8 +169,6 @@ class PromptConstructor:
|
|
169
169
|
|
170
170
|
placeholder = ["<< Option 1 - Placholder >>", "<< Option 2 - Placholder >>"]
|
171
171
|
|
172
|
-
# print("Question options entry: ", question_options_entry)
|
173
|
-
|
174
172
|
if isinstance(question_options_entry, str):
|
175
173
|
env = Environment()
|
176
174
|
parsed_content = env.parse(question_options_entry)
|
@@ -202,12 +200,13 @@ class PromptConstructor:
|
|
202
200
|
# e.g., {'question_text': 'Do you like school?', 'question_name': 'q0', 'question_options': ['yes', 'no']}
|
203
201
|
question_data = self.question.data.copy()
|
204
202
|
|
205
|
-
if
|
206
|
-
"question_options" in question_data
|
207
|
-
): # is this a question with question options?
|
203
|
+
if "question_options" in question_data:
|
208
204
|
question_options = self._get_question_options(question_data)
|
209
205
|
question_data["question_options"] = question_options
|
210
206
|
|
207
|
+
# check to see if the question_options is actually a string
|
208
|
+
# This is used when the user is using the question_options as a variable from a scenario
|
209
|
+
# if "question_options" in question_data:
|
211
210
|
replacement_dict = self.build_replacement_dict(question_data)
|
212
211
|
rendered_instructions = question_prompt.render(replacement_dict)
|
213
212
|
|
@@ -15,7 +15,7 @@ from edsl.surveys.Survey import Survey
|
|
15
15
|
from edsl.questions.QuestionMultipleChoice import QuestionMultipleChoice
|
16
16
|
from edsl.questions.QuestionFreeText import QuestionFreeText
|
17
17
|
from edsl.auto.utilities import gen_pipeline
|
18
|
-
from edsl.
|
18
|
+
from edsl.conjure.naming_utilities import sanitize_string
|
19
19
|
|
20
20
|
|
21
21
|
m = Model()
|
edsl/auto/utilities.py
CHANGED
@@ -2,7 +2,7 @@ from textwrap import dedent
|
|
2
2
|
import random
|
3
3
|
from typing import List, TypeVar, Generator, Optional
|
4
4
|
from edsl.auto.StageBase import StageBase
|
5
|
-
from edsl.
|
5
|
+
from edsl.conjure.naming_utilities import sanitize_string
|
6
6
|
from edsl import Agent, Survey, Model, Cache, AgentList
|
7
7
|
from edsl import QuestionFreeText, Scenario
|
8
8
|
from edsl import QuestionMultipleChoice, Scenario, Agent, ScenarioList
|
edsl/base/Base.py
CHANGED
@@ -229,16 +229,26 @@ class Base(
|
|
229
229
|
|
230
230
|
return data_to_html(self.to_dict())
|
231
231
|
|
232
|
+
# def html(self):
|
233
|
+
# html_string = self._repr_html_()
|
234
|
+
# import tempfile
|
235
|
+
# import webbrowser
|
236
|
+
|
237
|
+
# with tempfile.NamedTemporaryFile("w", delete=False, suffix=".html") as f:
|
238
|
+
# # print("Writing HTML to", f.name)
|
239
|
+
# f.write(html_string)
|
240
|
+
# webbrowser.open(f.name)
|
241
|
+
|
232
242
|
def __eq__(self, other):
|
233
243
|
"""Return whether two objects are equal."""
|
234
244
|
import inspect
|
235
245
|
|
236
246
|
if not isinstance(other, self.__class__):
|
237
247
|
return False
|
238
|
-
if "sort" in inspect.signature(self.
|
239
|
-
return self.
|
248
|
+
if "sort" in inspect.signature(self._to_dict).parameters:
|
249
|
+
return self._to_dict(sort=True) == other._to_dict(sort=True)
|
240
250
|
else:
|
241
|
-
return self.
|
251
|
+
return self._to_dict() == other._to_dict()
|
242
252
|
|
243
253
|
@abstractmethod
|
244
254
|
def example():
|
edsl/config.py
CHANGED
@@ -61,14 +61,6 @@ CONFIG_MAP = {
|
|
61
61
|
"default": "https://www.expectedparrot.com",
|
62
62
|
"info": "This config var holds the URL of the Expected Parrot API.",
|
63
63
|
},
|
64
|
-
"EDSL_MAX_CONCURRENT_TASKS": {
|
65
|
-
"default": "500",
|
66
|
-
"info": "This config var determines the maximum number of concurrent tasks that can be run by the async job-runner",
|
67
|
-
},
|
68
|
-
"EDSL_OPEN_EXCEPTION_REPORT_URL": {
|
69
|
-
"default": "False",
|
70
|
-
"info": "This config var determines whether to open the exception report URL in the browser",
|
71
|
-
},
|
72
64
|
}
|
73
65
|
|
74
66
|
|