edsl 0.1.28__py3-none-any.whl → 0.1.29__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 (76) hide show
  1. edsl/Base.py +18 -18
  2. edsl/__init__.py +24 -24
  3. edsl/__version__.py +1 -1
  4. edsl/agents/Agent.py +77 -41
  5. edsl/agents/AgentList.py +35 -6
  6. edsl/agents/Invigilator.py +19 -1
  7. edsl/agents/InvigilatorBase.py +15 -10
  8. edsl/agents/PromptConstructionMixin.py +342 -100
  9. edsl/agents/descriptors.py +2 -1
  10. edsl/base/Base.py +289 -0
  11. edsl/config.py +2 -1
  12. edsl/conjure/InputData.py +39 -8
  13. edsl/coop/coop.py +188 -151
  14. edsl/coop/utils.py +43 -75
  15. edsl/data/Cache.py +19 -5
  16. edsl/data/SQLiteDict.py +11 -3
  17. edsl/jobs/Answers.py +15 -1
  18. edsl/jobs/Jobs.py +92 -47
  19. edsl/jobs/buckets/ModelBuckets.py +4 -2
  20. edsl/jobs/buckets/TokenBucket.py +1 -2
  21. edsl/jobs/interviews/Interview.py +3 -9
  22. edsl/jobs/interviews/InterviewStatusMixin.py +3 -3
  23. edsl/jobs/interviews/InterviewTaskBuildingMixin.py +15 -10
  24. edsl/jobs/runners/JobsRunnerAsyncio.py +21 -25
  25. edsl/jobs/tasks/TaskHistory.py +4 -3
  26. edsl/language_models/LanguageModel.py +5 -11
  27. edsl/language_models/ModelList.py +3 -3
  28. edsl/language_models/repair.py +8 -7
  29. edsl/notebooks/Notebook.py +40 -3
  30. edsl/prompts/Prompt.py +31 -19
  31. edsl/questions/QuestionBase.py +38 -13
  32. edsl/questions/QuestionBudget.py +5 -6
  33. edsl/questions/QuestionCheckBox.py +7 -3
  34. edsl/questions/QuestionExtract.py +5 -3
  35. edsl/questions/QuestionFreeText.py +3 -3
  36. edsl/questions/QuestionFunctional.py +0 -3
  37. edsl/questions/QuestionList.py +3 -4
  38. edsl/questions/QuestionMultipleChoice.py +16 -8
  39. edsl/questions/QuestionNumerical.py +4 -3
  40. edsl/questions/QuestionRank.py +5 -3
  41. edsl/questions/__init__.py +4 -3
  42. edsl/questions/descriptors.py +4 -2
  43. edsl/questions/question_registry.py +20 -31
  44. edsl/questions/settings.py +1 -1
  45. edsl/results/Dataset.py +31 -0
  46. edsl/results/DatasetExportMixin.py +493 -0
  47. edsl/results/Result.py +22 -74
  48. edsl/results/Results.py +105 -67
  49. edsl/results/ResultsDBMixin.py +7 -3
  50. edsl/results/ResultsExportMixin.py +22 -537
  51. edsl/results/ResultsGGMixin.py +3 -3
  52. edsl/results/ResultsToolsMixin.py +5 -5
  53. edsl/scenarios/FileStore.py +140 -0
  54. edsl/scenarios/Scenario.py +5 -6
  55. edsl/scenarios/ScenarioList.py +44 -15
  56. edsl/scenarios/ScenarioListExportMixin.py +32 -0
  57. edsl/scenarios/ScenarioListPdfMixin.py +2 -1
  58. edsl/scenarios/__init__.py +1 -0
  59. edsl/study/ObjectEntry.py +89 -13
  60. edsl/study/ProofOfWork.py +5 -2
  61. edsl/study/SnapShot.py +4 -8
  62. edsl/study/Study.py +21 -14
  63. edsl/study/__init__.py +2 -0
  64. edsl/surveys/MemoryPlan.py +11 -4
  65. edsl/surveys/Survey.py +46 -7
  66. edsl/surveys/SurveyExportMixin.py +4 -2
  67. edsl/surveys/SurveyFlowVisualizationMixin.py +6 -4
  68. edsl/tools/plotting.py +4 -2
  69. edsl/utilities/__init__.py +21 -21
  70. edsl/utilities/interface.py +66 -45
  71. edsl/utilities/utilities.py +11 -13
  72. {edsl-0.1.28.dist-info → edsl-0.1.29.dist-info}/METADATA +11 -10
  73. {edsl-0.1.28.dist-info → edsl-0.1.29.dist-info}/RECORD +75 -72
  74. edsl-0.1.28.dist-info/entry_points.txt +0 -3
  75. {edsl-0.1.28.dist-info → edsl-0.1.29.dist-info}/LICENSE +0 -0
  76. {edsl-0.1.28.dist-info → edsl-0.1.29.dist-info}/WHEEL +0 -0
