synth-ai 0.1.0.dev39__py3-none-any.whl → 0.1.0.dev49__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 (69) hide show
  1. synth_ai/__init__.py +3 -1
  2. {synth_ai-0.1.0.dev39.dist-info → synth_ai-0.1.0.dev49.dist-info}/METADATA +12 -11
  3. synth_ai-0.1.0.dev49.dist-info/RECORD +6 -0
  4. {synth_ai-0.1.0.dev39.dist-info → synth_ai-0.1.0.dev49.dist-info}/WHEEL +1 -1
  5. synth_ai-0.1.0.dev49.dist-info/top_level.txt +1 -0
  6. private_tests/try_synth_sdk.py +0 -1
  7. public_tests/test_agent.py +0 -538
  8. public_tests/test_all_structured_outputs.py +0 -196
  9. public_tests/test_anthropic_structured_outputs.py +0 -0
  10. public_tests/test_deepseek_structured_outputs.py +0 -0
  11. public_tests/test_deepseek_tools.py +0 -64
  12. public_tests/test_gemini_output.py +0 -188
  13. public_tests/test_gemini_structured_outputs.py +0 -106
  14. public_tests/test_models.py +0 -183
  15. public_tests/test_openai_structured_outputs.py +0 -106
  16. public_tests/test_reasoning_effort.py +0 -75
  17. public_tests/test_reasoning_models.py +0 -92
  18. public_tests/test_recursive_structured_outputs.py +0 -180
  19. public_tests/test_structured.py +0 -137
  20. public_tests/test_structured_outputs.py +0 -109
  21. public_tests/test_synth_sdk.py +0 -384
  22. public_tests/test_text.py +0 -160
  23. public_tests/test_tools.py +0 -319
  24. synth_ai/zyk/__init__.py +0 -3
  25. synth_ai/zyk/lms/__init__.py +0 -0
  26. synth_ai/zyk/lms/caching/__init__.py +0 -0
  27. synth_ai/zyk/lms/caching/constants.py +0 -1
  28. synth_ai/zyk/lms/caching/dbs.py +0 -0
  29. synth_ai/zyk/lms/caching/ephemeral.py +0 -72
  30. synth_ai/zyk/lms/caching/handler.py +0 -142
  31. synth_ai/zyk/lms/caching/initialize.py +0 -13
  32. synth_ai/zyk/lms/caching/persistent.py +0 -83
  33. synth_ai/zyk/lms/config.py +0 -8
  34. synth_ai/zyk/lms/core/__init__.py +0 -0
  35. synth_ai/zyk/lms/core/all.py +0 -47
  36. synth_ai/zyk/lms/core/exceptions.py +0 -9
  37. synth_ai/zyk/lms/core/main.py +0 -314
  38. synth_ai/zyk/lms/core/vendor_clients.py +0 -85
  39. synth_ai/zyk/lms/cost/__init__.py +0 -0
  40. synth_ai/zyk/lms/cost/monitor.py +0 -1
  41. synth_ai/zyk/lms/cost/statefulness.py +0 -1
  42. synth_ai/zyk/lms/structured_outputs/__init__.py +0 -0
  43. synth_ai/zyk/lms/structured_outputs/handler.py +0 -442
  44. synth_ai/zyk/lms/structured_outputs/inject.py +0 -314
  45. synth_ai/zyk/lms/structured_outputs/rehabilitate.py +0 -187
  46. synth_ai/zyk/lms/tools/base.py +0 -104
  47. synth_ai/zyk/lms/vendors/__init__.py +0 -0
  48. synth_ai/zyk/lms/vendors/base.py +0 -31
  49. synth_ai/zyk/lms/vendors/constants.py +0 -22
  50. synth_ai/zyk/lms/vendors/core/__init__.py +0 -0
  51. synth_ai/zyk/lms/vendors/core/anthropic_api.py +0 -413
  52. synth_ai/zyk/lms/vendors/core/gemini_api.py +0 -306
  53. synth_ai/zyk/lms/vendors/core/mistral_api.py +0 -327
  54. synth_ai/zyk/lms/vendors/core/openai_api.py +0 -185
  55. synth_ai/zyk/lms/vendors/local/__init__.py +0 -0
  56. synth_ai/zyk/lms/vendors/local/ollama.py +0 -0
  57. synth_ai/zyk/lms/vendors/openai_standard.py +0 -374
  58. synth_ai/zyk/lms/vendors/retries.py +0 -3
  59. synth_ai/zyk/lms/vendors/supported/__init__.py +0 -0
  60. synth_ai/zyk/lms/vendors/supported/deepseek.py +0 -73
  61. synth_ai/zyk/lms/vendors/supported/groq.py +0 -16
  62. synth_ai/zyk/lms/vendors/supported/ollama.py +0 -14
  63. synth_ai/zyk/lms/vendors/supported/together.py +0 -11
  64. synth_ai-0.1.0.dev39.dist-info/RECORD +0 -67
  65. synth_ai-0.1.0.dev39.dist-info/top_level.txt +0 -4
  66. tests/test_agent.py +0 -538
  67. tests/test_recursive_structured_outputs.py +0 -180
  68. tests/test_structured_outputs.py +0 -100
  69. {synth_ai-0.1.0.dev39.dist-info → synth_ai-0.1.0.dev49.dist-info}/licenses/LICENSE +0 -0
