edsl 0.1.38__py3-none-any.whl → 0.1.38.dev2__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 (53) hide show
  1. edsl/Base.py +31 -60
  2. edsl/__version__.py +1 -1
  3. edsl/agents/Agent.py +9 -18
  4. edsl/agents/AgentList.py +8 -59
  5. edsl/agents/Invigilator.py +7 -18
  6. edsl/agents/InvigilatorBase.py +19 -0
  7. edsl/agents/PromptConstructor.py +4 -5
  8. edsl/config.py +0 -8
  9. edsl/coop/coop.py +7 -74
  10. edsl/data/Cache.py +2 -27
  11. edsl/data/CacheEntry.py +3 -8
  12. edsl/data/RemoteCacheSync.py +19 -0
  13. edsl/enums.py +0 -2
  14. edsl/inference_services/GoogleService.py +15 -7
  15. edsl/inference_services/registry.py +0 -2
  16. edsl/jobs/Jobs.py +548 -88
  17. edsl/jobs/interviews/Interview.py +11 -11
  18. edsl/jobs/runners/JobsRunnerAsyncio.py +35 -140
  19. edsl/jobs/runners/JobsRunnerStatus.py +2 -0
  20. edsl/jobs/tasks/TaskHistory.py +16 -15
  21. edsl/language_models/LanguageModel.py +84 -44
  22. edsl/language_models/ModelList.py +1 -47
  23. edsl/language_models/registry.py +4 -57
  24. edsl/prompts/Prompt.py +3 -8
  25. edsl/questions/QuestionBase.py +16 -20
  26. edsl/questions/QuestionExtract.py +4 -3
  27. edsl/questions/question_registry.py +6 -36
  28. edsl/results/Dataset.py +15 -146
  29. edsl/results/DatasetExportMixin.py +217 -231
  30. edsl/results/DatasetTree.py +4 -134
  31. edsl/results/Result.py +9 -18
  32. edsl/results/Results.py +51 -145
  33. edsl/scenarios/FileStore.py +13 -187
  34. edsl/scenarios/Scenario.py +4 -61
  35. edsl/scenarios/ScenarioList.py +62 -237
  36. edsl/surveys/Survey.py +2 -16
  37. edsl/surveys/SurveyFlowVisualizationMixin.py +9 -67
  38. edsl/surveys/instructions/Instruction.py +0 -12
  39. edsl/templates/error_reporting/interview_details.html +3 -3
  40. edsl/templates/error_reporting/interviews.html +9 -18
  41. edsl/utilities/utilities.py +0 -15
  42. {edsl-0.1.38.dist-info → edsl-0.1.38.dev2.dist-info}/METADATA +1 -2
  43. {edsl-0.1.38.dist-info → edsl-0.1.38.dev2.dist-info}/RECORD +45 -53
  44. edsl/inference_services/PerplexityService.py +0 -163
  45. edsl/jobs/JobsChecks.py +0 -147
  46. edsl/jobs/JobsPrompts.py +0 -268
  47. edsl/jobs/JobsRemoteInferenceHandler.py +0 -239
  48. edsl/results/CSSParameterizer.py +0 -108
  49. edsl/results/TableDisplay.py +0 -198
  50. edsl/results/table_display.css +0 -78
  51. edsl/scenarios/ScenarioJoin.py +0 -127
  52. {edsl-0.1.38.dist-info → edsl-0.1.38.dev2.dist-info}/LICENSE +0 -0
  53. {edsl-0.1.38.dist-info → edsl-0.1.38.dev2.dist-info}/WHEEL +0 -0