@@ -3,9 +3,9 @@
3
3
  from collections import UserDict, defaultdict
4
4
  from typing import Optional
5
5
 
6
- from edsl.surveys.Memory import Memory
7
- from edsl.prompts.Prompt import Prompt
8
- from edsl.surveys.DAG import DAG
6
+ # from edsl.surveys.Memory import Memory
7
+ # from edsl.prompts.Prompt import Prompt
8
+ # from edsl.surveys.DAG import DAG
9
9
 
10
10
 
11
11
  class MemoryPlan(UserDict):
@@ -61,6 +61,8 @@ class MemoryPlan(UserDict):
61
61
  :param answers: A dictionary of question names to answers.
62
62
 
63
63
  """
64
+ from edsl.prompts.Prompt import Prompt
65
+
64
66
  self._check_valid_question_name(focal_question)
65
67
 
66
68
  if focal_question not in self:
@@ -121,6 +123,7 @@ class MemoryPlan(UserDict):
121
123
  self._check_valid_question_name(focal_question)
122
124
  self._check_valid_question_name(prior_question)
123
125
  self._check_order(focal_question, prior_question)
126
+ from edsl.surveys.Memory import Memory
124
127
 
125
128
  if focal_question not in self:
126
129
  memory = Memory()
@@ -160,6 +163,8 @@ class MemoryPlan(UserDict):
160
163
  @classmethod
161
164
  def from_dict(cls, data) -> "MemoryPlan":
162
165
  """Deserialize a memory plan from a dictionary."""
166
+ from edsl.surveys.Memory import Memory
167
+
163
168
  newdata = {}
164
169
  for question_name, memory in data["data"].items():
165
170
  newdata[question_name] = Memory.from_dict(memory)
@@ -182,13 +187,15 @@ class MemoryPlan(UserDict):
182
187
  return new_d
183
188
 
184
189
  @property
185
- def dag(self) -> DAG:
190
+ def dag(self) -> "DAG":
186
191
  """Return a directed acyclic graph of the memory plan.
187
192
 
188
193
  >>> mp = MemoryPlan.example()
189
194
  >>> mp.dag
190
195
  {1: {0}}
191
196
  """
197
+ from edsl.surveys.DAG import DAG
198
+
192
199
  d = defaultdict(set)
193
200
  for focal_question, memory in self.items():
194
201
  for prior_question in memory:
edsl/surveys/Survey.py CHANGED
@@ -5,9 +5,6 @@ import re
5
5
 
6
6
  from typing import Any, Generator, Optional, Union, List, Literal, Callable
7
7
 
8
- from rich import print
9
- from rich.table import Table
10
-
11
8
  from edsl.exceptions import SurveyCreationError, SurveyHasNoRulesError
12
9
  from edsl.questions.QuestionBase import QuestionBase
13
10
  from edsl.surveys.base import RulePriority, EndOfSurvey
@@ -18,8 +15,8 @@ from edsl.Base import Base
18
15
  from edsl.surveys.SurveyExportMixin import SurveyExportMixin
19
16
  from edsl.surveys.descriptors import QuestionsDescriptor
20
17
  from edsl.surveys.MemoryPlan import MemoryPlan
18
+
21
19
  from edsl.surveys.DAG import DAG
22
- from edsl.utilities import is_notebook
23
20
  from edsl.utilities.decorators import add_edsl_version, remove_edsl_version
24
21
  from edsl.surveys.SurveyFlowVisualizationMixin import SurveyFlowVisualizationMixin
25
22
 
@@ -96,6 +93,10 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
96
93
  index = self.question_name_to_index[question_name]
97
94
  return self._questions[index]
98
95
 
96
+ def question_names_to_questions(self) -> dict:
97
+ """Return a dictionary mapping question names to question attributes."""
98
+ return {q.question_name: q for q in self.questions}
99
+
99
100
  def get_question(self, question_name: str) -> QuestionBase:
100
101
  """Return the question object given the question name."""
101
102
  # import warnings
@@ -112,6 +113,10 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
112
113
  def parameters(self):
113
114
  return set.union(*[q.parameters for q in self.questions])
114
115
 
116
+ @property
117
+ def parameters_by_question(self):
118
+ return {q.question_name: q.parameters for q in self.questions}
119
+
115
120
  @property
116
121
  def question_names(self) -> list[str]:
117
122
  """Return a list of question names in the survey.
