edsl 0.1.39__py3-none-any.whl → 0.1.39.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 +116 -197
- edsl/__init__.py +7 -15
- edsl/__version__.py +1 -1
- edsl/agents/Agent.py +147 -351
- edsl/agents/AgentList.py +73 -211
- edsl/agents/Invigilator.py +50 -101
- edsl/agents/InvigilatorBase.py +70 -62
- edsl/agents/PromptConstructor.py +225 -143
- edsl/agents/__init__.py +1 -0
- edsl/agents/prompt_helpers.py +3 -3
- edsl/auto/AutoStudy.py +5 -18
- edsl/auto/StageBase.py +40 -53
- edsl/auto/StageQuestions.py +1 -2
- edsl/auto/utilities.py +6 -0
- edsl/config.py +2 -22
- edsl/conversation/car_buying.py +1 -2
- edsl/coop/PriceFetcher.py +1 -1
- edsl/coop/coop.py +47 -125
- edsl/coop/utils.py +14 -14
- edsl/data/Cache.py +27 -45
- edsl/data/CacheEntry.py +15 -12
- edsl/data/CacheHandler.py +12 -31
- edsl/data/RemoteCacheSync.py +46 -154
- edsl/data/__init__.py +3 -4
- edsl/data_transfer_models.py +1 -2
- edsl/enums.py +0 -27
- edsl/exceptions/__init__.py +50 -50
- edsl/exceptions/agents.py +0 -12
- edsl/exceptions/questions.py +6 -24
- edsl/exceptions/scenarios.py +0 -7
- edsl/inference_services/AnthropicService.py +19 -38
- edsl/inference_services/AwsBedrock.py +2 -0
- edsl/inference_services/AzureAI.py +2 -0
- edsl/inference_services/GoogleService.py +12 -7
- edsl/inference_services/InferenceServiceABC.py +85 -18
- edsl/inference_services/InferenceServicesCollection.py +79 -120
- edsl/inference_services/MistralAIService.py +3 -0
- edsl/inference_services/OpenAIService.py +35 -47
- edsl/inference_services/PerplexityService.py +3 -0
- edsl/inference_services/TestService.py +10 -11
- edsl/inference_services/TogetherAIService.py +3 -5
- edsl/jobs/Answers.py +14 -1
- edsl/jobs/Jobs.py +431 -356
- edsl/jobs/JobsChecks.py +10 -35
- edsl/jobs/JobsPrompts.py +4 -6
- edsl/jobs/JobsRemoteInferenceHandler.py +133 -205
- edsl/jobs/buckets/BucketCollection.py +3 -44
- edsl/jobs/buckets/TokenBucket.py +21 -53
- edsl/jobs/interviews/Interview.py +408 -143
- edsl/jobs/runners/JobsRunnerAsyncio.py +403 -88
- edsl/jobs/runners/JobsRunnerStatus.py +165 -133
- edsl/jobs/tasks/QuestionTaskCreator.py +19 -21
- edsl/jobs/tasks/TaskHistory.py +18 -38
- edsl/jobs/tasks/task_status_enum.py +2 -0
- edsl/language_models/KeyLookup.py +30 -0
- edsl/language_models/LanguageModel.py +236 -194
- edsl/language_models/ModelList.py +19 -28
- edsl/language_models/__init__.py +2 -1
- edsl/language_models/registry.py +190 -0
- edsl/language_models/repair.py +2 -2
- edsl/language_models/unused/ReplicateBase.py +83 -0
- edsl/language_models/utilities.py +4 -5
- edsl/notebooks/Notebook.py +14 -19
- edsl/prompts/Prompt.py +39 -29
- edsl/questions/{answer_validator_mixin.py → AnswerValidatorMixin.py} +2 -47
- edsl/questions/QuestionBase.py +214 -68
- edsl/questions/{question_base_gen_mixin.py → QuestionBaseGenMixin.py} +50 -57
- edsl/questions/QuestionBasePromptsMixin.py +3 -7
- edsl/questions/QuestionBudget.py +1 -1
- edsl/questions/QuestionCheckBox.py +3 -3
- edsl/questions/QuestionExtract.py +7 -5
- edsl/questions/QuestionFreeText.py +3 -2
- edsl/questions/QuestionList.py +18 -10
- edsl/questions/QuestionMultipleChoice.py +23 -67
- edsl/questions/QuestionNumerical.py +4 -2
- edsl/questions/QuestionRank.py +17 -7
- edsl/questions/{response_validator_abc.py → ResponseValidatorABC.py} +26 -40
- edsl/questions/SimpleAskMixin.py +3 -4
- edsl/questions/__init__.py +1 -2
- edsl/questions/derived/QuestionLinearScale.py +3 -6
- edsl/questions/derived/QuestionTopK.py +1 -1
- edsl/questions/descriptors.py +3 -17
- edsl/questions/question_registry.py +1 -1
- edsl/results/CSSParameterizer.py +1 -1
- edsl/results/Dataset.py +7 -170
- edsl/results/DatasetExportMixin.py +305 -168
- edsl/results/DatasetTree.py +8 -28
- edsl/results/Result.py +206 -298
- edsl/results/Results.py +131 -149
- edsl/results/ResultsDBMixin.py +238 -0
- edsl/results/ResultsExportMixin.py +0 -2
- edsl/results/{results_selector.py → Selector.py} +13 -23
- edsl/results/TableDisplay.py +171 -98
- edsl/results/__init__.py +1 -1
- edsl/scenarios/FileStore.py +239 -150
- edsl/scenarios/Scenario.py +193 -90
- edsl/scenarios/ScenarioHtmlMixin.py +3 -4
- edsl/scenarios/{scenario_join.py → ScenarioJoin.py} +6 -10
- edsl/scenarios/ScenarioList.py +244 -415
- edsl/scenarios/ScenarioListExportMixin.py +7 -0
- edsl/scenarios/ScenarioListPdfMixin.py +37 -15
- edsl/scenarios/__init__.py +2 -1
- edsl/study/ObjectEntry.py +1 -1
- edsl/study/SnapShot.py +1 -1
- edsl/study/Study.py +12 -5
- edsl/surveys/Rule.py +4 -5
- edsl/surveys/RuleCollection.py +27 -25
- edsl/surveys/Survey.py +791 -270
- edsl/surveys/SurveyCSS.py +8 -20
- edsl/surveys/{SurveyFlowVisualization.py → SurveyFlowVisualizationMixin.py} +9 -11
- edsl/surveys/__init__.py +2 -4
- edsl/surveys/descriptors.py +2 -6
- edsl/surveys/instructions/ChangeInstruction.py +2 -1
- edsl/surveys/instructions/Instruction.py +13 -4
- edsl/surveys/instructions/InstructionCollection.py +6 -11
- edsl/templates/error_reporting/interview_details.html +1 -1
- edsl/templates/error_reporting/report.html +1 -1
- edsl/tools/plotting.py +1 -1
- edsl/utilities/utilities.py +23 -35
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/METADATA +10 -12
- edsl-0.1.39.dev1.dist-info/RECORD +277 -0
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/WHEEL +1 -1
- edsl/agents/QuestionInstructionPromptBuilder.py +0 -128
- edsl/agents/QuestionTemplateReplacementsBuilder.py +0 -137
- edsl/agents/question_option_processor.py +0 -172
- edsl/coop/CoopFunctionsMixin.py +0 -15
- edsl/coop/ExpectedParrotKeyHandler.py +0 -125
- edsl/exceptions/inference_services.py +0 -5
- edsl/inference_services/AvailableModelCacheHandler.py +0 -184
- edsl/inference_services/AvailableModelFetcher.py +0 -215
- edsl/inference_services/ServiceAvailability.py +0 -135
- edsl/inference_services/data_structures.py +0 -134
- edsl/jobs/AnswerQuestionFunctionConstructor.py +0 -223
- edsl/jobs/FetchInvigilator.py +0 -47
- edsl/jobs/InterviewTaskManager.py +0 -98
- edsl/jobs/InterviewsConstructor.py +0 -50
- edsl/jobs/JobsComponentConstructor.py +0 -189
- edsl/jobs/JobsRemoteInferenceLogger.py +0 -239
- edsl/jobs/RequestTokenEstimator.py +0 -30
- edsl/jobs/async_interview_runner.py +0 -138
- edsl/jobs/buckets/TokenBucketAPI.py +0 -211
- edsl/jobs/buckets/TokenBucketClient.py +0 -191
- edsl/jobs/check_survey_scenario_compatibility.py +0 -85
- edsl/jobs/data_structures.py +0 -120
- edsl/jobs/decorators.py +0 -35
- edsl/jobs/jobs_status_enums.py +0 -9
- edsl/jobs/loggers/HTMLTableJobLogger.py +0 -304
- edsl/jobs/results_exceptions_handler.py +0 -98
- edsl/language_models/ComputeCost.py +0 -63
- edsl/language_models/PriceManager.py +0 -127
- edsl/language_models/RawResponseHandler.py +0 -106
- edsl/language_models/ServiceDataSources.py +0 -0
- edsl/language_models/key_management/KeyLookup.py +0 -63
- edsl/language_models/key_management/KeyLookupBuilder.py +0 -273
- edsl/language_models/key_management/KeyLookupCollection.py +0 -38
- edsl/language_models/key_management/__init__.py +0 -0
- edsl/language_models/key_management/models.py +0 -131
- edsl/language_models/model.py +0 -256
- edsl/notebooks/NotebookToLaTeX.py +0 -142
- edsl/questions/ExceptionExplainer.py +0 -77
- edsl/questions/HTMLQuestion.py +0 -103
- edsl/questions/QuestionMatrix.py +0 -265
- edsl/questions/data_structures.py +0 -20
- edsl/questions/loop_processor.py +0 -149
- edsl/questions/response_validator_factory.py +0 -34
- edsl/questions/templates/matrix/__init__.py +0 -1
- edsl/questions/templates/matrix/answering_instructions.jinja +0 -5
- edsl/questions/templates/matrix/question_presentation.jinja +0 -20
- edsl/results/MarkdownToDocx.py +0 -122
- edsl/results/MarkdownToPDF.py +0 -111
- edsl/results/TextEditor.py +0 -50
- edsl/results/file_exports.py +0 -252
- edsl/results/smart_objects.py +0 -96
- edsl/results/table_data_class.py +0 -12
- edsl/results/table_renderers.py +0 -118
- edsl/scenarios/ConstructDownloadLink.py +0 -109
- edsl/scenarios/DocumentChunker.py +0 -102
- edsl/scenarios/DocxScenario.py +0 -16
- edsl/scenarios/PdfExtractor.py +0 -40
- edsl/scenarios/directory_scanner.py +0 -96
- edsl/scenarios/file_methods.py +0 -85
- edsl/scenarios/handlers/__init__.py +0 -13
- edsl/scenarios/handlers/csv.py +0 -49
- edsl/scenarios/handlers/docx.py +0 -76
- edsl/scenarios/handlers/html.py +0 -37
- edsl/scenarios/handlers/json.py +0 -111
- edsl/scenarios/handlers/latex.py +0 -5
- edsl/scenarios/handlers/md.py +0 -51
- edsl/scenarios/handlers/pdf.py +0 -68
- edsl/scenarios/handlers/png.py +0 -39
- edsl/scenarios/handlers/pptx.py +0 -105
- edsl/scenarios/handlers/py.py +0 -294
- edsl/scenarios/handlers/sql.py +0 -313
- edsl/scenarios/handlers/sqlite.py +0 -149
- edsl/scenarios/handlers/txt.py +0 -33
- edsl/scenarios/scenario_selector.py +0 -156
- edsl/surveys/ConstructDAG.py +0 -92
- edsl/surveys/EditSurvey.py +0 -221
- edsl/surveys/InstructionHandler.py +0 -100
- edsl/surveys/MemoryManagement.py +0 -72
- edsl/surveys/RuleManager.py +0 -172
- edsl/surveys/Simulator.py +0 -75
- edsl/surveys/SurveyToApp.py +0 -141
- edsl/utilities/PrettyList.py +0 -56
- edsl/utilities/is_notebook.py +0 -18
- edsl/utilities/is_valid_variable_name.py +0 -11
- edsl/utilities/remove_edsl_version.py +0 -24
- edsl-0.1.39.dist-info/RECORD +0 -358
- /edsl/questions/{register_questions_meta.py → RegisterQuestionsMeta.py} +0 -0
- /edsl/results/{results_fetch_mixin.py → ResultsFetchMixin.py} +0 -0
- /edsl/results/{results_tools_mixin.py → ResultsToolsMixin.py} +0 -0
- {edsl-0.1.39.dist-info → edsl-0.1.39.dev1.dist-info}/LICENSE +0 -0
edsl/Base.py
CHANGED
@@ -2,22 +2,61 @@
|
|
2
2
|
|
3
3
|
from abc import ABC, abstractmethod, ABCMeta
|
4
4
|
import gzip
|
5
|
+
import io
|
5
6
|
import json
|
6
7
|
from typing import Any, Optional, Union
|
7
8
|
from uuid import UUID
|
8
9
|
|
10
|
+
# from edsl.utilities.MethodSuggesterMixin import MethodSuggesterMixin
|
11
|
+
|
12
|
+
from edsl.utilities.utilities import is_notebook
|
13
|
+
|
14
|
+
|
15
|
+
class RichPrintingMixin:
|
16
|
+
pass
|
17
|
+
|
18
|
+
# def print(self):
|
19
|
+
# print(self)
|
20
|
+
|
21
|
+
|
22
|
+
# """Mixin for rich printing and persistence of objects."""
|
23
|
+
|
24
|
+
# def _for_console(self):
|
25
|
+
# """Return a string representation of the object for console printing."""
|
26
|
+
# from rich.console import Console
|
27
|
+
|
28
|
+
# with io.StringIO() as buf:
|
29
|
+
# console = Console(file=buf, record=True)
|
30
|
+
# table = self.rich_print()
|
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__()
|
38
|
+
|
39
|
+
# def print(self):
|
40
|
+
# """Print the object to the console."""
|
41
|
+
# from edsl.utilities.utilities import is_notebook
|
42
|
+
|
43
|
+
# if is_notebook():
|
44
|
+
# from IPython.display import display
|
45
|
+
|
46
|
+
# display(self.rich_print())
|
47
|
+
# else:
|
48
|
+
# from rich.console import Console
|
49
|
+
|
50
|
+
# console = Console()
|
51
|
+
# console.print(self.rich_print())
|
52
|
+
|
9
53
|
|
10
54
|
class PersistenceMixin:
|
11
55
|
"""Mixin for saving and loading objects to and from files."""
|
12
56
|
|
13
|
-
def duplicate(self, add_edsl_version=False):
|
14
|
-
"""Return a duplicate of the object."""
|
15
|
-
return self.from_dict(self.to_dict(add_edsl_version=False))
|
16
|
-
|
17
57
|
def push(
|
18
58
|
self,
|
19
59
|
description: Optional[str] = None,
|
20
|
-
alias: Optional[str] = None,
|
21
60
|
visibility: Optional[str] = "unlisted",
|
22
61
|
expected_parrot_url: Optional[str] = None,
|
23
62
|
):
|
@@ -25,41 +64,7 @@ class PersistenceMixin:
|
|
25
64
|
from edsl.coop import Coop
|
26
65
|
|
27
66
|
c = Coop(url=expected_parrot_url)
|
28
|
-
return c.create(self, description,
|
29
|
-
|
30
|
-
def to_yaml(self, add_edsl_version=False, filename: str = None) -> Union[str, None]:
|
31
|
-
import yaml
|
32
|
-
|
33
|
-
output = yaml.dump(self.to_dict(add_edsl_version=add_edsl_version))
|
34
|
-
if not filename:
|
35
|
-
return output
|
36
|
-
|
37
|
-
with open(filename, "w") as f:
|
38
|
-
f.write(output)
|
39
|
-
|
40
|
-
@classmethod
|
41
|
-
def from_yaml(cls, yaml_str: Optional[str] = None, filename: Optional[str] = None):
|
42
|
-
if yaml_str is None and filename is not None:
|
43
|
-
with open(filename, "r") as f:
|
44
|
-
yaml_str = f.read()
|
45
|
-
return cls.from_yaml(yaml_str=yaml_str)
|
46
|
-
elif yaml_str and filename is None:
|
47
|
-
import yaml
|
48
|
-
|
49
|
-
d = yaml.load(yaml_str, Loader=yaml.FullLoader)
|
50
|
-
return cls.from_dict(d)
|
51
|
-
else:
|
52
|
-
raise ValueError("Either yaml_str or filename must be provided.")
|
53
|
-
|
54
|
-
def create_download_link(self):
|
55
|
-
from tempfile import NamedTemporaryFile
|
56
|
-
from edsl.scenarios.FileStore import FileStore
|
57
|
-
|
58
|
-
with NamedTemporaryFile(suffix=".json.gz") as f:
|
59
|
-
self.save(f.name)
|
60
|
-
print(f.name)
|
61
|
-
fs = FileStore(path=f.name)
|
62
|
-
return fs.create_link()
|
67
|
+
return c.create(self, description, visibility)
|
63
68
|
|
64
69
|
@classmethod
|
65
70
|
def pull(
|
@@ -90,7 +95,6 @@ class PersistenceMixin:
|
|
90
95
|
uuid: Optional[Union[str, UUID]] = None,
|
91
96
|
url: Optional[str] = None,
|
92
97
|
description: Optional[str] = None,
|
93
|
-
alias: Optional[str] = None,
|
94
98
|
value: Optional[Any] = None,
|
95
99
|
visibility: Optional[str] = None,
|
96
100
|
):
|
@@ -103,7 +107,7 @@ class PersistenceMixin:
|
|
103
107
|
from edsl.coop import Coop
|
104
108
|
|
105
109
|
coop = Coop()
|
106
|
-
return coop.patch(uuid, url, description,
|
110
|
+
return coop.patch(uuid, url, description, value, visibility)
|
107
111
|
|
108
112
|
@classmethod
|
109
113
|
def search(cls, query):
|
@@ -113,13 +117,6 @@ class PersistenceMixin:
|
|
113
117
|
c = Coop()
|
114
118
|
return c.search(cls, query)
|
115
119
|
|
116
|
-
def store(self, d: dict, key_name: Optional[str] = None):
|
117
|
-
if key_name is None:
|
118
|
-
index = len(d)
|
119
|
-
else:
|
120
|
-
index = key_name
|
121
|
-
d[index] = self
|
122
|
-
|
123
120
|
def save(self, filename, compress=True):
|
124
121
|
"""Save the object to a file as zippped JSON.
|
125
122
|
|
@@ -129,9 +126,15 @@ class PersistenceMixin:
|
|
129
126
|
if filename.endswith("json.gz"):
|
130
127
|
import warnings
|
131
128
|
|
132
|
-
|
129
|
+
# warnings.warn(
|
130
|
+
# "Do not apply the file extensions. The filename should not end with 'json.gz'."
|
131
|
+
# )
|
132
|
+
filename = filename[:-7]
|
133
133
|
if filename.endswith("json"):
|
134
|
-
filename = filename[:-
|
134
|
+
filename = filename[:-4]
|
135
|
+
# warnings.warn(
|
136
|
+
# "Do not apply the file extensions. The filename should not end with 'json'."
|
137
|
+
# )
|
135
138
|
|
136
139
|
if compress:
|
137
140
|
full_file_name = filename + ".json.gz"
|
@@ -193,15 +196,9 @@ class RegisterSubclassesMeta(ABCMeta):
|
|
193
196
|
RegisterSubclassesMeta._registry[cls.__name__] = cls
|
194
197
|
|
195
198
|
@staticmethod
|
196
|
-
def get_registry(
|
199
|
+
def get_registry():
|
197
200
|
"""Return the registry of subclasses."""
|
198
|
-
|
199
|
-
exclude_classes = []
|
200
|
-
return {
|
201
|
-
k: v
|
202
|
-
for k, v in dict(RegisterSubclassesMeta._registry).items()
|
203
|
-
if k not in exclude_classes
|
204
|
-
}
|
201
|
+
return dict(RegisterSubclassesMeta._registry)
|
205
202
|
|
206
203
|
|
207
204
|
class DiffMethodsMixin:
|
@@ -212,147 +209,45 @@ class DiffMethodsMixin:
|
|
212
209
|
return BaseDiff(self, other)
|
213
210
|
|
214
211
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
212
|
+
class Base(
|
213
|
+
# RichPrintingMixin,
|
214
|
+
PersistenceMixin,
|
215
|
+
DiffMethodsMixin,
|
216
|
+
ABC,
|
217
|
+
metaclass=RegisterSubclassesMeta,
|
218
|
+
):
|
219
|
+
"""Base class for all classes in the package."""
|
222
220
|
|
223
|
-
class RepresentationMixin:
|
224
221
|
def json(self):
|
225
222
|
return json.loads(json.dumps(self.to_dict(add_edsl_version=False)))
|
226
223
|
|
227
|
-
def
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
def view(self):
|
233
|
-
"Displays an interactive / perspective view of the object"
|
234
|
-
return self.to_dataset().view()
|
235
|
-
|
236
|
-
# def print(self, format="rich"):
|
237
|
-
# return self.to_dataset().table()
|
238
|
-
|
239
|
-
def display_dict(self):
|
240
|
-
display_dict = {}
|
241
|
-
d = self.to_dict(add_edsl_version=False)
|
242
|
-
for key, value in d.items():
|
243
|
-
if isinstance(value, dict):
|
244
|
-
for k, v in value.items():
|
245
|
-
display_dict[f"{key}:{k}"] = v
|
246
|
-
elif isinstance(value, list):
|
247
|
-
for i, v in enumerate(value):
|
248
|
-
display_dict[f"{key}:{i}"] = v
|
249
|
-
else:
|
250
|
-
display_dict[key] = value
|
251
|
-
return display_dict
|
252
|
-
|
253
|
-
def print(self, format="rich"):
|
254
|
-
from rich.table import Table
|
255
|
-
from rich.console import Console
|
256
|
-
|
257
|
-
table = Table(title=self.__class__.__name__)
|
258
|
-
table.add_column("Key", style="bold")
|
259
|
-
table.add_column("Value", style="bold")
|
260
|
-
|
261
|
-
for key, value in self.display_dict().items():
|
262
|
-
table.add_row(key, str(value))
|
263
|
-
|
264
|
-
console = Console(record=True)
|
265
|
-
console.print(table)
|
266
|
-
|
267
|
-
def help(obj):
|
268
|
-
"""
|
269
|
-
Extract all public instance methods and their docstrings from a class instance.
|
270
|
-
|
271
|
-
Args:
|
272
|
-
obj: The instance to inspect
|
273
|
-
|
274
|
-
Returns:
|
275
|
-
dict: A dictionary where keys are method names and values are their docstrings
|
276
|
-
"""
|
277
|
-
import inspect
|
278
|
-
|
279
|
-
if inspect.isclass(obj):
|
280
|
-
raise TypeError("Please provide a class instance, not a class")
|
281
|
-
|
282
|
-
methods = {}
|
283
|
-
|
284
|
-
# Get all members of the instance
|
285
|
-
for name, member in inspect.getmembers(obj):
|
286
|
-
# Skip private and special methods (those starting with underscore)
|
287
|
-
if name.startswith("_"):
|
288
|
-
continue
|
289
|
-
|
290
|
-
# Check if it's specifically an instance method
|
291
|
-
if inspect.ismethod(member):
|
292
|
-
# Get the docstring (or empty string if none exists)
|
293
|
-
docstring = inspect.getdoc(member) or ""
|
294
|
-
methods[name] = docstring
|
295
|
-
|
296
|
-
from edsl.results.Dataset import Dataset
|
297
|
-
|
298
|
-
d = Dataset(
|
299
|
-
[
|
300
|
-
{"method": list(methods.keys())},
|
301
|
-
{"documentation": list(methods.values())},
|
302
|
-
]
|
303
|
-
)
|
304
|
-
return d
|
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.")
|
305
228
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
if hasattr(self, "_summary"):
|
310
|
-
summary_dict = self._summary()
|
311
|
-
summary_line = "".join([f" {k}: {v};" for k, v in summary_dict.items()])
|
312
|
-
class_name = self.__class__.__name__
|
313
|
-
docs = getattr(self, "__documentation__", "")
|
314
|
-
return (
|
315
|
-
"<p>"
|
316
|
-
+ f"<a href='{docs}'>{class_name}</a>"
|
317
|
-
+ summary_line
|
318
|
-
+ "</p>"
|
319
|
-
+ self.table()._repr_html_()
|
320
|
-
)
|
229
|
+
if hasattr(self, "table"):
|
230
|
+
return self.table()
|
321
231
|
else:
|
322
|
-
|
323
|
-
documenation = getattr(self, "__documentation__", "")
|
324
|
-
summary_line = "<p>" + f"<a href='{documenation}'>{class_name}</a>" + "</p>"
|
325
|
-
display_dict = self.display_dict()
|
326
|
-
return (
|
327
|
-
summary_line
|
328
|
-
+ TableDisplay.from_dictionary_wide(display_dict)._repr_html_()
|
329
|
-
)
|
232
|
+
return self
|
330
233
|
|
331
234
|
def __str__(self):
|
332
235
|
return self.__repr__()
|
333
236
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
RepresentationMixin,
|
349
|
-
PersistenceMixin,
|
350
|
-
DiffMethodsMixin,
|
351
|
-
HashingMixin,
|
352
|
-
ABC,
|
353
|
-
metaclass=RegisterSubclassesMeta,
|
354
|
-
):
|
355
|
-
"""Base class for all classes in the package."""
|
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")
|
356
251
|
|
357
252
|
def keys(self):
|
358
253
|
"""Return the keys of the object."""
|
@@ -369,11 +264,42 @@ class Base(
|
|
369
264
|
keys = self.keys()
|
370
265
|
return {data[key] for key in keys}
|
371
266
|
|
267
|
+
def _repr_html_(self):
|
268
|
+
from edsl.utilities.utilities import data_to_html
|
269
|
+
|
270
|
+
return data_to_html(self.to_dict())
|
271
|
+
|
272
|
+
# def html(self):
|
273
|
+
# html_string = self._repr_html_()
|
274
|
+
# import tempfile
|
275
|
+
# import webbrowser
|
276
|
+
|
277
|
+
# with tempfile.NamedTemporaryFile("w", delete=False, suffix=".html") as f:
|
278
|
+
# # print("Writing HTML to", f.name)
|
279
|
+
# f.write(html_string)
|
280
|
+
# webbrowser.open(f.name)
|
281
|
+
|
282
|
+
def __eq__(self, other):
|
283
|
+
"""Return whether two objects are equal."""
|
284
|
+
import inspect
|
285
|
+
|
286
|
+
if not isinstance(other, self.__class__):
|
287
|
+
return False
|
288
|
+
if "sort" in inspect.signature(self.to_dict).parameters:
|
289
|
+
return self.to_dict(sort=True) == other.to_dict(sort=True)
|
290
|
+
else:
|
291
|
+
return self.to_dict() == other.to_dict()
|
292
|
+
|
372
293
|
@abstractmethod
|
373
294
|
def example():
|
374
295
|
"""This method should be implemented by subclasses."""
|
375
296
|
raise NotImplementedError("This method is not implemented yet.")
|
376
297
|
|
298
|
+
@abstractmethod
|
299
|
+
def rich_print():
|
300
|
+
"""This method should be implemented by subclasses."""
|
301
|
+
raise NotImplementedError("This method is not implemented yet.")
|
302
|
+
|
377
303
|
@abstractmethod
|
378
304
|
def to_dict():
|
379
305
|
"""This method should be implemented by subclasses."""
|
@@ -382,13 +308,6 @@ class Base(
|
|
382
308
|
def to_json(self):
|
383
309
|
return json.dumps(self.to_dict())
|
384
310
|
|
385
|
-
def store(self, d: dict, key_name: Optional[str] = None):
|
386
|
-
if key_name is None:
|
387
|
-
index = len(d)
|
388
|
-
else:
|
389
|
-
index = key_name
|
390
|
-
d[index] = self
|
391
|
-
|
392
311
|
@abstractmethod
|
393
312
|
def from_dict():
|
394
313
|
"""This method should be implemented by subclasses."""
|
edsl/__init__.py
CHANGED
@@ -5,9 +5,7 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
5
5
|
ROOT_DIR = os.path.dirname(BASE_DIR)
|
6
6
|
|
7
7
|
from edsl.__version__ import __version__
|
8
|
-
|
9
|
-
# from edsl.config import Config, CONFIG
|
10
|
-
|
8
|
+
from edsl.config import Config, CONFIG
|
11
9
|
from edsl.agents.Agent import Agent
|
12
10
|
from edsl.agents.AgentList import AgentList
|
13
11
|
|
@@ -20,7 +18,6 @@ from edsl.questions import QuestionFreeText
|
|
20
18
|
from edsl.questions import QuestionFunctional
|
21
19
|
from edsl.questions import QuestionLikertFive
|
22
20
|
from edsl.questions import QuestionList
|
23
|
-
from edsl.questions import QuestionMatrix
|
24
21
|
from edsl.questions import QuestionLinearScale
|
25
22
|
from edsl.questions import QuestionNumerical
|
26
23
|
from edsl.questions import QuestionYesNo
|
@@ -28,27 +25,22 @@ from edsl.questions import QuestionBudget
|
|
28
25
|
from edsl.questions import QuestionRank
|
29
26
|
from edsl.questions import QuestionTopK
|
30
27
|
|
31
|
-
from edsl.scenarios
|
32
|
-
from edsl.scenarios
|
28
|
+
from edsl.scenarios import Scenario
|
29
|
+
from edsl.scenarios import ScenarioList
|
33
30
|
from edsl.scenarios.FileStore import FileStore
|
34
31
|
|
35
32
|
# from edsl.utilities.interface import print_dict_with_rich
|
36
33
|
from edsl.surveys.Survey import Survey
|
37
|
-
from edsl.language_models.
|
34
|
+
from edsl.language_models.registry import Model
|
38
35
|
from edsl.language_models.ModelList import ModelList
|
39
|
-
|
40
36
|
from edsl.results.Results import Results
|
41
37
|
from edsl.data.Cache import Cache
|
42
|
-
|
43
|
-
# from edsl.data.CacheEntry import CacheEntry
|
38
|
+
from edsl.data.CacheEntry import CacheEntry
|
44
39
|
from edsl.data.CacheHandler import set_session_cache, unset_session_cache
|
45
|
-
|
46
|
-
# from edsl.shared import shared_globals
|
47
|
-
|
40
|
+
from edsl.shared import shared_globals
|
48
41
|
from edsl.jobs.Jobs import Jobs
|
49
42
|
from edsl.notebooks.Notebook import Notebook
|
50
|
-
|
51
|
-
# from edsl.study.Study import Study
|
43
|
+
from edsl.study.Study import Study
|
52
44
|
|
53
45
|
# from edsl.conjure.Conjure import Conjure
|
54
46
|
from edsl.coop.coop import Coop
|
edsl/__version__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.39"
|
1
|
+
__version__ = "0.1.39.dev1"
|