edsl 0.1.54__py3-none-any.whl → 0.1.55__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.
Files changed (101) hide show
  1. edsl/__init__.py +8 -1
  2. edsl/__init__original.py +134 -0
  3. edsl/__version__.py +1 -1
  4. edsl/agents/agent.py +29 -0
  5. edsl/agents/agent_list.py +36 -1
  6. edsl/base/base_class.py +281 -151
  7. edsl/buckets/__init__.py +8 -3
  8. edsl/buckets/bucket_collection.py +9 -3
  9. edsl/buckets/model_buckets.py +4 -2
  10. edsl/buckets/token_bucket.py +2 -2
  11. edsl/buckets/token_bucket_client.py +5 -3
  12. edsl/caching/cache.py +131 -62
  13. edsl/caching/cache_entry.py +70 -58
  14. edsl/caching/sql_dict.py +17 -0
  15. edsl/cli.py +99 -0
  16. edsl/config/config_class.py +16 -0
  17. edsl/conversation/__init__.py +31 -0
  18. edsl/coop/coop.py +276 -242
  19. edsl/coop/coop_jobs_objects.py +59 -0
  20. edsl/coop/coop_objects.py +29 -0
  21. edsl/coop/coop_regular_objects.py +26 -0
  22. edsl/coop/utils.py +24 -19
  23. edsl/dataset/dataset.py +338 -101
  24. edsl/db_list/sqlite_list.py +349 -0
  25. edsl/inference_services/__init__.py +40 -5
  26. edsl/inference_services/exceptions.py +11 -0
  27. edsl/inference_services/services/anthropic_service.py +5 -2
  28. edsl/inference_services/services/aws_bedrock.py +6 -2
  29. edsl/inference_services/services/azure_ai.py +6 -2
  30. edsl/inference_services/services/google_service.py +3 -2
  31. edsl/inference_services/services/mistral_ai_service.py +6 -2
  32. edsl/inference_services/services/open_ai_service.py +6 -2
  33. edsl/inference_services/services/perplexity_service.py +6 -2
  34. edsl/inference_services/services/test_service.py +94 -5
  35. edsl/interviews/answering_function.py +167 -59
  36. edsl/interviews/interview.py +124 -72
  37. edsl/interviews/interview_task_manager.py +10 -0
  38. edsl/invigilators/invigilators.py +9 -0
  39. edsl/jobs/async_interview_runner.py +146 -104
  40. edsl/jobs/data_structures.py +6 -4
  41. edsl/jobs/decorators.py +61 -0
  42. edsl/jobs/fetch_invigilator.py +61 -18
  43. edsl/jobs/html_table_job_logger.py +14 -2
  44. edsl/jobs/jobs.py +180 -104
  45. edsl/jobs/jobs_component_constructor.py +2 -2
  46. edsl/jobs/jobs_interview_constructor.py +2 -0
  47. edsl/jobs/jobs_remote_inference_logger.py +4 -0
  48. edsl/jobs/jobs_runner_status.py +30 -25
  49. edsl/jobs/progress_bar_manager.py +79 -0
  50. edsl/jobs/remote_inference.py +35 -1
  51. edsl/key_management/key_lookup_builder.py +6 -1
  52. edsl/language_models/language_model.py +86 -6
  53. edsl/language_models/model.py +10 -3
  54. edsl/language_models/price_manager.py +45 -75
  55. edsl/language_models/registry.py +5 -0
  56. edsl/notebooks/notebook.py +77 -10
  57. edsl/questions/VALIDATION_README.md +134 -0
  58. edsl/questions/__init__.py +24 -1
  59. edsl/questions/exceptions.py +21 -0
  60. edsl/questions/question_dict.py +201 -16
  61. edsl/questions/question_multiple_choice_with_other.py +624 -0
  62. edsl/questions/question_registry.py +2 -1
  63. edsl/questions/templates/multiple_choice_with_other/__init__.py +0 -0
  64. edsl/questions/templates/multiple_choice_with_other/answering_instructions.jinja +15 -0
  65. edsl/questions/templates/multiple_choice_with_other/question_presentation.jinja +17 -0
  66. edsl/questions/validation_analysis.py +185 -0
  67. edsl/questions/validation_cli.py +131 -0
  68. edsl/questions/validation_html_report.py +404 -0
  69. edsl/questions/validation_logger.py +136 -0
  70. edsl/results/result.py +63 -16
  71. edsl/results/results.py +702 -171
  72. edsl/scenarios/construct_download_link.py +16 -3
  73. edsl/scenarios/directory_scanner.py +226 -226
  74. edsl/scenarios/file_methods.py +5 -0
  75. edsl/scenarios/file_store.py +117 -6
  76. edsl/scenarios/handlers/__init__.py +5 -1
  77. edsl/scenarios/handlers/mp4_file_store.py +104 -0
  78. edsl/scenarios/handlers/webm_file_store.py +104 -0
  79. edsl/scenarios/scenario.py +120 -101
  80. edsl/scenarios/scenario_list.py +800 -727
  81. edsl/scenarios/scenario_list_gc_test.py +146 -0
  82. edsl/scenarios/scenario_list_memory_test.py +214 -0
  83. edsl/scenarios/scenario_list_source_refactor.md +35 -0
  84. edsl/scenarios/scenario_selector.py +5 -4
  85. edsl/scenarios/scenario_source.py +1990 -0
  86. edsl/scenarios/tests/test_scenario_list_sources.py +52 -0
  87. edsl/surveys/survey.py +22 -0
  88. edsl/tasks/__init__.py +4 -2
  89. edsl/tasks/task_history.py +198 -36
  90. edsl/tests/scenarios/test_ScenarioSource.py +51 -0
  91. edsl/tests/scenarios/test_scenario_list_sources.py +51 -0
  92. edsl/utilities/__init__.py +2 -1
  93. edsl/utilities/decorators.py +121 -0
  94. edsl/utilities/memory_debugger.py +1010 -0
  95. {edsl-0.1.54.dist-info → edsl-0.1.55.dist-info}/METADATA +51 -76
  96. {edsl-0.1.54.dist-info → edsl-0.1.55.dist-info}/RECORD +99 -75
  97. edsl/jobs/jobs_runner_asyncio.py +0 -281
  98. edsl/language_models/unused/fake_openai_service.py +0 -60
  99. {edsl-0.1.54.dist-info → edsl-0.1.55.dist-info}/LICENSE +0 -0
  100. {edsl-0.1.54.dist-info → edsl-0.1.55.dist-info}/WHEEL +0 -0
  101. {edsl-0.1.54.dist-info → edsl-0.1.55.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,59 @@
1
+ import json
2
+ from typing import List
3
+
4
+ from .coop_objects import CoopObjects
5
+
6
+
7
+ class CoopJobsObjects(CoopObjects):
8
+ """ScenarioList of remote inference job objects returned by the .list() method.
9
+
10
+ This class provides specialized functionality for working with remote inference
11
+ jobs, allowing bulk fetching of jobs.
12
+ """
13
+
14
+ def fetch(self) -> List:
15
+ """Fetch each job's details using remote_inference_get and deserialize them.
16
+
17
+ Returns:
18
+ list: A list of Jobs objects
19
+
20
+ Example:
21
+ >>> jobs = coop.remote_inference_list() # Get list of remote jobs
22
+ >>> job_objects = jobs.fetch() # Returns list of Jobs objects
23
+ """
24
+ from ..coop import Coop
25
+ from ..jobs import Jobs
26
+
27
+ c = Coop()
28
+ job_details = [
29
+ c.remote_inference_get(obj["uuid"], include_json_string=True)
30
+ for obj in self
31
+ ]
32
+
33
+ # Deserialize each job from its JSON string
34
+ return [
35
+ Jobs.from_dict(json.loads(details["job_json_string"]))
36
+ for details in job_details
37
+ ]
38
+
39
+ def fetch_results(self) -> List:
40
+ """Fetch each job's results using the results_uuid.
41
+
42
+ Returns:
43
+ list: A list of Results objects
44
+
45
+ Example:
46
+ >>> jobs = coop.remote_inference_list() # Get list of remote jobs
47
+ >>> results = jobs.fetch_results() # Returns list of Results objects
48
+ """
49
+ from ..coop import Coop
50
+
51
+ c = Coop()
52
+ results = []
53
+
54
+ for obj in self:
55
+ if obj.get("results_uuid"):
56
+ result = c.get(obj["results_uuid"])
57
+ results.append(result)
58
+
59
+ return results
@@ -0,0 +1,29 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Optional, List
3
+ from ..scenarios import ScenarioList
4
+
5
+
6
+ class CoopObjects(ScenarioList, ABC):
7
+ """Base class for Coop object collections.
8
+
9
+ This abstract class extends ScenarioList to provide common functionality
10
+ for working with collections of Coop objects.
11
+ """
12
+
13
+ def __init__(
14
+ self, data: Optional[list] = None, codebook: Optional[dict[str, str]] = None
15
+ ):
16
+ super().__init__(data, codebook)
17
+
18
+ @abstractmethod
19
+ def fetch(self) -> List:
20
+ """Fetch each object in the list and return them as EDSL objects.
21
+
22
+ Returns:
23
+ list: A list of instantiated EDSL objects
24
+
25
+ Example:
26
+ >>> objects = coop.list("some_type")
27
+ >>> fetched_objects = objects.fetch() # Returns list of appropriate objects
28
+ """
29
+ pass
@@ -0,0 +1,26 @@
1
+ from typing import List
2
+
3
+ from .coop_objects import CoopObjects
4
+
5
+
6
+ class CoopRegularObjects(CoopObjects):
7
+ """ScenarioList of regular Coop objects returned by the .list() method.
8
+
9
+ This class provides specialized functionality for working with regular
10
+ Coop objects like questions, surveys, scenarios, etc.
11
+ """
12
+
13
+ def fetch(self) -> List:
14
+ """Fetch each object in the list and return them as EDSL objects.
15
+
16
+ Returns:
17
+ list: A list of EDSL objects (e.g., Survey, Question, etc.)
18
+
19
+ Example:
20
+ >>> objects = coop.list("survey")
21
+ >>> surveys = objects.fetch() # Returns list of Survey objects
22
+ """
23
+ from ..coop import Coop
24
+
25
+ c = Coop()
26
+ return [c.get(obj["uuid"]) for obj in self]
edsl/coop/utils.py CHANGED
@@ -45,6 +45,9 @@ RemoteJobStatus = Literal[
45
45
  "running",
46
46
  "completed",
47
47
  "failed",
48
+ "cancelled",
49
+ "cancelling",
50
+ "partial_failed",
48
51
  ]
49
52
 
50
53
  VisibilityType = Literal[
@@ -57,18 +60,18 @@ VisibilityType = Literal[
57
60
  class ObjectRegistry:
58
61
  """
59
62
  Registry that maps between EDSL class types and their cloud storage object types.
60
-
63
+
61
64
  This utility class maintains a bidirectional mapping between EDSL Python classes
62
65
  (like Survey, Agent, Results) and their corresponding object type identifiers
63
66
  used in the cloud storage system. It enables the proper serialization,
64
67
  deserialization, and type checking for objects stored in Expected Parrot's
65
68
  cloud services.
66
-
69
+
67
70
  The registry is used by the Coop client to:
68
71
  1. Determine the correct object type when uploading EDSL objects
69
72
  2. Instantiate the correct class when downloading objects
70
73
  3. Validate that retrieved objects match expected types
71
-
74
+
72
75
  Attributes:
73
76
  objects (list): List of mappings between object types and EDSL classes
74
77
  object_type_to_edsl_class (dict): Maps object type strings to EDSL classes
@@ -88,7 +91,7 @@ class ObjectRegistry:
88
91
  {"object_type": "scenario_list", "edsl_class": ScenarioList},
89
92
  {"object_type": "survey", "edsl_class": Survey},
90
93
  ]
91
-
94
+
92
95
  # Create mappings for efficient lookups
93
96
  object_type_to_edsl_class = {o["object_type"]: o["edsl_class"] for o in objects}
94
97
  edsl_class_to_object_type = {
@@ -99,19 +102,19 @@ class ObjectRegistry:
99
102
  def get_object_type_by_edsl_class(cls, edsl_object: EDSLObject) -> ObjectType:
100
103
  """
101
104
  Get the object type identifier for an EDSL class or instance.
102
-
105
+
103
106
  This method determines the appropriate object type string for a given EDSL class
104
107
  or instance, which is needed when storing the object in the cloud.
105
-
108
+
106
109
  Parameters:
107
110
  edsl_object (EDSLObject): An EDSL class (type) or instance
108
-
111
+
109
112
  Returns:
110
113
  ObjectType: The corresponding object type string (e.g., "survey", "agent")
111
-
114
+
112
115
  Raises:
113
116
  ValueError: If no mapping exists for the provided object
114
-
117
+
115
118
  Notes:
116
119
  - Special handling for Question classes, which all map to "question"
117
120
  - Works with both class types and instances
@@ -121,15 +124,16 @@ class ObjectRegistry:
121
124
  edsl_class_name = edsl_object.__name__
122
125
  else:
123
126
  edsl_class_name = type(edsl_object).__name__
124
-
127
+
125
128
  # Special handling for question classes
126
129
  if edsl_class_name.startswith("Question"):
127
130
  edsl_class_name = "QuestionBase"
128
-
131
+
129
132
  # Look up the object type
130
133
  object_type = cls.edsl_class_to_object_type.get(edsl_class_name)
131
134
  if object_type is None:
132
135
  from .exceptions import CoopValueError
136
+
133
137
  raise CoopValueError(f"Object type not found for {edsl_object=}")
134
138
  return object_type
135
139
 
@@ -137,22 +141,23 @@ class ObjectRegistry:
137
141
  def get_edsl_class_by_object_type(cls, object_type: ObjectType) -> EDSLObject:
138
142
  """
139
143
  Get the EDSL class for a given object type identifier.
140
-
144
+
141
145
  This method returns the appropriate EDSL class for a given object type string,
142
146
  which is needed when retrieving objects from the cloud.
143
-
147
+
144
148
  Parameters:
145
149
  object_type (ObjectType): The object type string (e.g., "survey", "agent")
146
-
150
+
147
151
  Returns:
148
152
  EDSLObject: The corresponding EDSL class
149
-
153
+
150
154
  Raises:
151
155
  ValueError: If no mapping exists for the provided object type
152
156
  """
153
157
  EDSL_class = cls.object_type_to_edsl_class.get(object_type)
154
158
  if EDSL_class is None:
155
159
  from .exceptions import CoopValueError
160
+
156
161
  raise CoopValueError(f"EDSL class not found for {object_type=}")
157
162
  return EDSL_class
158
163
 
@@ -164,18 +169,18 @@ class ObjectRegistry:
164
169
  ) -> dict:
165
170
  """
166
171
  Get a filtered registry of EDSL classes.
167
-
172
+
168
173
  This method returns a dictionary of EDSL classes, optionally excluding
169
174
  classes that are already registered elsewhere or explicitly excluded.
170
-
175
+
171
176
  Parameters:
172
177
  subclass_registry (dict, optional): Dictionary of classes to exclude
173
178
  because they are already registered elsewhere
174
179
  exclude_classes (list, optional): List of class names to explicitly exclude
175
-
180
+
176
181
  Returns:
177
182
  dict: Dictionary mapping class names to EDSL classes
178
-
183
+
179
184
  Notes:
180
185
  - This method is useful for building registries of classes that
181
186
  can be serialized and stored in the cloud