@@ -555,6 +560,12 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
555
560
  job = Jobs(survey=self)
556
561
  return job.by(*args)
557
562
 
563
+ def to_jobs(self):
564
+ """Convert the survey to a Jobs object."""
565
+ from edsl.jobs.Jobs import Jobs
566
+
567
+ return Jobs(survey=self)
568
+
558
569
  def run(self, *args, **kwargs) -> "Results":
559
570
  """Turn the survey into a Job and runs it.
560
571
 
@@ -732,6 +743,22 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
732
743
  except IndexError:
733
744
  raise
734
745
 
746
+ @property
747
+ def piping_dag(self) -> DAG:
748
+ d = {}
749
+ for question_name, depenencies in self.parameters_by_question.items():
750
+ if depenencies:
751
+ question_index = self.question_name_to_index[question_name]
752
+ for dependency in depenencies:
753
+ if dependency not in self.question_name_to_index:
754
+ pass
755
+ else:
756
+ dependency_index = self.question_name_to_index[dependency]
757
+ if question_index not in d:
758
+ d[question_index] = set()
759
+ d[question_index].add(dependency_index)
760
+ return d
761
+
735
762
  def dag(self, textify: bool = False) -> DAG:
736
763
  """Return the DAG of the survey, which reflects both skip-logic and memory.
737
764
 
@@ -745,10 +772,12 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
745
772
  """
746
773
  memory_dag = self.memory_plan.dag
747
774
  rule_dag = self.rule_collection.dag
775
+ piping_dag = self.piping_dag
748
776
  if textify:
749
777
  memory_dag = DAG(self.textify(memory_dag))
750
778
  rule_dag = DAG(self.textify(rule_dag))
751
- return memory_dag + rule_dag
779
+ piping_dag = DAG(self.textify(piping_dag))
780
+ return memory_dag + rule_dag + piping_dag
752
781
 
753
782
  ###################
754
783
  # DUNDER METHODS
@@ -931,6 +960,8 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
931
960
  │ └───────────────┴─────────────────┴───────────────┴──────────────────────────────────────────────┘ │
932
961
  └────────────────────────────────────────────────────────────────────────────────────────────────────┘
933
962
  """
963
+ from rich.table import Table
964
+
934
965
  table = Table(show_header=True, header_style="bold magenta")
935
966
  table.add_column("Questions", style="dim")
936
967
 
@@ -994,7 +1025,7 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
994
1025
  return res
995
1026
 
996
1027
  @classmethod