synth_ai/__init__.py CHANGED
@@ -2,4 +2,6 @@
2
2
  Synth AI - Software for aiding the best and multiplying the will.
3
3
  """
4
4
 
5
- __version__ = "0.1.0.dev16" # Hardcode version matching pyproject.toml
5
+ from importlib.metadata import version
6
+
7
+ __version__ = version("synth-ai") # Gets version from installed package metadata
@@ -1,7 +1,8 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: synth-ai
3
- Version: 0.1.0.dev39
3
+ Version: 0.1.0.dev49
4
4
  Summary: Software for aiding the best and multiplying the will.
5
+ Home-page: https://github.com/synth-laboratories/synth-ai
5
6
  Author: Josh Purtell
6
7
  Author-email: Josh Purtell <josh@usesynth.ai>
7
8
  License: MIT License
@@ -34,22 +35,22 @@ Classifier: Programming Language :: Python :: 3
34
35
  Requires-Python: >=3.10
35
36
  Description-Content-Type: text/markdown
36
37
  License-File: LICENSE
37
- Requires-Dist: openai
38
- Requires-Dist: pydantic
39
- Requires-Dist: diskcache
38
+ Requires-Dist: openai>=1.0.0
39
+ Requires-Dist: pydantic>=2.0.0
40
+ Requires-Dist: diskcache>=5.0.0
40
41
  Requires-Dist: backoff>=2.2.1
41
42
  Requires-Dist: anthropic>=0.34.2
42
43
  Requires-Dist: google>=3.0.0
43
- Requires-Dist: google-generativeai>=0.8.1
44
+ Requires-Dist: google-api-core
45
+ Requires-Dist: google-generativeai
44
46
  Requires-Dist: together>=1.2.12
45
47
  Requires-Dist: langfuse>=2.56.1
46
- Requires-Dist: synth-sdk==0.3.1.dev5
47
48
  Requires-Dist: datasets>=3.2.0
48
49
  Requires-Dist: groq>=0.18.0
49
50
  Requires-Dist: pytest-timeout>=2.3.1
50
- Requires-Dist: lock>=2018.3.25.2110
51
- Requires-Dist: ollama>=0.4.7
52
- Requires-Dist: mistralai>=1.5.0
51
+ Requires-Dist: mistralai
52
+ Dynamic: author
53
+ Dynamic: home-page
53
54
  Dynamic: license-file
54
55
 
55
56
  AI Infra used by the Synth AI Team
@@ -62,4 +63,4 @@ AI Infra used by the Synth AI Team
62
63
  |_____/ \__, |_| |_|\__|_| |_| /_/ \_\_____|
63
64
  __/ |
64
65
  |___/
65
- ```
66
+ ```
@@ -0,0 +1,6 @@
1
+ synth_ai/__init__.py,sha256=bf6Bd1RWGWHYrBUBvkQpqIyZhPFP_RmO49QftIKO92k,197
2
+ synth_ai-0.1.0.dev49.dist-info/licenses/LICENSE,sha256=ynhjRQUfqA_RdGRATApfFA_fBAy9cno04sLtLUqxVFM,1069
3
+ synth_ai-0.1.0.dev49.dist-info/METADATA,sha256=hu5NnTZCAsF1yOHU3Vta564QhNAgbpjdP63MlW9x4ck,2731
4
+ synth_ai-0.1.0.dev49.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
5
+ synth_ai-0.1.0.dev49.dist-info/top_level.txt,sha256=fBmtZyVHuKaGa29oHBaaUkrUIWTqSpoVMPiVdCDP3k8,9
6
+ synth_ai-0.1.0.dev49.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.7.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1 @@
1
+ synth_ai
@@ -1 +0,0 @@
1
- import synth_sdk.tracing
@@ -1,538 +0,0 @@
1
- import unittest
2
- from typing import List, Union
3
-
4
- from pydantic import BaseModel
5
-
6
- from synth_ai.zyk.lms.core.main import LM
7
-
8
-
9
- class UnitTestDict(BaseModel):
10
- test_description: str
11
- input_names: List[str]
12
- input_types: List[str]
13
- stringified_input_values: List[str]
14
- assertion_condition: str
15
- assertion_type: str # Consider using Literal for specific assertion types
16
-
17
-
18
- class ActionArgument(BaseModel):
19
- key: str
20
- value: Union[str, int, float, bool, UnitTestDict]
21
-
22
-
23
- class ReAct(BaseModel):
24
- reasoning: str
25
- action_name: str
26
- action_args: List[ActionArgument] # Dict#[str, Dict]
27
-
28
-
29
- system = """
30
- <System Message>
31
- # Premise
32
- You are a software engineer
33
- Here is some information about this setting
34
- <Setting Information>
35
- You are working to solve a computer science problem. You will need to submit a solution to the problem, which will be tested against a suite of hidden unit tests.
36
- </Setting Information>
37
- <Actions Available>
38
- <edit_submission>
39
- <action_context>
40
- Edit the submission code. Use this when you want to make changes to the current solution.
41
- </action_context>
42
- <action_arg_spec>
43
- {'first_line': <class 'int'>, 'last_line': <class 'int'>, 'new_code': <class 'str'>}
44
- </action_arg_spec>
45
- <action_description>
46
- Edit the submission code
47
- </action_description>
48
-
49
- </edit_submission>
50
- <add_submission>
51
- <action_context>
52
- Add the submission code. Use this when you want to start from scratch with a new solution.
53
- </action_context>
54
- <action_arg_spec>
55
- {'submission': <class 'str'>}
56
- </action_arg_spec>
57
- <action_description>
58
- Add the submission code
59
- </action_description>
60
-
61
- </add_submission>
62
- <add_unit_test>
63
- <action_context>
64
- Add a unit test. The unit test information you submit must be in the format of a BCBUnitTest:
65
-
66
- class BCBUnitTest(BaseModel):
67
- test_description: str
68
- input_names: List[str]
69
- input_types: List[str]
70
- input_values: List[Any]
71
- assertion_condition: str
72
- assertion_type: Literal["assertTrue", "assertRaises"] = "assertTrue"
73
-
74
-
75
- It will be parsed via BCBUnitTest(**unit_test_dict)
76
-
77
-
78
-
79
- # Some various notes:
80
- 1. If an input should be of a type defined by a specific package, add the package name/alias to the type. E.g. "np.ndarray" or "pd.DataFrame". You still should fully define the value for the input_value field e.g. "pd.DataFrame({'a': [1, 2, 3]})"
81
-
82
- 2. Unit tests will be compiled from the BCBUnitTest class as follows:
83
- A. For AssertTrue type tests, the test will be compiled as follows:
84
- ```python
85
- def test_case(self):
86
- # {{self.test_description}}
87
-
88
- {{defs}}
89
- result = {{function_name}}(**{{{{args}}}}})
90
- self.{{self.assertion_type}}({{self.assertion_condition}})
91
- ```
92
- B. For AssertRaises type tests, the test will be compiled as follows:
93
-
94
- ```python
95
- def test_case(self):
96
- # {{self.test_description}}
97
- {{defs}}
98
- with self.{{self.assertion_type}}({{self.assertion_condition}}):
99
- {{function_name}}(**{{{{args}}}}})
100
- ```
101
-
102
- Provide information accordingly.
103
-
104
- </action_context>
105
- <action_arg_spec>
106
- {'unit_test_name': <class 'str'>, 'unit_test_dict': typing.Dict}
107
- </action_arg_spec>
108
- <action_description>
109
- Add a unit test
110
- </action_description>
111
-
112
- </add_unit_test>
113
- <remove_unit_test>
114
- <action_context>
115
- Remove a unit test
116
- </action_context>
117
- <action_arg_spec>
118
- {'unit_test_name': <class 'str'>}
119
- </action_arg_spec>
120
- <action_description>
121
- Remove a unit test
122
- </action_description>
123
-
124
- </remove_unit_test>
125
- <test_submission>
126
- <action_context>
127
- Test the submission
128
- </action_context>
129
- <action_arg_spec>
130
- {}
131
- </action_arg_spec>
132
- <action_description>
133
- Test the submission
134
- </action_description>
135
-
136
- </test_submission>
137
- <submit_solution>
138
- <action_context>
139
- Submit the solution
140
- </action_context>
141
- <action_arg_spec>
142
- {}
143
- </action_arg_spec>
144
- <action_description>
145
- Submit the solution
146
- </action_description>
147
-
148
- </submit_solution>
149
-
150
- </Actions Available>
151
- You'll be given your past actions/thoughts, along with recent raw observations from the environment
152
- The environment one step in the past is your current environment.
153
-
154
- # Objective
155
- Please complete the problem by drafting a solution, creating unit tests, improving the solution, and submitting the solution.
156
-
157
- # Constraints
158
- You will be given a code_prompt_for_answer, which contains imports and the function signature. Your solution must comprise code that can be appended to code_prompt_for_answer and run as a single script.
159
-
160
- """
161
-
162
- user = """
163
- <User Message>
164
- # Recent Actions / Thoughts
165
-
166
- # Recent Observations
167
- <1 environment step(s) in the past>{'action_result': None, 'environment_state': {'question': 'import pandas as pd\nimport numpy as np\n\n# Constants\nCOLUMNS = [\'column1\', \'column2\', \'column3\', \'column4\', \'column5\']\n\ndef task_func(df, dct):\n '''\n Replace certain values in a DataFrame with a dictionary mapping and calculate the Pearson correlation coefficient between each pair of columns.\n\n Parameters:\n df (DataFrame): The input DataFrame, containing numeric or categorical data.\n dct (dict): A dictionary for replacing values in df, where keys are existing values and values are new values.\n\n Returns:\n DataFrame: A DataFrame with the correlation coefficients between each pair of columns. The format of the DataFrame is a square matrix with column and index labels matching the columns of the input DataFrame.\n \n Requirements:\n - pandas\n - numpy\n \n Note:\n - This function operates on DataFrames containing numeric or categorical data that can be replaced with numeric values, as correlation calculations require numeric data.\n - This function using pearson method to calculate the correlation matrix.\n \n Raises:\n - This function will raise a ValueError is input df is not a DataFrame.\n \n Example:\n >>> df = pd.DataFrame({\'A\': [1, 2, 3], \'B\': [4, 5, 6]})\n >>> dct = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}\n >>> correlation_matrix = task_func(df, dct)\n >>> correlation_matrix.shape == (2, 2)\n True\n >>> np.allclose(correlation_matrix, np.array([[1.0, 1.0], [1.0, 1.0]]))\n True\n '''\n', 'code_prompt_for_answer': "import pandas as pd\nimport numpy as np\n# Constants\nCOLUMNS = ['column1', 'column2', 'column3', 'column4', 'column5']\ndef task_func(df, dct):\n", 'unit_tests_you_have_written': {}, 'current_solution': ''}}</1 environment step(s) in the past>
168
-
169
- Your next actions / thought:
170
- """
171
-
172
-
173
- ###
174
-
175
- hard_system = """
176
- # Premise
177
- You are a software engineer
178
- Here is some information about this setting
179
- <Setting Information>
180
- You are working to solve a computer science problem. You will need to submit a solution to the problem, which will be tested against a suite of hidden unit tests.
181
- </Setting Information>
182
- <Actions Available>
183
- <edit_submission>
184
- <action_context>
185
- Edit the submission code. Use this when you want to make changes to the current solution.
186
- </action_context>
187
- <action_arg_spec>
188
- {'first_line': <class 'int'>, 'last_line': <class 'int'>, 'new_code': <class 'str'>}
189
- </action_arg_spec>
190
- <action_description>
191
- Edit the submission code
192
- </action_description>
193
-
194
- </edit_submission>
195
- <add_submission>
196
- <action_context>
197
- Add the submission code. Use this when you want to start from scratch with a new solution.
198
- </action_context>
199
- <action_arg_spec>
200
- {'submission': <class 'str'>}
201
- </action_arg_spec>
202
- <action_description>
203
- Add the submission code
204
- </action_description>
205
-
206
- </add_submission>
207
- <add_unit_test>
208
- <action_context>
209
- Add a unit test. The unit test information you submit must be in the format of a BCBUnitTest:
210
-
211
- class BCBUnitTest(BaseModel):
212
- test_description: str
213
- input_names: List[str]
214
- input_types: List[str]
215
- input_values: List[Any]
216
- assertion_condition: str
217
- assertion_type: Literal["assertTrue", "assertRaises"] = "assertTrue"
218
-
219
-
220
- It will be parsed via BCBUnitTest(**unit_test_dict)
221
-
222
-
223
-
224
- # Some various notes:
225
- 1. If an input should be of a type defined by a specific package, add the package name/alias to the type. E.g. "np.ndarray" or "pd.DataFrame". You still should fully define the value for the input_value field e.g. "pd.DataFrame({'a': [1, 2, 3]})"
226
-
227
- 2. Unit tests will be compiled from the BCBUnitTest class as follows:
228
- A. For AssertTrue type tests, the test will be compiled as follows:
229
- ```python
230
- def test_case(self):
231
- # {{self.test_description}}
232
-
233
- {{defs}}
234
- result = {{function_name}}(**{{{{args}}}}})
235
- self.{{self.assertion_type}}({{self.assertion_condition}})
236
- ```
237
- B. For AssertRaises type tests, the test will be compiled as follows:
238
-
239
- ```python
240
- def test_case(self):
241
- # {{self.test_description}}
242
- {{defs}}
243
- with self.{{self.assertion_type}}({{self.assertion_condition}}):
244
- {{function_name}}(**{{{{args}}}}})
245
- ```
246
-
247
- Provide information accordingly.
248
-
249
- </action_context>
250
- <action_arg_spec>
251
- {'unit_test_name': <class 'str'>, 'unit_test_dict': typing.Dict}
252
- </action_arg_spec>
253
- <action_description>
254
- Add a unit test
255
- </action_description>
256
-
257
- </add_unit_test>
258
- <remove_unit_test>
259
- <action_context>
260
- Remove a unit test
261
- </action_context>
262
- <action_arg_spec>
263
- {'unit_test_name': <class 'str'>}
264
- </action_arg_spec>
265
- <action_description>
266
- Remove a unit test
267
- </action_description>
268
-
269
- </remove_unit_test>
270
- <test_submission>
271
- <action_context>
272
- Test the submission
273
- </action_context>
274
- <action_arg_spec>
275
- {}
276
- </action_arg_spec>
277
- <action_description>
278
- Test the submission
279
- </action_description>
280
-
281
- </test_submission>
282
- <submit_solution>
283
- <action_context>
284
- Submit the solution
285
- </action_context>
286
- <action_arg_spec>
287
- {}
288
- </action_arg_spec>
289
- <action_description>
290
- Submit the solution
291
- </action_description>
292
-
293
- </submit_solution>
294
-
295
- </Actions Available>
296
- You'll be given your past actions/thoughts, along with recent raw observations from the environment
297
- The environment one step in the past is your current environment.
298
-
299
- # Objective
300
- Please complete the problem by drafting a solution, creating unit tests, improving the solution, and submitting the solution.
301
-
302
- # Constraints
303
- You will be given a code_prompt_for_answer, which contains imports and the function signature. Your solution must comprise code that can be appended to code_prompt_for_answer and run as a single script.
304
-
305
-
306
- <User Message>
307
- # Recent Actions / Thoughts
308
-
309
- # Recent Observations
310
- <1 environment step(s) in the past>{'action_result': None, 'environment_state': {'question': 'import pandas as pd\nimport numpy as np\n\n# Constants\nCOLUMNS = [\'column1\', \'column2\', \'column3\', \'column4\', \'column5\']\n\ndef task_func(df, dct):\n '''\n Replace certain values in a DataFrame with a dictionary mapping and calculate the Pearson correlation coefficient between each pair of columns.\n\n Parameters:\n df (DataFrame): The input DataFrame, containing numeric or categorical data.\n dct (dict): A dictionary for replacing values in df, where keys are existing values and values are new values.\n\n Returns:\n DataFrame: A DataFrame with the correlation coefficients between each pair of columns. The format of the DataFrame is a square matrix with column and index labels matching the columns of the input DataFrame.\n \n Requirements:\n - pandas\n - numpy\n \n Note:\n - This function operates on DataFrames containing numeric or categorical data that can be replaced with numeric values, as correlation calculations require numeric data.\n - This function using pearson method to calculate the correlation matrix.\n \n Raises:\n - This function will raise a ValueError is input df is not a DataFrame.\n \n Example:\n >>> df = pd.DataFrame({\'A\': [1, 2, 3], \'B\': [4, 5, 6]})\n >>> dct = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}\n >>> correlation_matrix = task_func(df, dct)\n >>> correlation_matrix.shape == (2, 2)\n True\n >>> np.allclose(correlation_matrix, np.array([[1.0, 1.0], [1.0, 1.0]]))\n True\n '''\n', 'code_prompt_for_answer': "import pandas as pd\nimport numpy as np\n# Constants\nCOLUMNS = ['column1', 'column2', 'column3', 'column4', 'column5']\ndef task_func(df, dct):\n", 'unit_tests_you_have_written': {}, 'current_solution': ''}}</1 environment step(s) in the past>
311
-
312
- Your next actions / thought:
313
-
314
- Structured output: reasoning="I need to implement the function 'task_func' that replaces values in a DataFrame based on a dictionary and calculates the Pearson correlation coefficient between each pair of columns. I will also ensure to handle the case where the input is not a DataFrame by raising a ValueError." action_name='edit_submission' action_args=[ActionArgument(key='first_line', value=4), ActionArgument(key='last_line', value=4), ActionArgument(key='new_code', value=" if not isinstance(df, pd.DataFrame):\n raise ValueError('Input must be a DataFrame')\n df.replace(dct, inplace=True)\n return df.corr(method='pearson')")]
315
- <System Message>
316
- # Premise
317
- You are a software engineer
318
- Here is some information about this setting
319
- <Setting Information>
320
- You are working to solve a computer science problem. You will need to submit a solution to the problem, which will be tested against a suite of hidden unit tests.
321
- </Setting Information>
322
- <Actions Available>
323
- <edit_submission>
324
- <action_context>
325
- Edit the submission code. Use this when you want to make changes to the current solution.
326
- </action_context>
327
- <action_arg_spec>
328
- {'first_line': <class 'int'>, 'last_line': <class 'int'>, 'new_code': <class 'str'>}
329
- </action_arg_spec>
330
- <action_description>
331
- Edit the submission code
332
- </action_description>
333
-
334
- </edit_submission>
335
- <add_submission>
336
- <action_context>
337
- Add the submission code. Use this when you want to start from scratch with a new solution.
338
- </action_context>
339
- <action_arg_spec>
340
- {'submission': <class 'str'>}
341
- </action_arg_spec>
342
- <action_description>
343
- Add the submission code
344
- </action_description>
345
-
346
- </add_submission>
347
- <add_unit_test>
348
- <action_context>
349
- Add a unit test. The unit test information you submit must be in the format of a BCBUnitTest:
350
-
351
- class BCBUnitTest(BaseModel):
352
- test_description: str
353
- input_names: List[str]
354
- input_types: List[str]
355
- input_values: List[Any]
356
- assertion_condition: str
357
- assertion_type: Literal["assertTrue", "assertRaises"] = "assertTrue"
358
-
359
-
360
- It will be parsed via BCBUnitTest(**unit_test_dict)
361
-
362
-
363
-
364
- # Some various notes:
365
- 1. If an input should be of a type defined by a specific package, add the package name/alias to the type. E.g. "np.ndarray" or "pd.DataFrame". You still should fully define the value for the input_value field e.g. "pd.DataFrame({'a': [1, 2, 3]})"
366
-
367
- 2. Unit tests will be compiled from the BCBUnitTest class as follows:
368
- A. For AssertTrue type tests, the test will be compiled as follows:
369
- ```python
370
- def test_case(self):
371
- # {{self.test_description}}
372
-
373
- {{defs}}
374
- result = {{function_name}}(**{{{{args}}}}})
375
- self.{{self.assertion_type}}({{self.assertion_condition}})
376
- ```
377
- B. For AssertRaises type tests, the test will be compiled as follows:
378
-
379
- ```python
380
- def test_case(self):
381
- # {{self.test_description}}
382
- {{defs}}
383
- with self.{{self.assertion_type}}({{self.assertion_condition}}):
384
- {{function_name}}(**{{{{args}}}}})
385
- ```
386
-
387
- Provide information accordingly.
388
-
389
- </action_context>
390
- <action_arg_spec>
391
- {'unit_test_name': <class 'str'>, 'unit_test_dict': typing.Dict}
392
- </action_arg_spec>
393
- <action_description>
394
- Add a unit test
395
- </action_description>
396
-
397
- </add_unit_test>
398
- <remove_unit_test>
399
- <action_context>
400
- Remove a unit test
401
- </action_context>
402
- <action_arg_spec>
403
- {'unit_test_name': <class 'str'>}
404
- </action_arg_spec>
405
- <action_description>
406
- Remove a unit test
407
- </action_description>
408
-
409
- </remove_unit_test>
410
- <test_submission>
411
- <action_context>
412
- Test the submission
413
- </action_context>
414
- <action_arg_spec>
415
- {}
416
- </action_arg_spec>
417
- <action_description>
418
- Test the submission
419
- </action_description>
420
-
421
- </test_submission>
422
- <submit_solution>
423
- <action_context>
424
- Submit the solution
425
- </action_context>
426
- <action_arg_spec>
427
- {}
428
- </action_arg_spec>
429
- <action_description>
430
- Submit the solution
431
- </action_description>
432
-
433
- </submit_solution>
434
-
435
- </Actions Available>
436
- You'll be given your past actions/thoughts, along with recent raw observations from the environment
437
- The environment one step in the past is your current environment.
438
-
439
- # Objective
440
- Please complete the problem by drafting a solution, creating unit tests, improving the solution, and submitting the solution.
441
-
442
- # Constraints
443
- You will be given a code_prompt_for_answer, which contains imports and the function signature. Your solution must comprise code that can be appended to code_prompt_for_answer and run as a single script.
444
- """
445
-
446
- hard_user = """
447
- # Recent Actions / Thoughts
448
- <1 reasoning step(s) in the past>reasoning="I need to implement the function 'task_func' that replaces values in a DataFrame based on a dictionary and calculates the Pearson correlation coefficient between the columns. I will also ensure to handle the case where the input is not a DataFrame by raising a ValueError." action_name='edit_submission' action_args=[ActionArgument(key='first_line', value=4), ActionArgument(key='last_line', value=4), ActionArgument(key='new_code', value=" if not isinstance(df, pd.DataFrame):\n raise ValueError('Input must be a DataFrame')\n df.replace(dct, inplace=True)\n return df.corr(method='pearson')")]</1 reasoning step(s) in the past>
449
- # Recent Observations
450
- <1 environment step(s) in the past>success=True result='Edited submission successfully'</1 environment step(s) in the past>
451
- <2 environment step(s) in the past>{'action_result': None, 'environment_state': {'question': 'import pandas as pd\nimport numpy as np\n\n# Constants\nCOLUMNS = [\'column1\', \'column2\', \'column3\', \'column4\', \'column5\']\n\ndef task_func(df, dct):\n '''\n Replace certain values in a DataFrame with a dictionary mapping and calculate the Pearson correlation coefficient between each pair of columns.\n\n Parameters:\n df (DataFrame): The input DataFrame, containing numeric or categorical data.\n dct (dict): A dictionary for replacing values in df, where keys are existing values and values are new values.\n\n Returns:\n DataFrame: A DataFrame with the correlation coefficients between each pair of columns. The format of the DataFrame is a square matrix with column and index labels matching the columns of the input DataFrame.\n \n Requirements:\n - pandas\n - numpy\n \n Note:\n - This function operates on DataFrames containing numeric or categorical data that can be replaced with numeric values, as correlation calculations require numeric data.\n - This function using pearson method to calculate the correlation matrix.\n \n Raises:\n - This function will raise a ValueError is input df is not a DataFrame.\n \n Example:\n >>> df = pd.DataFrame({\'A\': [1, 2, 3], \'B\': [4, 5, 6]})\n >>> dct = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}\n >>> correlation_matrix = task_func(df, dct)\n >>> correlation_matrix.shape == (2, 2)\n True\n >>> np.allclose(correlation_matrix, np.array([[1.0, 1.0], [1.0, 1.0]]))\n True\n '''\n', 'code_prompt_for_answer': "import pandas as pd\nimport numpy as np\n# Constants\nCOLUMNS = ['column1', 'column2', 'column3', 'column4', 'column5']\ndef task_func(df, dct):\n", 'unit_tests_you_have_written': {}, 'current_solution': ''}}</2 environment step(s) in the past>
452
-
453
- Your next actions / thought:
454
- """
455
-
456
-
457
- class TestLMStructuredOutputs(unittest.TestCase):
458
- # ... existing code ...
459
-
460
- @classmethod
461
- def setUpClass(cls):
462
- # Initialize LMs for both forced_json and stringified_json modes
463
- cls.lm_forced_json = LM(
464
- model_name="gpt-4o-mini",
465
- formatting_model_name="gpt-4o-mini",
466
- temperature=0.0,
467
- max_retries="Few",
468
- structured_output_mode="forced_json",
469
- )
470
- cls.lm_stringified_json = LM(
471
- model_name="gpt-4o-mini",
472
- formatting_model_name="gpt-4o-mini",
473
- temperature=0.0,
474
- max_retries="Few",
475
- structured_output_mode="stringified_json",
476
- )
477
-
478
- def test_sync_react_response_content(self):
479
- system_message = system
480
-
481
- user_message = user
482
-
483
- for lm in [self.lm_forced_json, self.lm_stringified_json]:
484
- with self.subTest(
485
- mode=lm.structured_output_handler.handler.structured_output_mode
486
- ):
487
- result = lm.respond_sync(
488
- system_message=system_message,
489
- user_message=user_message,
490
- response_model=ReAct,
491
- )
492
- self.assertIsInstance(result.structured_output, ReAct)
493
- self.assertIsInstance(result.structured_output.reasoning, str)
494
- self.assertIsInstance(result.structured_output.action_name, str)
495
- self.assertIsInstance(result.structured_output.action_args, list)
496
- for arg in result.structured_output.action_args:
497
- self.assertIsInstance(arg, ActionArgument)
498
- self.assertIsInstance(arg.key, str)
499
- # self.assertIsInstance(arg.value, str)
500
-
501
- def test_sync_react_response_hard_content(self):
502
- system_message = hard_system
503
-
504
- user_message = hard_user
505
-
506
- for lm in [self.lm_forced_json, self.lm_stringified_json]:
507
- with self.subTest(
508
- mode=lm.structured_output_handler.handler.structured_output_mode
509
- ):
510
- result = lm.respond_sync(
511
- system_message=system_message,
512
- user_message=user_message,
513
- response_model=ReAct,
514
- )
515
- self.assertIsInstance(result.structured_output, ReAct)
516
- self.assertIsInstance(result.structured_output.reasoning, str)
517
- self.assertIsInstance(result.structured_output.action_name, str)
518
- self.assertIsInstance(result.structured_output.action_args, list)
519
- for arg in result.structured_output.action_args:
520
- self.assertIsInstance(arg, ActionArgument)
521
- self.assertIsInstance(arg.key, str)
522
- # self.assertIsInstance(arg.value, str)
523
-
524
-
525
- # use non-trivial fallback?
526
-
527
- if __name__ == "__main__":
528
- # Create an instance of the test class
529
- test_instance = TestLMStructuredOutputs()
530
-
531
- # Set up the class (this would normally be done by unittest)
532
- test_instance.setUpClass()
533
-
534
- # Run the test methods
535
- test_instance.test_sync_react_response_content()
536
- test_instance.test_sync_react_response_hard_content()
537
-
538
- print("All tests completed.")