edsl 0.1.27.dev1__tar.gz → 0.1.28__tar.gz

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 (210) hide show
  1. {edsl-0.1.27.dev1 → edsl-0.1.28}/PKG-INFO +43 -17
  2. edsl-0.1.28/README.md +55 -0
  3. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/Base.py +99 -22
  4. edsl-0.1.28/edsl/BaseDiff.py +260 -0
  5. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/__init__.py +4 -0
  6. edsl-0.1.28/edsl/__version__.py +1 -0
  7. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/agents/Agent.py +26 -5
  8. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/agents/AgentList.py +62 -7
  9. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/agents/Invigilator.py +4 -9
  10. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/agents/InvigilatorBase.py +5 -5
  11. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/agents/descriptors.py +3 -1
  12. edsl-0.1.28/edsl/conjure/AgentConstructionMixin.py +152 -0
  13. edsl-0.1.28/edsl/conjure/Conjure.py +56 -0
  14. edsl-0.1.28/edsl/conjure/InputData.py +628 -0
  15. edsl-0.1.28/edsl/conjure/InputDataCSV.py +48 -0
  16. edsl-0.1.28/edsl/conjure/InputDataMixinQuestionStats.py +182 -0
  17. edsl-0.1.28/edsl/conjure/InputDataPyRead.py +91 -0
  18. edsl-0.1.28/edsl/conjure/InputDataSPSS.py +8 -0
  19. edsl-0.1.28/edsl/conjure/InputDataStata.py +8 -0
  20. edsl-0.1.28/edsl/conjure/QuestionOptionMixin.py +76 -0
  21. edsl-0.1.28/edsl/conjure/QuestionTypeMixin.py +23 -0
  22. edsl-0.1.28/edsl/conjure/RawQuestion.py +65 -0
  23. edsl-0.1.28/edsl/conjure/SurveyResponses.py +7 -0
  24. edsl-0.1.28/edsl/conjure/__init__.py +9 -0
  25. edsl-0.1.28/edsl/conjure/naming_utilities.py +263 -0
  26. edsl-0.1.28/edsl/conjure/utilities.py +201 -0
  27. edsl-0.1.28/edsl/conversation/Conversation.py +238 -0
  28. edsl-0.1.28/edsl/conversation/car_buying.py +58 -0
  29. edsl-0.1.28/edsl/conversation/mug_negotiation.py +81 -0
  30. edsl-0.1.28/edsl/conversation/next_speaker_utilities.py +93 -0
  31. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/coop/coop.py +191 -12
  32. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/coop/utils.py +28 -1
  33. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/data/Cache.py +55 -17
  34. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/data/CacheHandler.py +10 -9
  35. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/inference_services/AnthropicService.py +1 -0
  36. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/inference_services/DeepInfraService.py +20 -13
  37. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/inference_services/GoogleService.py +7 -1
  38. edsl-0.1.28/edsl/inference_services/InferenceServicesCollection.py +60 -0
  39. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/inference_services/OpenAIService.py +17 -10
  40. edsl-0.1.28/edsl/inference_services/models_available_cache.py +69 -0
  41. edsl-0.1.28/edsl/inference_services/rate_limits_cache.py +25 -0
  42. edsl-0.1.28/edsl/inference_services/write_available.py +10 -0
  43. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/Jobs.py +240 -36
  44. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/buckets/BucketCollection.py +9 -3
  45. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/Interview.py +4 -1
  46. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/InterviewTaskBuildingMixin.py +24 -10
  47. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/retry_management.py +4 -4
  48. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/runners/JobsRunnerAsyncio.py +87 -45
  49. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/runners/JobsRunnerStatusData.py +3 -3
  50. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tasks/QuestionTaskCreator.py +4 -2
  51. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/language_models/LanguageModel.py +37 -44
  52. edsl-0.1.28/edsl/language_models/ModelList.py +96 -0
  53. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/language_models/registry.py +14 -0
  54. edsl-0.1.28/edsl/language_models/repair.py +174 -0
  55. edsl-0.1.28/edsl/notebooks/Notebook.py +204 -0
  56. edsl-0.1.28/edsl/notebooks/__init__.py +1 -0
  57. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionBase.py +109 -12
  58. edsl-0.1.28/edsl/questions/derived/__init__.py +0 -0
  59. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/descriptors.py +5 -2
  60. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/question_registry.py +7 -0
  61. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/Result.py +20 -8
  62. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/Results.py +85 -11
  63. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/ResultsDBMixin.py +3 -6
  64. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/ResultsExportMixin.py +47 -16
  65. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/ResultsToolsMixin.py +5 -5
  66. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/scenarios/Scenario.py +59 -5
  67. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/scenarios/ScenarioList.py +97 -40
  68. edsl-0.1.28/edsl/study/ObjectEntry.py +97 -0
  69. edsl-0.1.28/edsl/study/ProofOfWork.py +110 -0
  70. edsl-0.1.28/edsl/study/SnapShot.py +77 -0
  71. edsl-0.1.28/edsl/study/Study.py +491 -0
  72. edsl-0.1.28/edsl/study/__init__.py +2 -0
  73. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/Survey.py +79 -31
  74. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/SurveyExportMixin.py +21 -3
  75. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/__init__.py +1 -0
  76. edsl-0.1.28/edsl/utilities/gcp_bucket/__init__.py +0 -0
  77. edsl-0.1.28/edsl/utilities/gcp_bucket/cloud_storage.py +96 -0
  78. edsl-0.1.28/edsl/utilities/gcp_bucket/simple_example.py +9 -0
  79. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/interface.py +24 -28
  80. edsl-0.1.28/edsl/utilities/repair_functions.py +28 -0
  81. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/utilities.py +57 -2
  82. {edsl-0.1.27.dev1 → edsl-0.1.28}/pyproject.toml +6 -1
  83. edsl-0.1.27.dev1/README.md +0 -29
  84. edsl-0.1.27.dev1/edsl/__version__.py +0 -1
  85. edsl-0.1.27.dev1/edsl/conjure/RawResponseColumn.py +0 -327
  86. edsl-0.1.27.dev1/edsl/conjure/SurveyBuilder.py +0 -308
  87. edsl-0.1.27.dev1/edsl/conjure/SurveyBuilderCSV.py +0 -78
  88. edsl-0.1.27.dev1/edsl/conjure/SurveyBuilderSPSS.py +0 -118
  89. edsl-0.1.27.dev1/edsl/conjure/__init__.py +0 -4
  90. edsl-0.1.27.dev1/edsl/conjure/utilities.py +0 -64
  91. edsl-0.1.27.dev1/edsl/data/RemoteDict.py +0 -103
  92. edsl-0.1.27.dev1/edsl/inference_services/InferenceServicesCollection.py +0 -34
  93. edsl-0.1.27.dev1/edsl/language_models/repair.py +0 -103
  94. {edsl-0.1.27.dev1 → edsl-0.1.28}/LICENSE +0 -0
  95. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/agents/PromptConstructionMixin.py +0 -0
  96. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/agents/__init__.py +0 -0
  97. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/config.py +0 -0
  98. /edsl-0.1.27.dev1/edsl/inference_services/__init__.py → /edsl-0.1.28/edsl/conjure/examples/placeholder.txt +0 -0
  99. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/coop/__init__.py +0 -0
  100. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/data/CacheEntry.py +0 -0
  101. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/data/SQLiteDict.py +0 -0
  102. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/data/__init__.py +0 -0
  103. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/data/orm.py +0 -0
  104. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/data_transfer_models.py +0 -0
  105. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/enums.py +0 -0
  106. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/__init__.py +0 -0
  107. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/agents.py +0 -0
  108. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/configuration.py +0 -0
  109. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/coop.py +0 -0
  110. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/data.py +0 -0
  111. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/general.py +0 -0
  112. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/jobs.py +0 -0
  113. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/language_models.py +0 -0
  114. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/prompts.py +0 -0
  115. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/questions.py +0 -0
  116. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/results.py +0 -0
  117. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/exceptions/surveys.py +0 -0
  118. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/inference_services/InferenceServiceABC.py +0 -0
  119. {edsl-0.1.27.dev1/edsl/questions/derived → edsl-0.1.28/edsl/inference_services}/__init__.py +0 -0
  120. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/inference_services/registry.py +0 -0
  121. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/Answers.py +0 -0
  122. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/__init__.py +0 -0
  123. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/buckets/ModelBuckets.py +0 -0
  124. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/buckets/TokenBucket.py +0 -0
  125. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/InterviewStatistic.py +0 -0
  126. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/InterviewStatisticsCollection.py +0 -0
  127. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/InterviewStatusDictionary.py +0 -0
  128. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/InterviewStatusLog.py +0 -0
  129. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/InterviewStatusMixin.py +0 -0
  130. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/ReportErrors.py +0 -0
  131. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/interview_exception_tracking.py +0 -0
  132. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/interviews/interview_status_enum.py +0 -0
  133. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/runners/JobsRunnerStatusMixin.py +0 -0
  134. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tasks/TaskCreators.py +0 -0
  135. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tasks/TaskHistory.py +0 -0
  136. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tasks/TaskStatusLog.py +0 -0
  137. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tasks/task_management.py +0 -0
  138. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tasks/task_status_enum.py +0 -0
  139. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tokens/InterviewTokenUsage.py +0 -0
  140. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/jobs/tokens/TokenUsage.py +0 -0
  141. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/language_models/RegisterLanguageModelsMeta.py +0 -0
  142. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/language_models/__init__.py +0 -0
  143. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/language_models/unused/ReplicateBase.py +0 -0
  144. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/Prompt.py +0 -0
  145. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/QuestionInstructionsBase.py +0 -0
  146. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/__init__.py +0 -0
  147. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/agent_instructions.py +0 -0
  148. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/agent_persona.py +0 -0
  149. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_budget.py +0 -0
  150. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_checkbox.py +0 -0
  151. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_extract.py +0 -0
  152. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_freetext.py +0 -0
  153. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_linear_scale.py +0 -0
  154. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_list.py +0 -0
  155. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_multiple_choice.py +0 -0
  156. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_numerical.py +0 -0
  157. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/library/question_rank.py +0 -0
  158. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/prompt_config.py +0 -0
  159. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/prompts/registry.py +0 -0
  160. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/AnswerValidatorMixin.py +0 -0
  161. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionBudget.py +0 -0
  162. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionCheckBox.py +0 -0
  163. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionExtract.py +0 -0
  164. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionFreeText.py +0 -0
  165. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionFunctional.py +0 -0
  166. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionList.py +0 -0
  167. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionMultipleChoice.py +0 -0
  168. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionNumerical.py +0 -0
  169. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/QuestionRank.py +0 -0
  170. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/RegisterQuestionsMeta.py +0 -0
  171. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/SimpleAskMixin.py +0 -0
  172. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/__init__.py +0 -0
  173. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/compose_questions.py +0 -0
  174. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/derived/QuestionLikertFive.py +0 -0
  175. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/derived/QuestionLinearScale.py +0 -0
  176. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/derived/QuestionTopK.py +0 -0
  177. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/derived/QuestionYesNo.py +0 -0
  178. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/questions/settings.py +0 -0
  179. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/Dataset.py +0 -0
  180. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/ResultsFetchMixin.py +0 -0
  181. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/ResultsGGMixin.py +0 -0
  182. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/results/__init__.py +0 -0
  183. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/scenarios/ScenarioHtmlMixin.py +0 -0
  184. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/scenarios/ScenarioImageMixin.py +0 -0
  185. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/scenarios/ScenarioListPdfMixin.py +0 -0
  186. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/scenarios/__init__.py +0 -0
  187. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/shared.py +0 -0
  188. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/DAG.py +0 -0
  189. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/Memory.py +0 -0
  190. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/MemoryPlan.py +0 -0
  191. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/Rule.py +0 -0
  192. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/RuleCollection.py +0 -0
  193. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/SurveyCSS.py +0 -0
  194. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/SurveyFlowVisualizationMixin.py +0 -0
  195. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/__init__.py +0 -0
  196. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/base.py +0 -0
  197. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/surveys/descriptors.py +0 -0
  198. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/tools/__init__.py +0 -0
  199. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/tools/clusters.py +0 -0
  200. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/tools/embeddings.py +0 -0
  201. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/tools/embeddings_plotting.py +0 -0
  202. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/tools/plotting.py +0 -0
  203. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/tools/summarize.py +0 -0
  204. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/SystemInfo.py +0 -0
  205. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/ast_utilities.py +0 -0
  206. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/data/Registry.py +0 -0
  207. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/data/__init__.py +0 -0
  208. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/data/scooter_results.json +0 -0
  209. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/decorators.py +0 -0
  210. {edsl-0.1.27.dev1 → edsl-0.1.28}/edsl/utilities/restricted_python.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: edsl