997
- def example(cls) -> Survey:
1028
+ def example(cls, params=False) -> Survey:
998
1029
  """Return an example survey.
999
1030
 
1000
1031
  >>> s = Survey.example()
@@ -1018,12 +1049,20 @@ class Survey(SurveyExportMixin, SurveyFlowVisualizationMixin, Base):
1018
1049
  question_options=["**lack*** of killer bees in cafeteria", "other"],
1019
1050
  question_name="q2",
1020
1051
  )
1052
+ if params:
1053
+ q3 = QuestionMultipleChoice(
1054
+ question_text="To the question '{{ q0.question_text}}', you said '{{ q0.answer }}'. Do you still feel this way?",
1055
+ question_options=["yes", "no"],
1056
+ question_name="q3",
1057
+ )
1058
+ s = cls(questions=[q0, q1, q2, q3])
1059
+ return s
1021
1060
  s = cls(questions=[q0, q1, q2])
1022
1061
  s = s.add_rule(q0, "q0 == 'yes'", q2)
1023
1062
  return s
1024
1063
 
1025
1064
  def get_job(self, model=None, agent=None, **kwargs):
1026
- if not model:
1065
+ if model is None:
1027
1066
  from edsl import Model
1028
1067
 
1029
1068
  model = Model()
@@ -1,8 +1,6 @@
1
1
  """A mixin class for exporting surveys to different formats."""
2
2
 
3
- from docx import Document
4
3
  from typing import Union, Optional
5
- import black
6
4
 
7
5
 
8
6
  class SurveyExportMixin:
@@ -29,6 +27,8 @@ class SurveyExportMixin:
29
27
 
30
28
  def docx(self, filename=None) -> Union["Document", None]:
31
29
  """Generate a docx document for the survey."""
30
+ from docx import Document
31
+
32
32
  doc = Document()
33
33
  doc.add_heading("EDSL Survey")
34
34
  doc.add_paragraph(f"\n")
@@ -83,6 +83,8 @@ class SurveyExportMixin:
83
83
  survey = Survey(questions=[q0, q1, q2])
84
84
  ...
85
85
  """
86
+ import black
87
+
86
88
  header_lines = ["from edsl.surveys.Survey import Survey"]
87
89
  header_lines.append("from edsl import Question")
88
90
  lines = ["\n".join(header_lines)]
@@ -1,10 +1,7 @@
1
1
  """A mixin for visualizing the flow of a survey."""
2
2
 
3
- import pydot
4
- import tempfile
5
- from IPython.display import Image
6
- from edsl.utilities import is_notebook
7
3
  from edsl.surveys.base import RulePriority, EndOfSurvey
4
+ import tempfile
8
5
 
9
6
 
10
7
  class SurveyFlowVisualizationMixin:
@@ -13,6 +10,8 @@ class SurveyFlowVisualizationMixin:
13
10
  def show_flow(self, filename: str = None):
14
11
  """Create an image showing the flow of users through the survey."""
15
12
  # Create a graph object
13
+ import pydot
14
+
16
15
  graph = pydot.Dot(graph_type="digraph")
17
16
 
18
17
  # Add nodes for each question
@@ -101,8 +100,11 @@ class SurveyFlowVisualizationMixin:
101
100
  on Ubuntu.
102
101
  """
103
102
  )
103
+ from edsl.utilities.utilities import is_notebook
104
104
 
105
105
  if is_notebook():
106
+ from IPython.display import Image
107
+
106
108
  display(Image(tmp_file.name))
107
109
  else:
108
110
  import os
edsl/tools/plotting.py CHANGED
@@ -93,8 +93,10 @@ def theme_plot(results, field, context, themes=None, progress_bar=False):
93
93
  SELECT json_each.value AS theme
94
94
  FROM self,
95
95
  json_each({ field }_themes)
96
- ) GROUP BY theme
97
- ORDER BY mentions DESC
96
+ )
97
+ GROUP BY theme
98
+ HAVING theme <> 'Other'
99
+ ORDER BY mentions DESC
98
100
  """
99
101
  themes = results.sql(themes_query, to_list=True)
100
102
 
@@ -1,22 +1,22 @@
1
- from edsl.utilities.interface import (
2
- print_dict_as_html_table,
3
- print_dict_with_rich,
4
- print_list_of_dicts_as_html_table,
5
- print_table_with_rich,
6
- print_public_methods_with_doc,
7
- print_list_of_dicts_as_markdown_table,
8
- )
1
+ # from edsl.utilities.interface import (
2
+ # print_dict_as_html_table,
3
+ # print_dict_with_rich,
4
+ # print_list_of_dicts_as_html_table,
5
+ # print_table_with_rich,
6
+ # print_public_methods_with_doc,
7
+ # print_list_of_dicts_as_markdown_table,
8
+ # )
9
9
 
