edsl 0.1.36.dev6__py3-none-any.whl → 0.1.36.dev7__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/__init__.py CHANGED
@@ -27,6 +27,7 @@ from edsl.questions import QuestionTopK
27
27
 
28
28
  from edsl.scenarios import Scenario
29
29
  from edsl.scenarios import ScenarioList
30
+ from edsl.scenarios.FileStore import FileStore
30
31
 
31
32
  # from edsl.utilities.interface import print_dict_with_rich
32
33
  from edsl.surveys.Survey import Survey
edsl/__version__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.36.dev6"
1
+ __version__ = "0.1.36.dev7"
@@ -115,7 +115,11 @@ class InvigilatorBase(ABC):
115
115
  iteration = data["iteration"]
116
116
  additional_prompt_data = data["additional_prompt_data"]
117
117
  cache = Cache.from_dict(data["cache"])
118
- sidecar_model = LanguageModel.from_dict(data["sidecar_model"])
118
+
119
+ if data["sidecar_model"] is None:
120
+ sidecar_model = None
121
+ else:
122
+ sidecar_model = LanguageModel.from_dict(data["sidecar_model"])
119
123
 
120
124
  return cls(
121
125
  agent=agent,
@@ -1,17 +1,11 @@
1
1
  from __future__ import annotations
2
2
  from typing import Dict, Any, Optional, Set
3
- from collections import UserList
4
- import pdb
5
3
 
6
4
  from jinja2 import Environment, meta
7
5
 
8
6
  from edsl.prompts.Prompt import Prompt
9
- from edsl.data_transfer_models import ImageInfo
10
7
 
11
- # from edsl.prompts.registry import get_classes as prompt_lookup
12
- from edsl.exceptions import QuestionScenarioRenderError
13
-
14
- from edsl.agents.prompt_helpers import PromptComponent, PromptList, PromptPlan
8
+ from edsl.agents.prompt_helpers import PromptPlan
15
9
 
16
10
 
17
11
  def get_jinja2_variables(template_str: str) -> Set[str]:
@@ -153,14 +147,28 @@ class PromptConstructor:
153
147
 
154
148
  # might be getting it from the prior answers
155
149
  if self.prior_answers_dict().get(question_option_key) is not None:
156
- if isinstance(
157
- question_options := self.prior_answers_dict()
158
- .get(question_option_key)
159
- .answer,
160
- list,
161
- ):
162
- question_data["question_options"] = question_options
163
- self.question.question_options = question_options
150
+ prior_question = self.prior_answers_dict().get(question_option_key)
151
+ if hasattr(prior_question, "answer"):
152
+ if isinstance(prior_question.answer, list):
153
+ question_data["question_options"] = prior_question.answer
154
+ self.question.question_options = prior_question.answer
155
+ else:
156
+ placeholder_options = [
157
+ "N/A",
158
+ "Will be populated by prior answer",
159
+ "These are placeholder options",
160
+ ]
161
+ question_data["question_options"] = placeholder_options
162
+ self.question.question_options = placeholder_options
163
+
164
+ # if isinstance(
165
+ # question_options := self.prior_answers_dict()
166
+ # .get(question_option_key)
167
+ # .answer,
168
+ # list,
169
+ # ):
170
+ # question_data["question_options"] = question_options
171
+ # self.question.question_options = question_options
164
172
 
165
173
  replacement_dict = (
166
174
  {key: f"<see file {key}>" for key in self.scenario_file_keys}
@@ -169,6 +169,7 @@ class Conversation:
169
169
  agent=speaker,
170
170
  just_answer=False,
171
171
  cache=self.cache,
172
+ model=speaker.model,
172
173
  )
173
174
  return results[0]
174
175
 
@@ -179,7 +180,6 @@ class Conversation:
179
180
  i = 0
180
181
  while await self.continue_conversation():
181
182
  speaker = self.next_speaker()
182
- # breakpoint()
183
183
 
184
184
  next_statement = AgentStatement(
185
185
  statement=await self.get_next_statement(
@@ -60,13 +60,15 @@ class InferenceServicesCollection:
60
60
 
61
61
  if model_name == "test":
62
62
  return TestService.create_model(model_name)
63
+
64
+ if service_name:
65
+ for service in self.services:
66
+ if service_name == service._inference_service_:
67
+ return service.create_model(model_name)
68
+
63
69
  for service in self.services:
64
70
  if model_name in self._get_service_available(service):
65
71
  if service_name is None or service_name == service._inference_service_:
66
72
  return service.create_model(model_name)
67
73
 
68
- # if model_name == "test":
69
- # from edsl.language_models import LanguageModel
70
- # return LanguageModel(test = True)
71
-
72
74
  raise Exception(f"Model {model_name} not found in any of the services")
@@ -178,7 +178,7 @@ class Interview:
178
178
  if include_exceptions:
179
179
  d["exceptions"] = self.exceptions.to_dict()
180
180
  return d
181
-
181
+
182
182
  @classmethod
183
183
  def from_dict(cls, d: dict[str, Any]) -> "Interview":
184
184
  """Return an Interview instance from a dictionary."""
@@ -187,13 +187,23 @@ class Interview:
187
187
  scenario = Scenario.from_dict(d["scenario"])
188
188
  model = LanguageModel.from_dict(d["model"])
189
189
  iteration = d["iteration"]
190
- return cls(agent=agent, survey=survey, scenario=scenario, model=model, iteration=iteration)
190
+ interview = cls(
191
+ agent=agent,
192
+ survey=survey,
193
+ scenario=scenario,
194
+ model=model,
195
+ iteration=iteration,
196
+ )
197
+ if "exceptions" in d:
198
+ exceptions = InterviewExceptionCollection.from_dict(d["exceptions"])
199
+ interview.exceptions = exceptions
200
+ return interview
191
201
 
192
202
  def __hash__(self) -> int:
193
203
  from edsl.utilities.utilities import dict_hash
194
204
 
195
205
  return dict_hash(self._to_dict(include_exceptions=False))
196
-
206
+
197
207
  def __eq__(self, other: "Interview") -> bool:
198
208
  """
199
209
  >>> from edsl.jobs.interviews.Interview import Interview; i = Interview.example(); d = i._to_dict(); i2 = Interview.from_dict(d); i == i2
@@ -132,18 +132,25 @@ class InterviewExceptionEntry:
132
132
  )
133
133
  console.print(tb)
134
134
  return html_output.getvalue()
135
-
135
+
136
136
  @staticmethod
137
137
  def serialize_exception(exception: Exception) -> dict:
138
138
  return {
139
139
  "type": type(exception).__name__,
140
140
  "message": str(exception),
141
- "traceback": "".join(traceback.format_exception(type(exception), exception, exception.__traceback__)),
141
+ "traceback": "".join(
142
+ traceback.format_exception(
143
+ type(exception), exception, exception.__traceback__
144
+ )
145
+ ),
142
146
  }
143
-
147
+
144
148
  @staticmethod
145
149
  def deserialize_exception(data: dict) -> Exception:
146
- exception_class = globals()[data["type"]]
150
+ try:
151
+ exception_class = globals()[data["type"]]
152
+ except KeyError:
153
+ exception_class = Exception
147
154
  return exception_class(data["message"])
148
155
 
149
156
  def to_dict(self) -> dict:
@@ -158,7 +165,7 @@ class InterviewExceptionEntry:
158
165
  "traceback": self.traceback,
159
166
  "invigilator": self.invigilator.to_dict(),
160
167
  }
161
-
168
+
162
169
  @classmethod
163
170
  def from_dict(cls, data: dict) -> "InterviewExceptionEntry":
164
171
  """Create an InterviewExceptionEntry from a dictionary."""
@@ -77,8 +77,19 @@ class FileStore(Scenario):
77
77
  def __str__(self):
78
78
  return "FileStore: self.path"
79
79
 
80
+ @classmethod
81
+ def example(self):
82
+ import tempfile
83
+
84
+ with tempfile.NamedTemporaryFile(suffix=".txt", delete=False) as f:
85
+ f.write(b"Hello, World!")
86
+
87
+ return self(path=f.name)
88
+
80
89
  @property
81
90
  def size(self) -> int:
91
+ if self.base64_string != None:
92
+ return (len(self.base64_string) / 4.0) * 3 # from base64 to char size
82
93
  return os.path.getsize(self.path)
83
94
 
84
95
  def upload_google(self, refresh: bool = False) -> None:
@@ -93,7 +104,7 @@ class FileStore(Scenario):
93
104
  return cls(**d)
94
105
 
95
106
  def __repr__(self):
96
- return f"FileStore({self.path})"
107
+ return f"FileStore(path='{self.path}')"
97
108
 
98
109
  def encode_file_to_base64_string(self, file_path: str):
99
110
  try:
@@ -272,7 +283,8 @@ class CSVFileStore(FileStore):
272
283
 
273
284
  with tempfile.NamedTemporaryFile(suffix=".csv", delete=False) as f:
274
285
  r.to_csv(filename=f.name)
275
- return cls(f.name)
286
+
287
+ return cls(f.name)
276
288
 
277
289
  def view(self):
278
290
  import pandas as pd
@@ -352,7 +364,8 @@ class PDFFileStore(FileStore):
352
364
 
353
365
  with tempfile.NamedTemporaryFile(suffix=".pdf", delete=False) as f:
354
366
  f.write(pdf_string.encode())
355
- return cls(f.name)
367
+
368
+ return cls(f.name)
356
369
 
357
370
 
358
371
  class PNGFileStore(FileStore):
@@ -367,7 +380,8 @@ class PNGFileStore(FileStore):
367
380
 
368
381
  with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as f:
369
382
  f.write(png_string.encode())
370
- return cls(f.name)
383
+
384
+ return cls(f.name)
371
385
 
372
386
  def view(self):
373
387
  import matplotlib.pyplot as plt
@@ -407,7 +421,8 @@ class HTMLFileStore(FileStore):
407
421
 
408
422
  with tempfile.NamedTemporaryFile(suffix=".html", delete=False) as f:
409
423
  f.write("<html><body><h1>Test</h1></body></html>".encode())
410
- return cls(f.name)
424
+
425
+ return cls(f.name)
411
426
 
412
427
  def view(self):
413
428
  import webbrowser
@@ -448,7 +448,10 @@ class Scenario(Base, UserDict, ScenarioHtmlMixin):
448
448
  from edsl.scenarios.FileStore import FileStore
449
449
 
450
450
  for key, value in d.items():
451
- if isinstance(value, FileStore):
451
+ # TODO: we should check this better if its a FileStore + add remote security check against path traversal
452
+ if (
453
+ isinstance(value, dict) and "base64_string" in value and "path" in value
454
+ ) or isinstance(value, FileStore):
452
455
  d[key] = FileStore.from_dict(value)
453
456
  return cls(d)
454
457
 
@@ -1,2 +1,4 @@
1
1
  from edsl.scenarios.Scenario import Scenario
2
2
  from edsl.scenarios.ScenarioList import ScenarioList
3
+
4
+ # from edsl.scenarios.FileStore import FileStore
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: edsl
3
- Version: 0.1.36.dev6
3
+ Version: 0.1.36.dev7
4
4
  Summary: Create and analyze LLM-based surveys
5
5
  Home-page: https://www.expectedparrot.com/
6
6
  License: MIT
@@ -1,13 +1,13 @@
1
- edsl/__init__.py,sha256=FSkGD82Dmfq6YBA3qI2bJ78OkQ8mpIik0sttRyFRy3M,1817
2
- edsl/__version__.py,sha256=Xth943Ecpt6YA-YRz5PoihEUZTNkilcDyvngmNz_OGI,29
1
+ edsl/__init__.py,sha256=Xc4AuXpEALuT7khU4CFgvV_WI9elsQ28w5RuyVx8MME,1865
2
+ edsl/__version__.py,sha256=6G_boHcFK2Q6vwHq6Zziy2_UPxrrBy5vUxfKO8biOkI,29
3
3
  edsl/agents/__init__.py,sha256=Jw2EmdckbcROk_4tRPcJ2i-YEutApOs8BCohy3IHzqY,139
4
4
  edsl/agents/Agent.py,sha256=wfkYA8OSQVnxpp5mz-CxhbDeLTefe4JGqs7PNriYRzU,30262
5
5
  edsl/agents/AgentList.py,sha256=wV_URK5jc5OAVjT9UUeBatyVCoy0KAqE8id3ZUrnnGE,11300
6
6
  edsl/agents/descriptors.py,sha256=Qj-G_ZgfFJFc8wPGz4-Aae4hpL4XRBvxPEeewfaUWv4,3020
7
7
  edsl/agents/Invigilator.py,sha256=FTGgnXAEn1oTWQHHeZ32Rq4t7qgX01XZoYhVKsqWQE8,9302
8
- edsl/agents/InvigilatorBase.py,sha256=wUt4qmO9nu45gGDkfnsrONqPkx1EBqumiZcP07-pqKo,10635
8
+ edsl/agents/InvigilatorBase.py,sha256=S5KGNnq0bKbP-q4eJCH-Bb8MYQG1Ol2oIXPfrrXI4D4,10733
9
9
  edsl/agents/prompt_helpers.py,sha256=oBuv6vWyP3na8qmBV_uYMB2Aq0_FEHzCYFhpEzt8leE,5152
10
- edsl/agents/PromptConstructor.py,sha256=47atZ0F_6uTcVo3Bp-VnHxtdDmmMK248CR3tjFKEry8,13342
10
+ edsl/agents/PromptConstructor.py,sha256=tGZQ7kXjjr8DXbgqDE1kTQJjEJH_3VA3WgPaCVmti6Y,13925
11
11
  edsl/auto/AutoStudy.py,sha256=bUhIvpDzQdYgDpAc8jCpNdCh6cI6brdJU8DaoScxkTo,3960
12
12
  edsl/auto/StageBase.py,sha256=BUcIdH5O2nsoSjlNyBM61dGTnKV-09N6-5HO0ykmbTU,8163
13
13
  edsl/auto/StageGenerateSurvey.py,sha256=4xe7PVTXSP-i3O9NSmX-an2OkRoyxCBygWaT-nslBsA,7572
@@ -40,7 +40,7 @@ edsl/conjure/RawQuestion.py,sha256=jRlnuSq5Wa9wtmlocSAyCC6gLXe_3zOWtOCpyUjL0Is,2
40
40
  edsl/conjure/SurveyResponses.py,sha256=_qvRhInlXovVLU4TEzouQ2HvZeYlCvUPaElC9MxvEbg,198
41
41
  edsl/conjure/utilities.py,sha256=kFj8mp69fTRYmk-9GX43bRF5Y3HvnBkz4xLcPQPTCI4,5740
42
42
  edsl/conversation/car_buying.py,sha256=cY2y7wGiZiXWsat0F0Bh6MJBfVxcuKlZIMlJSpmTbH8,2008
43
- edsl/conversation/Conversation.py,sha256=7RGYK9goGur-h7gvEBX8rbNdMCW02EJ9EmGXco3tXW4,7865
43
+ edsl/conversation/Conversation.py,sha256=al29DNlKb1QnO1pHN6pAxNSilSrWPbcClySswjQ4nL4,7871
44
44
  edsl/conversation/mug_negotiation.py,sha256=WhdhN6dCiZ8bvpptudEnIEObkUQuy4y52-ysQSPuk54,2697
45
45
  edsl/conversation/next_speaker_utilities.py,sha256=EpGlZ_J9-vSNzezpngC58EFCfxOoN8tZ3DHBKcT3h80,3722
46
46
  edsl/coop/__init__.py,sha256=XqMfFaHIeyAb_dfDw7VaKf6wCPdahh19ye4w6XAY3R4,117
@@ -76,7 +76,7 @@ edsl/inference_services/DeepInfraService.py,sha256=OKpc9E9nyJu-mOqUHs_dBwOHh9xhD
76
76
  edsl/inference_services/GoogleService.py,sha256=8nQIlnKNlfP_FNtc0aZGJq1mnAW9aFnU0x8k8YMvTU4,5578
77
77
  edsl/inference_services/GroqService.py,sha256=D2E6lnOjeJNSApo1_ndvHJnUUwXn4nOPmmFgt0CzTYs,530
78
78
  edsl/inference_services/InferenceServiceABC.py,sha256=u5L56F9iecukMaU5KnXmEjfGipNB466aluuaQl4g3as,4841
79
- edsl/inference_services/InferenceServicesCollection.py,sha256=D7F6e3eb0NsSav6_cqWCcXGQO5wSwLSciRoL_EB9nKQ,3040
79
+ edsl/inference_services/InferenceServicesCollection.py,sha256=Zvsimdq9GHUavZ_1WAIjuxjZ_V8iG_L7-JqLeOjFK5Q,3090
80
80
  edsl/inference_services/MistralAIService.py,sha256=42nQ_yh6hZpu9zSEdm0uJxi4sQI9i5YV3p2iK7omCr4,4001
81
81
  edsl/inference_services/models_available_cache.py,sha256=y159MaMtHWQd7Ia7140-dL5zSVKeHRzz1U7y7RAZtL0,4179
82
82
  edsl/inference_services/OllamaService.py,sha256=ewT2SKDXnKcc4wHmMaSlVyJDA9uGLLEWcNTifnz31-g,516
@@ -91,10 +91,10 @@ edsl/jobs/Answers.py,sha256=v1aqWXwSwmra3da3JOYYzU2C1IXkAuYxcrxA4jhxqDw,1877
91
91
  edsl/jobs/buckets/BucketCollection.py,sha256=X843JvQ2Ii_85Z10dpBSq5kIhyUbwTJ3e1iacyvilX8,2349
92
92
  edsl/jobs/buckets/ModelBuckets.py,sha256=Lma0kQ8FvZ1FkB8PkBE2nunU27uDeMxBs1GVAbXrtmo,2484
93
93
  edsl/jobs/buckets/TokenBucket.py,sha256=-Dsqrd-TdRH8WElyCv2SaWmUVMQmugEhfVpOBQeqO7w,9338
94
- edsl/jobs/interviews/Interview.py,sha256=LUAL8geTpd64tAzvyfyncZApalX0txoZ6ZcCUu8N6is,26406
94
+ edsl/jobs/interviews/Interview.py,sha256=pOIxDSNZHgvPpCZemaIDWKFfFUT2_AbfMGewzQWTyQo,26666
95
95
  edsl/jobs/interviews/interview_status_enum.py,sha256=p9Nqw2mcKqx3JMOyDQ7wQNnRkM03HVCA8YUPmKaRBrU,238
96
96
  edsl/jobs/interviews/InterviewExceptionCollection.py,sha256=F6cHFiG-sQtznVmgZh56yOGaIii6yaGykiNmP0MHNHs,3769
97
- edsl/jobs/interviews/InterviewExceptionEntry.py,sha256=4KGBg9PywUVRTHtX2Myz4L7GaaJO8gedGGJSrgFW_bc,5771
97
+ edsl/jobs/interviews/InterviewExceptionEntry.py,sha256=-pfyNYrmZxkoumlXVckiwG-k_Fk2-IjM9tWARJyJ_Zg,5916
98
98
  edsl/jobs/interviews/InterviewStatistic.py,sha256=U-tgtvE6vReExlzMqbb5XzNT8aA3BpwcQ2KOXvI6Yi0,1919
99
99
  edsl/jobs/interviews/InterviewStatisticsCollection.py,sha256=gAUQ77j1tTpBrhnGo4l2l_AD3cvYa7JH_CfdmMVljtM,813
100
100
  edsl/jobs/interviews/InterviewStatusDictionary.py,sha256=mxNuG6rVtiqhaeN7r7z_A0ikAqOha-nzKztsPE8YV-4,2563
@@ -212,9 +212,9 @@ edsl/results/ResultsGGMixin.py,sha256=e_PP_IRFjYtxUBJKeQRlTfu0RoavReV1CIY_9g1OQw
212
212
  edsl/results/ResultsToolsMixin.py,sha256=WkxeXVi77h1-lkYD6RoVRfpd2Hmb5KNzsEpNzdZdMes,3115
213
213
  edsl/results/Selector.py,sha256=rnufGzOX9Nb9KHmv318A0zyWNj80xJMCyZovRP9Z2qA,4521
214
214
  edsl/results/tree_explore.py,sha256=IN3dFSXrCfTfjhOb6NmypK6p-TW1TqOD8278BMcyIEg,4739
215
- edsl/scenarios/__init__.py,sha256=z0E7KqtoirVubKi4VlcR6eKKzy6fX80iVDTPG8FhlM0,100
216
- edsl/scenarios/FileStore.py,sha256=4QLHgACEk0LyfnrbQrctr53CyI17LXHpDulYeRNNdVE,14372
217
- edsl/scenarios/Scenario.py,sha256=WtrszxUpRi_ZJiJce9Dzs2LnlpJVxBFWVUxIW2STCUA,17699
215
+ edsl/scenarios/__init__.py,sha256=y67hh_l-sCdMP0fFUa7nEbC-wP-X97OdhTLrcfYussw,152
216
+ edsl/scenarios/FileStore.py,sha256=AHDN8sWIP5Rb1qej_yYNVY4eoKdGAxGyDLrXkZaBmCA,14718
217
+ edsl/scenarios/Scenario.py,sha256=pcMawbPgZRc45CZTnAL2hmi2dZIn-jp8-VlCkGMf2do,17928
218
218
  edsl/scenarios/ScenarioHtmlMixin.py,sha256=SS5ZVxw8fo6Z3TER_nJP6FV8UdcYP11wgu-VxBhgqcQ,1941
219
219
  edsl/scenarios/ScenarioList.py,sha256=er1qIxC86nBDdD-IiJWwUaKE88y71s98VwK2g7LsFNM,42043
220
220
  edsl/scenarios/ScenarioListExportMixin.py,sha256=IjOGh3c8WPJnmdJz69W6DnUcTKpHVsMikdQxzs7-5OE,1733
@@ -273,7 +273,7 @@ edsl/utilities/repair_functions.py,sha256=ZnoJsWzBRxhZnMf4yY3586nmoR_5pzktV-xWdh
273
273
  edsl/utilities/restricted_python.py,sha256=ZK4r_T3cNSvIMXTuyC6dCHVX6-ed2NRzzXUbHAcgLlw,2130
274
274
  edsl/utilities/SystemInfo.py,sha256=7xJ8MYEEx3aVFOoynu_nQqAv2ePQMyehEZOxFWMZk44,820
275
275
  edsl/utilities/utilities.py,sha256=7om9Nh9IWxusHEA2a2QuwZiaoLozbSTCIPkfKf5ZIGk,11758
276
- edsl-0.1.36.dev6.dist-info/LICENSE,sha256=hq3hkdxkn1rC8xTiiHh0VdWniMNkcS3rBozeiaKE5SQ,1132
277
- edsl-0.1.36.dev6.dist-info/METADATA,sha256=e9tVTO4aysOkrbQIyO_S7QsmmrWUvBDtKlMtNP5zsl4,4476
278
- edsl-0.1.36.dev6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
279
- edsl-0.1.36.dev6.dist-info/RECORD,,
276
+ edsl-0.1.36.dev7.dist-info/LICENSE,sha256=hq3hkdxkn1rC8xTiiHh0VdWniMNkcS3rBozeiaKE5SQ,1132
277
+ edsl-0.1.36.dev7.dist-info/METADATA,sha256=Cq1gWcs0i1QKdPy14Vwel2s9D9DvEhqvv0qmVX8tFKs,4476
278
+ edsl-0.1.36.dev7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
279
+ edsl-0.1.36.dev7.dist-info/RECORD,,