3
- Version: 0.1.27.dev1
3
+ Version: 0.1.28
4
4
  Summary: Create and analyze LLM-based surveys
5
5
  Home-page: https://www.expectedparrot.com/
6
6
  License: MIT
@@ -30,6 +30,7 @@ Requires-Dist: pandas (>=2.1.4,<3.0.0)
30
30
  Requires-Dist: pydot (>=2.0.0,<3.0.0)
31
31
  Requires-Dist: pygments (>=2.17.2,<3.0.0)
32
32
  Requires-Dist: pymupdf (>=1.24.4,<2.0.0)
33
+ Requires-Dist: pyreadstat (>=1.2.7,<2.0.0)
33
34
  Requires-Dist: python-docx (>=1.1.0,<2.0.0)
34
35
  Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
35
36
  Requires-Dist: restrictedpython (>=7.1,<8.0)
@@ -45,28 +46,53 @@ Description-Content-Type: text/markdown
45
46
  <img src="https://github.com/expectedparrot/edsl/blob/main/static/logo.png?raw=true" alt="edsl.png" width="100"/>
46
47
  </p>
47
48
 
48
- The Expected Parrot Domain-Specific Language (EDSL) package lets you conduct computational social science and market research with AI. Use it to design surveys and experiments, simulate responses with large language models, and perform data labeling and other research tasks. EDSL comes with built-in methods for analyzing, visualizing and sharing your results.
49
+ The Expected Parrot Domain-Specific Language (EDSL) package lets you conduct computational social science and market research with AI. Use it to design surveys and experiments, simulate responses with large language models, and perform data labeling and other research tasks. Results are formatted as specified datasets and come with built-in methods for analyzing, visualizing, and sharing.
49
50
 