10
- from edsl.utilities.utilities import (
11
- create_valid_var_name,
12
- dict_to_html,
13
- hash_value,
14
- HTMLSnippet,
15
- is_notebook,
16
- is_gzipped,
17
- is_valid_variable_name,
18
- random_string,
19
- repair_json,
20
- shorten_string,
21
- time_all_functions,
22
- )
10
+ # from edsl.utilities.utilities import (
11
+ # create_valid_var_name,
12
+ # dict_to_html,
13
+ # hash_value,
14
+ # HTMLSnippet,
15
+ # is_notebook,
16
+ # is_gzipped,
17
+ # is_valid_variable_name,
18
+ # random_string,
19
+ # repair_json,
20
+ # shorten_string,
21
+ # time_all_functions,
22
+ # )
@@ -1,12 +1,45 @@
1
1
  """A module for displaying data in various formats."""
2
2
 
3
3
  from html import escape
4
- from IPython.display import HTML
5
- from IPython.display import display as ipython_diplay
6
4
 
7
- # from PIL import Image, ImageDraw, ImageFont
8
- from rich.console import Console
9
- from rich.table import Table
5
+
6
+ def create_image(console, image_filename):
7
+ """Create an image from the console output."""
8
+ font_size = 15
9
+ from PIL import Image, ImageDraw, ImageFont
10
+
11
+ text = console.export_text() # Get the console output as text.
12
+
13
+ # Create an image from the text
14
+ font_size = 15
15
+ font = ImageFont.load_default() # Use the default font to avoid file path issues.
16
+ # text_width, text_height = ImageDraw.Draw(
17
+ # Image.new("RGB", (100, 100))
18
+ # ).multiline_textsize(text, font=font)
19
+ text_width, text_height = get_multiline_textsize(text, font)
20
+ image = Image.new(
21
+ "RGB", (text_width + 20, text_height + 20), color=(255, 255, 255)
22
+ ) # Add some padding
23
+ d = ImageDraw.Draw(image)
24
+
25
+ # Draw text to image
26
+ d.multiline_text((10, 10), text, font=font, fill=(0, 0, 0))
27
+ # Save the image
28
+ image.save(image_filename)
29
+
30
+
31
+ def display_table(console, table, filename):
32
+ # from rich.console import Console
33
+ # from rich.table import Table
34
+ """Display the table using the rich library and save it to a file if a filename is provided."""
35
+ if filename is not None:
36
+ with open(filename, "w") as f:
37
+ with console.capture() as capture:
38
+ console.print(table)
39
+ f.write(capture.get())
40
+ create_image(console, filename + ".png")
41
+ else:
42
+ console.print(table)
10
43
 
11
44
 
12
45
  def gen_html_sandwich(html_inner, interactive=False):
@@ -133,43 +166,10 @@ def get_multiline_textsize(text, font):
133
166
  return max_width, total_height
134
167
 
135
168
 
136
- # def create_image(console, image_filename):
137
- # """Create an image from the console output."""
138
- # font_size = 15
139
-
140
- # text = console.export_text() # Get the console output as text.
141
-
142
- # # Create an image from the text
143
- # font_size = 15
144
- # font = ImageFont.load_default() # Use the default font to avoid file path issues.
145
- # # text_width, text_height = ImageDraw.Draw(
146
- # # Image.new("RGB", (100, 100))
147
- # # ).multiline_textsize(text, font=font)
148
- # text_width, text_height = get_multiline_textsize(text, font)
149
- # image = Image.new(
150
- # "RGB", (text_width + 20, text_height + 20), color=(255, 255, 255)
151
- # ) # Add some padding
152
- # d = ImageDraw.Draw(image)
153
-
154
- # # Draw text to image
155
- # d.multiline_text((10, 10), text, font=font, fill=(0, 0, 0))
156
- # # Save the image
157
- # image.save(image_filename)
158
-
159
-
160
- def display(console, table, filename):
161
- """Display the table using the rich library and save it to a file if a filename is provided."""
162
- if filename is not None:
163
- with open(filename, "w") as f:
164
- with console.capture() as capture:
165
- console.print(table)
166
- f.write(capture.get())
167
- create_image(console, filename + ".png")
168
- else:
169
- console.print(table)
170
-
171
-
172
169
  def print_results_long(results, max_rows=None):