@@ -1,198 +0,0 @@
1
- from tabulate import tabulate
2
- from pathlib import Path
3
-
4
- from edsl.results.CSSParameterizer import CSSParameterizer
5
-
6
-
7
- class TableDisplay:
8
- max_height = 400
9
- min_height = 200
10
-
11
- @classmethod
12
- def get_css(cls):
13
- """Load CSS content from the file next to this module"""
14
- css_path = Path(__file__).parent / "table_display.css"
15
- return css_path.read_text()
16
-
17
- def __init__(self, headers, data, tablefmt=None, raw_data_set=None):
18
- self.headers = headers
19
- self.data = data
20
- self.tablefmt = tablefmt
21
- self.raw_data_set = raw_data_set
22
-
23
- if hasattr(raw_data_set, "print_parameters"):
24
- if raw_data_set.print_parameters:
25
- self.printing_parameters = raw_data_set.print_parameters
26
- else:
27
- self.printing_parameters = {}
28
- else:
29
- self.printing_parameters = {}
30
-
31
- def to_csv(self, filename: str):
32
- self.raw_data_set.to_csv(filename)
33
-
34
- def write(self, filename: str):
35
- if self.tablefmt is None:
36
- table = tabulate(self.data, headers=self.headers, tablefmt="simple")
37
- else:
38
- table = tabulate(self.data, headers=self.headers, tablefmt=self.tablefmt)
39
-
40
- with open(filename, "w") as file:
41
- print("Writing table to", filename)
42
- file.write(table)
43
-
44
- def to_pandas(self):
45
- return self.raw_data_set.to_pandas()
46
-
47
- def to_list(self):
48
- return self.raw_data_set.to_list()
49
-
50
- def __repr__(self):
51
- from tabulate import tabulate
52
-
53
- if self.tablefmt is None:
54
- return tabulate(self.data, headers=self.headers, tablefmt="simple")
55
- else:
56
- return tabulate(self.data, headers=self.headers, tablefmt=self.tablefmt)
57
-
58
- def long(self):
59
- new_header = ["row", "key", "value"]
60
- new_data = []
61
- for index, row in enumerate(self.data):
62
- new_data.extend([[index, k, v] for k, v in zip(self.headers, row)])
63
- return TableDisplay(new_header, new_data)
64
-
65
- def _repr_html_(self):
66
- if self.tablefmt is not None:
67
- return (
68
- "<pre>"
69
- + tabulate(self.data, headers=self.headers, tablefmt=self.tablefmt)
70
- + "</pre>"
71
- )
72
-
73
- num_rows = len(self.data)
74
- height = min(
75
- num_rows * 30 + 50, self.max_height
76
- ) # Added extra space for header
77
-
78
- if height < self.min_height:
79
- height = self.min_height
80
-
81
- html_template = """
82
- <style>
83
- {css}
84
- </style>
85
- <div class="table-container">
86
- <div class="scroll-table-wrapper">
87
- {table}
88
- </div>
89
- </div>
90
- """
91
-
92
- html_content = tabulate(self.data, headers=self.headers, tablefmt="html")
93
- html_content = html_content.replace("<table>", '<table class="scroll-table">')
94
-
95
- height_string = f"{height}px"
96
- parameters = {"containerHeight": height_string, "headerColor": "blue"}
97
- parameters.update(self.printing_parameters)
98
- rendered_css = CSSParameterizer(self.get_css()).apply_parameters(parameters)
99
-
100
- return html_template.format(table=html_content, css=rendered_css)
101
-
102
- @classmethod
103
- def example(
104
- cls,
105
- headers=None,
106
- data=None,
107
- filename: str = "table_example.html",
108
- auto_open: bool = True,
109
- ):
110
- """
111
- Creates a standalone HTML file with an example table in an iframe and optionally opens it in a new tab.
112
-
113
- Args:
114
- cls: The class itself
115
- headers (list): List of column headers. If None, uses example headers
116
- data (list): List of data rows. If None, uses example data
117
- filename (str): The name of the HTML file to create. Defaults to "table_example.html"
118
- auto_open (bool): Whether to automatically open the file in the default web browser. Defaults to True
119
-
120
- Returns:
121
- str: The path to the created HTML file
122
- """
123
- import os
124
- import webbrowser
125
-
126
- # Use example data if none provided
127
- if headers is None:
128
- headers = ["Name", "Age", "City", "Occupation"]
129
- if data is None:
130
- data = [
131
- [
132
- "John Doe",
133
- 30,
134
- "New York",
135
- """cls: The class itself
136
- headers (list): List of column headers. If None, uses example headers
137
- data (list): List of data rows. If None, uses example data
138
- filename (str): The name of the HTML file to create. Defaults to "table_example.html"
139
- auto_open (bool): Whether to automatically open the file in the default web browser. Defaults to True
140
- """,
141
- ],
142
- ["Jane Smith", 28, "San Francisco", "Designer"],
143
- ["Bob Johnson", 35, "Chicago", "Manager"],
144
- ["Alice Brown", 25, "Boston", "Developer"],
145
- ["Charlie Wilson", 40, "Seattle", "Architect"],
146
- ]
147
-
148
- # Create instance with the data
149
- instance = cls(headers=headers, data=data)
150
-
151
- # Get the table HTML content
152
- table_html = instance._repr_html_()
153
-
154
- # Calculate the appropriate iframe height
155
- num_rows = len(data)
156
- iframe_height = min(num_rows * 140 + 50, cls.max_height)
157
- print(f"Table height: {iframe_height}px")
158
-
159
- # Create the full HTML document
160
- html_content = f"""
161
- <!DOCTYPE html>
162
- <html>
163
- <head>
164
- <title>Table Display Example</title>
165
- <style>
166
- body {{
167
- margin: 0;
168
- padding: 20px;
169
- font-family: Arial, sans-serif;
170
- }}
171
- iframe {{
172
- width: 100%;
173
- height: {iframe_height}px;
174
- border: none;
175
- overflow: hidden;
176
- }}
177
- </style>
178
- </head>
179
- <body>
180
- <iframe srcdoc='{table_html}'></iframe>
181
- </body>
182
- </html>
183
- """
184
-
185
- # Write the HTML file
186
- abs_path = os.path.abspath(filename)
187
- with open(filename, "w", encoding="utf-8") as f:
188
- f.write(html_content)
189
-
190
- # Open in browser if requested
191
- if auto_open:
192
- webbrowser.open("file://" + abs_path, new=2)
193
-
194
- return abs_path
195
-
196
-
197
- if __name__ == "__main__":
198
- TableDisplay.example()
@@ -1,78 +0,0 @@
1
- .table-container {
2
- height: var(--containerHeight) !important;
3
- width: 100%;
4
- overflow: auto; /* This enables both horizontal and vertical scrolling */
5
- border: 1px solid #d4d4d4;
6
- background: transparent;
7
- position: relative; /* Create stacking context for sticky header */
8
- }
9
-
10
- .scroll-table {
11
- /* Remove width: 100% to prevent table from being constrained */
12
- /* min-width: 100% ensures table takes at least full container width */
13
- min-width: 100%;
14
- border-collapse: separate;
15
- border-spacing: 4px;
16
- background: transparent;
17
- table-layout: auto; /* Allow table to size based on content */
18
- }
19
-
20
- .scroll-table th {
21
- background: transparent; /* Semi-transparent background to ensure text readability */
22
- position: sticky;
23
- top: 0;
24
- z-index: 1;
25
- text-align: left !important;
26
- padding: 8px;
27
- font-weight: bold;
28
- white-space: nowrap; /* Prevent header text from wrapping */
29
- min-width: 100px; /* Ensure minimum column width */
30
- backdrop-filter: blur(8px); /* Optional: adds extra clarity */
31
- color: var(--headerColor);
32
- }
33
-
34
- .scroll-table td {
35
- padding: 8px;
36
- text-align: left !important;
37
- white-space: pre-wrap;
38
- word-wrap: break-word;
39
- vertical-align: top;
40
- color: inherit;
41
- border-bottom: none;
42
- background: transparent;
43
- min-width: 100px; /* Match header minimum width */
44
- }
45
-
46
- .scroll-table tbody tr:hover {
47
- background: transparent;
48
- }
49
-
50
- /* Additional rule to ensure header background is truly transparent */
51
- .scroll-table thead tr {
52
- background: transparent !important;
53
- }
54
-
55
- /* Add shadow to indicate scrollable content */
56
- .table-container::after {
57
- content: '';
58
- position: absolute;
59
- top: 0;
60
- right: 0;
61
- bottom: 0;
62
- width: 5px;
63
- background: linear-gradient(to right, transparent, rgba(242, 6, 6, 0.1));
64
- pointer-events: none;
65
- opacity: 0;
66
- transition: opacity 0.3s;
67
- }
68
-
69
- .table-container:hover::after {
70
- opacity: 1;
71
- }
72
-
73
- /* Handle Jupyter notebook specific styling */
74
- .jp-OutputArea-output .table-container {
75
- max-width: 100%;
76
- margin: 0;
77
- overflow-x: auto;
78
- }
@@ -1,127 +0,0 @@
1
- from __future__ import annotations
2
- from typing import Union, TYPE_CHECKING
3
-
4
- # if TYPE_CHECKING:
5
- from edsl.scenarios.ScenarioList import ScenarioList
6
- from edsl.scenarios.Scenario import Scenario
7
-
8
-
9
- class ScenarioJoin:
10
- """Handles join operations between two ScenarioLists.
11
-
12
- This class encapsulates all join-related logic, making it easier to maintain
13
- and extend with other join types (inner, right, full) in the future.
14
- """
15
-
16
- def __init__(self, left: "ScenarioList", right: "ScenarioList"):
17
- """Initialize join operation with two ScenarioLists.
18
-
19
- Args:
20
- left: The left ScenarioList
21
- right: The right ScenarioList
22
- """
23
- self.left = left
24
- self.right = right
25
-
26
- def left_join(self, by: Union[str, list[str]]) -> ScenarioList:
27
- """Perform a left join between the two ScenarioLists.
28
-
29
- Args:
30
- by: String or list of strings representing the key(s) to join on. Cannot be empty.
31
-
32
- Returns:
33
- A new ScenarioList containing the joined scenarios
34
-
35
- Raises:
36
- ValueError: If by is empty or if any join keys don't exist in both ScenarioLists
37
- """
38
- self._validate_join_keys(by)
39
- by_keys = [by] if isinstance(by, str) else by
40
-
41
- other_dict = self._create_lookup_dict(self.right, by_keys)
42
- all_keys = self._get_all_keys()
43
-
44
- return ScenarioList(
45
- self._create_joined_scenarios(by_keys, other_dict, all_keys)
46
- )
47
-
48
- def _validate_join_keys(self, by: Union[str, list[str]]) -> None:
49
- """Validate join keys exist in both ScenarioLists."""
50
- if not by:
51
- raise ValueError(
52
- "Join keys cannot be empty. Please specify at least one key to join on."
53
- )
54
-
55
- by_keys = [by] if isinstance(by, str) else by
56
- left_keys = set(next(iter(self.left)).keys()) if self.left else set()
57
- right_keys = set(next(iter(self.right)).keys()) if self.right else set()
58
-
59
- missing_left = set(by_keys) - left_keys
60
- missing_right = set(by_keys) - right_keys
61
- if missing_left or missing_right:
62
- missing = missing_left | missing_right
63
- raise ValueError(f"Join key(s) {missing} not found in both ScenarioLists")
64
-
65
- @staticmethod
66
- def _get_key_tuple(scenario: Scenario, keys: list[str]) -> tuple:
67
- """Create a tuple of values for the join keys."""
68
- return tuple(scenario[k] for k in keys)
69
-
70
- def _create_lookup_dict(self, scenarios: ScenarioList, by_keys: list[str]) -> dict:
71
- """Create a lookup dictionary for the right scenarios."""
72
- return {
73
- self._get_key_tuple(scenario, by_keys): scenario for scenario in scenarios
74
- }
75
-
76
- def _get_all_keys(self) -> set:
77
- """Get all unique keys from both ScenarioLists."""
78
- all_keys = set()
79
- for scenario in self.left:
80
- all_keys.update(scenario.keys())
81
- for scenario in self.right:
82
- all_keys.update(scenario.keys())
83
- return all_keys
84
-
85
- def _create_joined_scenarios(
86
- self, by_keys: list[str], other_dict: dict, all_keys: set
87
- ) -> list[Scenario]:
88
- """Create the joined scenarios."""
89
- new_scenarios = []
90
-
91
- for scenario in self.left:
92
- new_scenario = {key: None for key in all_keys}
93
- new_scenario.update(scenario)
94
-
95
- key_tuple = self._get_key_tuple(scenario, by_keys)
96
- if matching_scenario := other_dict.get(key_tuple):
97
- self._handle_matching_scenario(
98
- new_scenario, scenario, matching_scenario, by_keys
99
- )
100
-
101
- new_scenarios.append(Scenario(new_scenario))
102
-
103
- return new_scenarios
104
-
105
- def _handle_matching_scenario(
106
- self,
107
- new_scenario: dict,
108
- left_scenario: Scenario,
109
- right_scenario: Scenario,
110
- by_keys: list[str],
111
- ) -> None:
112
- """Handle merging of matching scenarios and conflict warnings."""
113
- overlapping_keys = set(left_scenario.keys()) & set(right_scenario.keys())
114
-
115
- for key in overlapping_keys:
116
- if key not in by_keys and left_scenario[key] != right_scenario[key]:
117
- join_conditions = [f"{k}='{left_scenario[k]}'" for k in by_keys]
118
- print(
119
- f"Warning: Conflicting values for key '{key}' where "
120
- f"{' AND '.join(join_conditions)}. "
121
- f"Keeping left value: {left_scenario[key]} "
122
- f"(discarding: {right_scenario[key]})"
123
- )
124
-
125
- # Only update with non-overlapping keys from matching scenario
126
- new_keys = set(right_scenario.keys()) - set(left_scenario.keys())
127
- new_scenario.update({k: right_scenario[k] for k in new_keys})