50
51
  ## 🔗 Links
51
- - PyPI: https://pypi.org/project/edsl/
52
- - Documentation: https://docs.expectedparrot.com
53
- - Getting started: https://docs.expectedparrot.com/en/latest/starter_tutorial.html
54
- - Discord: https://discord.com/invite/mxAYkjfy9m
52
+ - [PyPI](https://pypi.org/project/edsl/)
53
+ - [Documentation](https://docs.expectedparrot.com)
54
+ - [Getting started](https://docs.expectedparrot.com/en/latest/starter_tutorial.html)
55
+ - [Discord](https://discord.com/invite/mxAYkjfy9m)
56
+ - [Twitter](https://x.com/ExpectedParrot)
57
+ - [LinkedIn](https://www.linkedin.com/company/expectedparrot/)
58
+ - [Blog](https://blog.expectedparrot.com)
55
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).
56
63
 
57
- ## 💡 Contributions, Feature Requests & Bugs
58
- Interested in contributing? Want us to add a new feature? Found a nasty bug that you would like us to squash? Please send us an email at info@expectedparrot.com or message us at our Discord server.
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).
59
68
 
69
+ ## 🌎 Hello, World!
70
+ A quick example:
60
71
 
61
- ## 💻 Getting started
62
- EDSL is compatible with Python 3.9 - 3.12.
63
- ```
64
- pip install edsl
65
- ```
72
+ ```python
73
+ # Import a question type
74
+ from edsl.questions import QuestionMultipleChoice
66
75
 
67
- - Read the docs at http://docs.expectedparrot.com.
68
- - See https://docs.expectedparrot.com/en/latest/starter_tutorial.html for examples and tutorials.
76
+ # Construct a question using the question type template
77
+ q = QuestionMultipleChoice(
78
+ question_name="example_question",
79
+ question_text="How do you feel today?",
80
+ question_options=["Bad", "OK", "Good"]
81
+ )
69
82
 
70
- ## 🔧 Dependencies
71
- API keys for LLMs that you want to use, stored in a `.env` file
83
+ # Run it with the default language model
84
+ results = q.run()
72
85
 
86
+ # Inspect the results in a dataset
87
+ results.select("example_question").print()
88
+ ```
89
+
90
+ Output:
91
+ ```python
92
+ ┏━━━━━━━━━━━━━━━━━━━┓
93
+ ┃ answer ┃
94
+ ┃ .example_question ┃
95
+ ┡━━━━━━━━━━━━━━━━━━━┩
96
+ │ Good │
97
+ └───────────────────┘
98
+ ```
edsl-0.1.28/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Expected Parrot Domain-Specific Language
2
+ <p align="center">
3
+ <img src="https://github.com/expectedparrot/edsl/blob/main/static/logo.png?raw=true" alt="edsl.png" width="100"/>
4
+ </p>
5
+
6
+ The Expected Parrot Domain-Specific Language (EDSL) package lets you conduct computational social science and market research with AI. Use it to design surveys and experiments, simulate responses with large language models, and perform data labeling and other research tasks. Results are formatted as specified datasets and come with built-in methods for analyzing, visualizing, and sharing.
7
+
8
+ ## 🔗 Links
9
+ - [PyPI](https://pypi.org/project/edsl/)
10
+ - [Documentation](https://docs.expectedparrot.com)
11
+ - [Getting started](https://docs.expectedparrot.com/en/latest/starter_tutorial.html)
12
+ - [Discord](https://discord.com/invite/mxAYkjfy9m)
13
+ - [Twitter](https://x.com/ExpectedParrot)
14
+ - [LinkedIn](https://www.linkedin.com/company/expectedparrot/)
15
+ - [Blog](https://blog.expectedparrot.com)
16
+
17
+ ## 💡 Contributions, feature requests & bugs
18
+ Interested in contributing? Want us to add a new feature? Found a bug for us to squash?
19
+ 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).
20
+
21
+ ## 💻 Requirements
22
+ * EDSL is compatible with Python 3.9 - 3.12.
23
+ * API keys for large language models that you want to use, stored in a `.env` file.
24
+ See instructions on [storing API keys](https://docs.expectedparrot.com/en/latest/api_keys.html).
25
+
26
+ ## 🌎 Hello, World!
27
+ A quick example:
28
+
29
+ ```python
30
+ # Import a question type
31
+ from edsl.questions import QuestionMultipleChoice
32
+
33
+ # Construct a question using the question type template
34
+ q = QuestionMultipleChoice(
35
+ question_name="example_question",
36
+ question_text="How do you feel today?",
37
+ question_options=["Bad", "OK", "Good"]
38
+ )
39
+
40
+ # Run it with the default language model
41
+ results = q.run()
42
+
43
+ # Inspect the results in a dataset
44
+ results.select("example_question").print()
45
+ ```
46
+
47
+ Output:
48
+ ```python
49
+ ┏━━━━━━━━━━━━━━━━━━━┓
50
+ ┃ answer ┃
51
+ ┃ .example_question ┃
52
+ ┡━━━━━━━━━━━━━━━━━━━┩
53
+ │ Good │
54
+ └───────────────────┘
55
+ ```
@@ -4,7 +4,7 @@ from abc import ABC, abstractmethod, ABCMeta
4
4
  import gzip
5
5
  import io
6
6
  import json
7
- from typing import Union
7
+ from typing import Any, Optional, Union
8
8
  from uuid import UUID
9
9
  from IPython.display import display
10
10
  from rich.console import Console
@@ -40,25 +40,30 @@ class RichPrintingMixin:
40
40
  class PersistenceMixin:
41
41
  """Mixin for saving and loading objects to and from files."""
42
42
 
43
- def push(self, visibility="unlisted"):
43
+ def push(
44
+ self,
45
+ description: Optional[str] = None,
46
+ visibility: Optional[str] = "unlisted",
47
+ ):
44
48
  """Post the object to coop."""
45
49
  from edsl.coop import Coop
46
50
 
47
51
  c = Coop()
48
- return c.create(self, visibility)
52
+ return c.create(self, description, visibility)
49
53
 
50
54
  @classmethod
51
- def pull(cls, id_or_url: Union[str, UUID]):
55
+ def pull(cls, id_or_url: Union[str, UUID], exec_profile=None):
52
56
  """Pull the object from coop."""
53
57
  from edsl.coop import Coop
54
58
 
59
+ if id_or_url.startswith("http"):
60
+ uuid_value = id_or_url.split("/")[-1]
61
+ else:
62
+ uuid_value = id_or_url
63
+
55
64
  c = Coop()
56
- return c._get_base(cls, id_or_url)
57
- # if isinstance(id_or_url, str) and c.url in id_or_url:
58
- # return c.get(url=id_or_url)
59
- # else:
60
- # _, object_type = c._resolve_edsl_object(cls)
61
- # return c.get(object_type, id_or_url)
65
+
66
+ return c._get_base(cls, uuid_value, exec_profile=exec_profile)
62
67
 
63
68
  @classmethod
64
69
  def delete(cls, id_or_url: Union[str, UUID]):
@@ -69,15 +74,23 @@ class PersistenceMixin:
69
74
  return c._delete_base(cls, id_or_url)
70
75
 
71
76
  @classmethod
72
- def patch(cls, id_or_url: Union[str, UUID], visibility: str):
77
+ def patch(
78
+ cls,
79
+ id_or_url: Union[str, UUID],
80
+ description: Optional[str] = None,
81
+ value: Optional[Any] = None,
82
+ visibility: Optional[str] = None,
83
+ ):
73
84
  """
74
85
  Patch an uploaded objects attributes.
75
- - Only supports changing visibility for now.
86
+ - `description` changes the description of the object on Coop
87
+ - `value` changes the value of the object on Coop. **has to be an EDSL object**
88
+ - `visibility` changes the visibility of the object on Coop
76
89
  """
77
90
  from edsl.coop import Coop
78
91
 
79
92
  c = Coop()
80
- return c._patch_base(cls, id_or_url, visibility)
93
+ return c._patch_base(cls, id_or_url, description, value, visibility)
81
94
 
82
95
  @classmethod
83
96
  def search(cls, query):
@@ -87,14 +100,45 @@ class PersistenceMixin:
87
100
  c = Coop()
88
101
  return c.search(cls, query)
89
102
 
90
- def save(self, filename):
103
+ def save(self, filename, compress=True):
91
104
  """Save the object to a file as zippped JSON.
92
105
 
93
106
  >>> obj.save("obj.json.gz")
94
107
 
95
108
  """
96
- with gzip.open(filename, "wb") as f:
97
- f.write(json.dumps(self.to_dict()).encode("utf-8"))
109
+ if filename.endswith("json.gz"):
110
+ import warnings
111
+
112
+ warnings.warn(
113
+ "Do not apply the file extensions. The filename should not end with 'json.gz'."
114
+ )
115
+ filename = filename[:-7]
116
+ if filename.endswith("json"):
117
+ filename = filename[:-4]
118
+ warnings.warn(
119
+ "Do not apply the file extensions. The filename should not end with 'json'."
120
+ )
121
+
122
+ if compress:
123
+ with gzip.open(filename + ".json.gz", "wb") as f:
124
+ f.write(json.dumps(self.to_dict()).encode("utf-8"))
125
+ else:
126
+ with open(filename + ".json", "w") as f:
127
+ f.write(json.dumps(self.to_dict()))
128
+
129
+ @staticmethod
130
+ def open_compressed_file(filename):
131
+ with gzip.open(filename, "rb") as f:
132
+ file_contents = f.read()
133
+ file_contents_decoded = file_contents.decode("utf-8")
134
+ d = json.loads(file_contents_decoded)
135
+ return d
136
+
137
+ @staticmethod
138
+ def open_regular_file(filename):
139
+ with open(filename, "r") as f:
140
+ d = json.loads(f.read())
141
+ return d
98
142
 
99
143
  @classmethod
100
144
  def load(cls, filename):
@@ -103,11 +147,19 @@ class PersistenceMixin:
103
147
  >>> obj = cls.load("obj.json.gz")
104
148
 
105
149
  """
106
- with gzip.open(filename, "rb") as f:
107
- file_contents = f.read()
108
- file_contents_decoded = file_contents.decode("utf-8")
109
- d = json.loads(file_contents_decoded)
110
- # d = json.loads(f.read().decode("utf-8"))
150
+
151
+ if filename.endswith("json.gz"):
152
+ d = cls.open_compressed_file(filename)
153
+ elif filename.endswith("json"):
154
+ d = cls.open_regular_file(filename)
155
+ else:
156
+ try:
157
+ d = cls.open_compressed_file(filename)
158
+ except:
159
+ d = cls.open_regular_file(filename)
160
+ finally:
161
+ raise ValueError("File must be a json or json.gz file")
162
+
111
163
  return cls.from_dict(d)
112
164
 
113
165
 
@@ -128,7 +180,21 @@ class RegisterSubclassesMeta(ABCMeta):
128
180
  return dict(RegisterSubclassesMeta._registry)
129
181
 
130
182
 
131
- class Base(RichPrintingMixin, PersistenceMixin, ABC, metaclass=RegisterSubclassesMeta):
183
+ class DiffMethodsMixin:
184
+ def __sub__(self, other):
185
+ """Return the difference between two objects."""
186
+ from edsl.BaseDiff import BaseDiff
187
+
188
+ return BaseDiff(self, other)
189
+
190
+
191
+ class Base(
192
+ RichPrintingMixin,
193
+ PersistenceMixin,
194
+ DiffMethodsMixin,
195
+ ABC,
196
+ metaclass=RegisterSubclassesMeta,
197
+ ):
132
198
  """Base class for all classes in the package."""
133
199
 
134
200
  # def __getitem__(self, key):
@@ -172,6 +238,17 @@ class Base(RichPrintingMixin, PersistenceMixin, ABC, metaclass=RegisterSubclasse
172
238
  # f.write(html_string)
173
239
  # webbrowser.open(f.name)
174
240
 
241
+ def __eq__(self, other):
242
+ """Return whether two objects are equal."""
243
+ import inspect
244
+
245
+ if not isinstance(other, self.__class__):
246
+ return False
247
+ if "sort" in inspect.signature(self._to_dict).parameters:
248
+ return self._to_dict(sort=True) == other._to_dict(sort=True)
249
+ else:
250
+ return self._to_dict() == other._to_dict()
251
+
175
252
  @abstractmethod
176
253
  def example():
177
254
  """This method should be implemented by subclasses."""
@@ -0,0 +1,260 @@
1
+ import difflib
2
+ import json
3
+ from typing import Any, Dict, Tuple
4
+ from collections import UserList
5
+ import inspect
6
+
7
+
8
+ class BaseDiffCollection(UserList):
9
+ def __init__(self, diffs=None):
10
+ if diffs is None:
11
+ diffs = []
12
+ super().__init__(diffs)
13
+
14
+ def apply(self, obj: Any):
15
+ for diff in self:
16
+ obj = diff.apply(obj)
17
+ return obj
18
+
19
+ def add_diff(self, diff) -> "BaseDiffCollection":
20
+ self.append(diff)
21
+ return self
22
+
23
+
24
+ class DummyObject:
25
+ def __init__(self, object_dict):
26
+ self.object_dict = object_dict
27
+
28
+ def _to_dict(self):
29
+ return self.object_dict
30
+
31
+
32
+ class BaseDiff:
33
+ def __init__(
34
+ self, obj1: Any, obj2: Any, added=None, removed=None, modified=None, level=0
35
+ ):
36
+ self.level = level
37
+
38
+ self.obj1 = obj1
39
+ self.obj2 = obj2
40
+
41
+ if "sort" in inspect.signature(obj1._to_dict).parameters:
42
+ self._dict1 = obj1._to_dict(sort=True)
43
+ self._dict2 = obj2._to_dict(sort=True)
44
+ else:
45
+ self._dict1 = obj1._to_dict()
46
+ self._dict2 = obj2._to_dict()
47
+ self._obj_class = type(obj1)
48
+
49
+ self.added = added
50
+ self.removed = removed
51
+ self.modified = modified
52
+
53
+ def __bool__(self):
54
+ return bool(self.added or self.removed or self.modified)
55
+
56
+ @property
57
+ def added(self):
58
+ if self._added is None:
59
+ self._added = self._find_added()
60
+ return self._added
61
+
62
+ def __add__(self, other):
63
+ return self.apply(other)
64
+
65
+ @added.setter
66
+ def added(self, value):
67
+ self._added = value if value is not None else self._find_added()
68
+
69
+ @property
70
+ def removed(self):
71
+ if self._removed is None:
72
+ self._removed = self._find_removed()
73
+ return self._removed
74
+
75
+ @removed.setter
76
+ def removed(self, value):
77
+ self._removed = value if value is not None else self._find_removed()
78
+
79
+ @property
80
+ def modified(self):
81
+ if self._modified is None:
82
+ self._modified = self._find_modified()
83
+ return self._modified
84
+
85
+ @modified.setter
86
+ def modified(self, value):
87
+ self._modified = value if value is not None else self._find_modified()
88
+
89
+ def _find_added(self) -> Dict[Any, Any]:
90
+ return {k: self._dict2[k] for k in self._dict2 if k not in self._dict1}
91
+
92
+ def _find_removed(self) -> Dict[Any, Any]:
93
+ return {k: self._dict1[k] for k in self._dict1 if k not in self._dict2}
94
+
95
+ def _find_modified(self) -> Dict[Any, Tuple[Any, Any, str]]:
96
+ modified = {}
97
+ for k in self._dict1:
98
+ if k in self._dict2 and self._dict1[k] != self._dict2[k]:
99
+ if isinstance(self._dict1[k], str) and isinstance(self._dict2[k], str):
100
+ diff = self._diff_strings(self._dict1[k], self._dict2[k])
101
+ modified[k] = (self._dict1[k], self._dict2[k], diff)
102
+ elif isinstance(self._dict1[k], dict) and isinstance(
103
+ self._dict2[k], dict
104
+ ):
105
+ diff = self._diff_dicts(self._dict1[k], self._dict2[k])
106
+ modified[k] = (self._dict1[k], self._dict2[k], diff)
107
+ elif isinstance(self._dict1[k], list) and isinstance(
108
+ self._dict2[k], list
109
+ ):
110
+ d1 = dict(zip(range(len(self._dict1[k])), self._dict1[k]))
111
+ d2 = dict(zip(range(len(self._dict2[k])), self._dict2[k]))
112
+ diff = BaseDiff(
113
+ DummyObject(d1), DummyObject(d2), level=self.level + 1
114
+ )
115
+ modified[k] = (self._dict1[k], self._dict2[k], diff)
116
+ else:
117
+ modified[k] = (self._dict1[k], self._dict2[k], "")
118
+ return modified
119
+
120
+ @staticmethod
121
+ def is_json(string_that_could_be_json: str) -> bool:
122
+ try:
123
+ json.loads(string_that_could_be_json)
124
+ return True
125
+ except json.JSONDecodeError:
126
+ return False
127
+
128
+ def _diff_dicts(self, dict1: Dict[str, Any], dict2: Dict[str, Any]) -> str:
129
+ diff = BaseDiff(DummyObject(dict1), DummyObject(dict2), level=self.level + 1)
130
+ return diff
131
+
132
+ def _diff_strings(self, str1: str, str2: str) -> str:
133
+ if self.is_json(str1) and self.is_json(str2):
134
+ diff = self._diff_dicts(json.loads(str1), json.loads(str2))
135
+ return diff
136
+ diff = difflib.ndiff(str1.splitlines(), str2.splitlines())
137
+ return diff
138
+
139
+ def apply(self, obj: Any):
140
+ """Apply the diff to the object."""
141
+
142
+ new_obj_dict = obj._to_dict()
143
+ for k, v in self.added.items():
144
+ new_obj_dict[k] = v
145
+ for k in self.removed.keys():
146
+ del new_obj_dict[k]
147
+ for k, (v1, v2, diff) in self.modified.items():
148
+ new_obj_dict[k] = v2
149
+
150
+ return obj.from_dict(new_obj_dict)
151
+
152
+ def to_dict(self) -> Dict[str, Any]:
153
+ return {
154
+ "added": self.added,
155
+ "removed": self.removed,
156
+ "modified": self.modified,
157
+ "obj1": self._dict1,
158
+ "obj2": self._dict2,
159
+ "obj_class": self._obj_class.__name__,
160
+ "level": self.level,
161
+ }
162
+
163
+ @classmethod
164
+ def from_dict(cls, diff_dict: Dict[str, Any], obj1: Any, obj2: Any):
165
+ return cls(
166
+ obj1=obj1,
167
+ obj2=obj2,
168
+ added=diff_dict["added"],
169
+ removed=diff_dict["removed"],
170
+ modified=diff_dict["modified"],
171
+ level=diff_dict["level"],
172
+ )
173
+
174
+ class Results(UserList):
175
+ def __init__(self, prepend=" ", level=0):
176
+ super().__init__()
177
+ self.prepend = prepend
178
+ self.level = level
179
+
180
+ def append(self, item):
181
+ super().append(self.prepend * self.level + item)
182
+
183
+ def __str__(self):
184
+ prepend = " "
185
+ result = self.Results(level=self.level, prepend="\t")
186
+ if self.added:
187
+ result.append("Added keys and values:")
188
+ for k, v in self.added.items():
189
+ result.append(prepend + f" {k}: {v}")
190
+ if self.removed:
191
+ result.append("Removed keys and values:")
192
+ for k, v in self.removed.items():
193
+ result.append(f" {k}: {v}")
194
+ if self.modified:
195
+ result.append("Modified keys and values:")
196
+ for k, (v1, v2, diff) in self.modified.items():
197
+ result.append(f"Key: {k}:")
198
+ result.append(f" Old value: {v1}")
199
+ result.append(f" New value: {v2}")
200
+ if diff:
201
+ result.append(f" Diff:")
202
+ try:
203
+ for line in diff:
204
+ result.append(f" {line}")
205
+ except:
206
+ result.append(f" {diff}")
207
+ return "\n".join(result)
208
+
209
+ def __repr__(self):
210
+ return (
211
+ f"BaseDiff(obj1={self.obj1!r}, obj2={self.obj2!r}, added={self.added!r}, "
212
+ f"removed={self.removed!r}, modified={self.modified!r})"
213
+ )
214
+
215
+ def add_diff(self, diff) -> "BaseDiffCollection":
216
+ return BaseDiffCollection([self, diff])
217
+
218
+
219
+ if __name__ == "__main__":
220
+ from edsl import Question
221
+
222
+ q_ft = Question.example("free_text")
223
+ q_mc = Question.example("multiple_choice")
224
+
225
+ diff1 = q_ft - q_mc
226
+ assert q_ft == q_mc + diff1
227
+ assert q_ft == diff1.apply(q_mc)
228
+ # new_q_mc = diff1.apply(q_ft)
229
+ # assert new_q_mc == q_mc
230
+
231
+ # new_q_mc = q_ft + diff1
232
+ # assert new_q_mc == q_mc
233
+
234
+ # new_q_mc = diff1 + q_ft
235
+ # assert new_q_mc == q_mc
236
+
237
+ # ## Test chain of diffs
238
+ q0 = Question.example("free_text")
239
+ q1 = q0.copy()
240
+ q1.question_text = "Why is Buzzard's Bay so named?"
241
+ diff1 = q1 - q0
242
+ q2 = q1.copy()
243
+ q2.question_name = "buzzard_bay"
244
+ diff2 = q2 - q1
245
+
246
+ diff_chain = diff1.add_diff(diff2)
247
+
248
+ new_q2 = diff_chain.apply(q0)
249
+ assert new_q2 == q2
250
+
251
+ new_q2 = diff_chain + q0
252
+ assert new_q2 == q2
253
+
254
+ # new_diffs = diff1.add_diff(diff1).add_diff(diff1)
255
+ # assert len(new_diffs) == 3
256
+
257
+ # q0 = Question.example("free_text")
258
+ # q1 = Question.example("free_text")
259
+ # q1.question_text = "Why is Buzzard's Bay so named?"
260
+ # q2 = q1.copy()
@@ -35,4 +35,8 @@ from edsl.data.CacheEntry import CacheEntry
35
35
  from edsl.data.CacheHandler import set_session_cache, unset_session_cache
36
36
  from edsl.shared import shared_globals
37
37
  from edsl.jobs import Jobs
38
+ from edsl.notebooks import Notebook
39
+ from edsl.study.Study import Study
38
40
  from edsl.coop.coop import Coop
41
+ from edsl.conjure.Conjure import Conjure
42
+ from edsl.language_models.ModelList import ModelList
@@ -0,0 +1 @@
1
+ __version__ = "0.1.28"
@@ -98,7 +98,7 @@ class Agent(Base):
98
98
 
99
99
  >>> a = Agent(traits = {"age": 10}, traits_presentation_template = "I am a {{age}} year old.")
100
100
  >>> repr(a.agent_persona)
101
- "Prompt(text='I am a {{age}} year old.')"
101
+ 'Prompt(text=\"""I am a {{age}} year old.\""")'
102
102
 
103
103
  When this is rendered for presentation to the LLM, it will replace the `{{age}}` with the actual age.
104
104
  it is also possible to use the `codebook` to provide a more human-readable description of the trait.
@@ -109,7 +109,7 @@ class Agent(Base):
109
109
  >>> a = Agent(traits = traits, codebook = codebook, traits_presentation_template = "This agent is Dave. {{codebook['age']}} {{age}}")
110
110
  >>> d = a.traits | {'codebook': a.codebook}
111
111
  >>> a.agent_persona.render(d)
112
- Prompt(text='This agent is Dave. Their age is 10')
112
+ Prompt(text=\"""This agent is Dave. Their age is 10\""")
113
113
 
114
114
  Instructions
115
115
  ------------
@@ -198,6 +198,18 @@ class Agent(Base):
198
198
  else:
199
199
  return self._traits
200
200
 
201
+ def rename(self, old_name: str, new_name: str) -> Agent:
202
+ """Rename a trait.
203
+
204
+ Example usage:
205
+
206
+ >>> a = Agent(traits = {"age": 10, "hair": "brown", "height": 5.5})
207
+ >>> a.rename("age", "years") == Agent(traits = {'years': 10, 'hair': 'brown', 'height': 5.5})
208
+ True
209
+ """
210
+ self.traits[new_name] = self.traits.pop(old_name)
211
+ return self
212
+
201
213
  def __getitem__(self, key):
202
214
  """Allow for accessing traits using the bracket notation.
203
215
 
@@ -327,7 +339,7 @@ class Agent(Base):
327
339
  >>> from edsl import QuestionFreeText
328
340
  >>> q = QuestionFreeText.example()
329
341
  >>> a.answer_question(question = q, cache = False)
330
- {'answer': 'I am a direct answer.', 'comment': 'This is a real survey response from a human.', 'question_name': 'how_are_you', 'prompts': {'user_prompt': Prompt(text='NA'), 'system_prompt': Prompt(text='NA')}, 'usage': {'prompt_tokens': 0, 'completion_tokens': 0}, 'cached_response': None, 'raw_model_response': None, 'simple_model_raw_response': None}
342
+ {'answer': 'I am a direct answer.', 'comment': 'This is a real survey response from a human.', ...}
331
343
 
332
344
  This is a function where an agent returns an answer to a particular question.
333
345
  However, there are several different ways an agent can answer a question, so the
@@ -547,6 +559,15 @@ class Agent(Base):
547
559
 
548
560
  return raw_data
549
561
 
562
+ def __hash__(self) -> int:
563
+ from edsl.utilities.utilities import dict_hash
564
+
565
+ return dict_hash(self._to_dict())
566
+
567
+ def _to_dict(self) -> dict[str, Union[dict, bool]]:
568
+ """Serialize to a dictionary."""
569
+ return self.data
570
+
550
571
  @add_edsl_version
551
572
  def to_dict(self) -> dict[str, Union[dict, bool]]:
552
573
  """Serialize to a dictionary.
@@ -557,7 +578,7 @@ class Agent(Base):
557
578
  >>> a.to_dict()
558
579
  {'name': 'Steve', 'traits': {'age': 10, 'hair': 'brown', 'height': 5.5}, 'edsl_version': '...', 'edsl_class_name': 'Agent'}
559
580
  """
560
- return self.data
581
+ return self._to_dict()
561
582
 
562
583
  @classmethod
563
584
  @remove_edsl_version
@@ -567,7 +588,7 @@ class Agent(Base):
567
588
  Example usage:
568
589
 
569
590
  >>> Agent.from_dict({'name': "Steve", 'traits': {'age': 10, 'hair': 'brown', 'height': 5.5}})
570
- Agent(name = 'Steve', traits = {'age': 10, 'hair': 'brown', 'height': 5.5})
591
+ Agent(name = \"""Steve\""", traits = {'age': 10, 'hair': 'brown', 'height': 5.5})
571
592
 
572
593
  """
573
594
  return cls(**agent_dict)