170
+ from rich.console import Console
171
+ from rich.table import Table
172
+
173
173
  console = Console(record=True)
174
174
  table = Table(show_header=True, header_style="bold magenta")
175
175
  table.add_column("Result index", style="dim")
@@ -199,6 +199,9 @@ def print_dict_with_rich(d, key_name="Key", value_name="Value", filename=None):
199
199
  │ c │ 3 │
200
200
  └─────┴───────┘
201
201
  """
202
+ from rich.console import Console
203
+ from rich.table import Table
204
+
202
205
  console = Console(record=True)
203
206
  table = Table(show_header=True, header_style="bold magenta")
204
207
  table.add_column(key_name, style="dim")
@@ -206,7 +209,7 @@ def print_dict_with_rich(d, key_name="Key", value_name="Value", filename=None):
206
209
  for key, value in d.items():
207
210
  table.add_row(key, str(value))
208
211
  console.print(table)
209
- # display(console, table, filename)
212
+ # display_table(console, table, filename)
210
213
 
211
214
 
212
215
  def print_dict_as_html_table(
@@ -251,6 +254,9 @@ def print_dict_as_html_table(
251
254
 
252
255
 
253
256
  def print_scenario_list(data):
257
+ from rich.console import Console
258
+ from rich.table import Table
259
+
254
260
  new_data = []
255
261
  for obs in data:
256
262
  try:
@@ -300,6 +306,9 @@ def print_dataset_with_rich(data, filename=None, split_at_dot=True):
300
306
  │ 3 │ 6 │
301
307
  └───┴───┘
302
308
  """
309
+ from rich.console import Console
310
+ from rich.table import Table
311
+
303
312
  console = Console(record=True)
304
313
 
305
314
  # Create a table object
@@ -321,7 +330,7 @@ def print_dataset_with_rich(data, filename=None, split_at_dot=True):
321
330
  table.add_row(*row)
322
331
 
323
332
  console.print(table)
324
- # display(console, table, filename)
333
+ # display_table(console, table, filename)
325
334
 
326
335
 
327
336
  def create_latex_table_from_data(data, filename=None, split_at_dot=True):
@@ -495,6 +504,9 @@ def print_list_of_dicts_as_markdown_table(data, filename=None):
495
504
 
496
505
  def print_public_methods_with_doc(obj):
497
506
  """Print the public methods of an object along with their docstrings."""
507
+ from rich.console import Console
508
+ from rich.table import Table
509
+
498
510
  console = Console()
499
511
  public_methods_with_docstrings = [
500
512
  (method, getattr(obj, method).__doc__)
@@ -525,6 +537,10 @@ def print_tally_with_rich(data, filename=None):
525
537
  └───────┴───────┘
526
538
  """
527
539
  # Initialize a console object
540
+ from rich.console import Console
541
+ from rich.table import Table
542
+ from IPython.display import display
543
+
528
544
  console = Console(record=True)
529
545
 
530
546
  # Create a new table
@@ -538,7 +554,9 @@ def print_tally_with_rich(data, filename=None):
538
554
  for key, value in data.items():
539
555
  table.add_row(key, str(value))
540
556
 
541
- display(console, table, filename)
557
+ from IPython.display import display
558
+
559
+ display_table(console, table, filename)
542
560
 
543
561
 
544
562
  def print_table_with_rich(data, filename=None):
@@ -561,6 +579,9 @@ def print_table_with_rich(data, filename=None):
561
579
  │ 2 │ 9 │ 8 │
562
580
  └───┴───┴───┘
563
581
  """
582
+ from rich.console import Console
583
+ from rich.table import Table
584
+
564
585
  # Initialize a console object - expects a list of dictionaries
565
586
  console = Console(record=True)
566
587
 
@@ -580,7 +601,7 @@ def print_table_with_rich(data, filename=None):
580
601
  for row in data:
581
602
  table.add_row(*[str(value) for value in row.values()])
582
603
 
583
- display(console, table, filename)
604
+ display_table(console, table, filename)
584
605
 
585
606
 
586
607
  if __name__ == "__main__":
@@ -1,5 +1,9 @@
1
1
  """Utility functions for working with strings, dictionaries, and files."""
2
2
 
3
+ from functools import wraps
4
+ import types
5
+ import time
6
+
3
7
  import hashlib
4
8
  import json
5
9
  import keyword
@@ -11,18 +15,10 @@ import tempfile
11
15
  import gzip
12
16
  import webbrowser
13
17
  import json
18
+
14
19
  from html import escape
15
20
  from typing import Callable, Union
16
21
 
17
- from pygments import highlight
18
- from pygments.lexers import JsonLexer
19
- from pygments.formatters import HtmlFormatter
20
- from IPython.display import HTML
21
-
22
- from functools import wraps
23
- import types
24
- import time
25
-
26
22
 
27
23
  def time_it(func):
28
24
  @wraps(func)
@@ -52,10 +48,6 @@ def dict_hash(data: dict):
52
48
  )
53
49
 
54
50
 
55
- import re
56
- import json
57
-
58
-
59
51
  def extract_json_from_string(text):
60
52
  pattern = re.compile(r"\{.*?\}")
61
53
  match = pattern.search(text)
@@ -96,6 +88,11 @@ def data_to_html(data, replace_new_lines=False):
96
88
  if "edsl_class_name" in data:
97
89
  _ = data.pop("edsl_class_name")
98
90
 
91
+ from pygments import highlight
92
+ from pygments.lexers import JsonLexer
93
+ from pygments.formatters import HtmlFormatter
94
+ from IPython.display import HTML
95
+
99
96
  json_str = json.dumps(data, indent=4)
100
97
  formatted_json = highlight(
101
98
  json_str,
@@ -104,6 +101,7 @@ def data_to_html(data, replace_new_lines=False):
104
101
  )
105
102
  if replace_new_lines:
106
103
  formatted_json = formatted_json.replace("\\n", "<br>")
104
+
107
105
  return HTML(formatted_json).data
108
106
 
109
107
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: edsl
3
- Version: 0.1.28
3
+ Version: 0.1.29
4
4
  Summary: Create and analyze LLM-based surveys
5
5
  Home-page: https://www.expectedparrot.com/
6
6
  License: MIT
@@ -57,15 +57,6 @@ The Expected Parrot Domain-Specific Language (EDSL) package lets you conduct com
57
57
  - [LinkedIn](https://www.linkedin.com/company/expectedparrot/)
58
58
  - [Blog](https://blog.expectedparrot.com)
59
59
 
60
- ## 💡 Contributions, feature requests & bugs
61
- Interested in contributing? Want us to add a new feature? Found a bug for us to squash?
62
- Please send us an email at [info@expectedparrot.com](mailto:info@expectedparrot.com) or message us at our [Discord channel](https://discord.com/invite/mxAYkjfy9m).
63
-
64
- ## 💻 Requirements
65
- * EDSL is compatible with Python 3.9 - 3.12.
66
- * API keys for large language models that you want to use, stored in a `.env` file.
67
- See instructions on [storing API keys](https://docs.expectedparrot.com/en/latest/api_keys.html).
68
-
69
60
  ## 🌎 Hello, World!
70
61
  A quick example:
71
62
 
@@ -96,3 +87,13 @@ Output:
96
87
  │ Good │
97
88
  └───────────────────┘
98
89
  ```
90
+
91
+ ## 💻 Requirements
92
+ * EDSL is compatible with Python 3.9 - 3.12.
93
+ * API keys for large language models that you want to use, stored in a `.env` file.
94
+ See instructions on [storing API keys](https://docs.expectedparrot.com/en/latest/api_keys.html).
95
+
96
+ ## 💡 Contributions, feature requests & bugs
97
+ Interested in contributing? Want us to add a new feature? Found a bug for us to squash?
98
+ Please send us an email at [info@expectedparrot.com](mailto:info@expectedparrot.com) or message us at our [Discord channel](https://discord.com/invite/mxAYkjfy9m).
99
+