codefix-env 0.2.1__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.
- codefix_env/__init__.py +80 -0
- codefix_env/cli.py +83 -0
- codefix_env/client.py +194 -0
- codefix_env/env.py +503 -0
- codefix_env/models.py +234 -0
- codefix_env/rewards.py +157 -0
- codefix_env/tasks/__init__.py +75 -0
- codefix_env/tasks/easy.py +244 -0
- codefix_env/tasks/hard.py +430 -0
- codefix_env/tasks/medium.py +342 -0
- codefix_env/utils/__init__.py +33 -0
- codefix_env/utils/metrics.py +165 -0
- codefix_env/utils/reward_model.py +79 -0
- codefix_env/utils/sandbox.py +392 -0
- codefix_env-0.2.1.dist-info/METADATA +663 -0
- codefix_env-0.2.1.dist-info/RECORD +20 -0
- codefix_env-0.2.1.dist-info/WHEEL +5 -0
- codefix_env-0.2.1.dist-info/entry_points.txt +2 -0
- codefix_env-0.2.1.dist-info/licenses/LICENSE +201 -0
- codefix_env-0.2.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codefix-env
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: A high-performance PyTorch-based RL environment for automated code debugging and LLM agent evaluation
|
|
5
|
+
Author-email: Shailendra Dhakad <dhakarshailendra829@gmail.com>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright [yyyy] [name of copyright owner]
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
|
207
|
+
|
|
208
|
+
Project-URL: Homepage, https://github.com/dhakarshailendra829/codefix-env
|
|
209
|
+
Project-URL: Repository, https://github.com/dhakarshailendra829/codefix-env
|
|
210
|
+
Project-URL: Issues, https://github.com/dhakarshailendra829/codefix-env/issues
|
|
211
|
+
Keywords: reinforcement-learning,pytorch,llm,code-debugging,gymnasium,openenv,rl-environment,genai
|
|
212
|
+
Classifier: Development Status :: 3 - Alpha
|
|
213
|
+
Classifier: Intended Audience :: Developers
|
|
214
|
+
Classifier: Intended Audience :: Science/Research
|
|
215
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
216
|
+
Classifier: Programming Language :: Python :: 3
|
|
217
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
218
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
219
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
220
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
221
|
+
Requires-Python: >=3.10
|
|
222
|
+
Description-Content-Type: text/markdown
|
|
223
|
+
License-File: LICENSE
|
|
224
|
+
Requires-Dist: fastapi>=0.110.0
|
|
225
|
+
Requires-Dist: uvicorn[standard]>=0.29.0
|
|
226
|
+
Requires-Dist: pydantic>=2.6.0
|
|
227
|
+
Requires-Dist: httpx>=0.27.0
|
|
228
|
+
Requires-Dist: websockets>=12.0
|
|
229
|
+
Requires-Dist: torch>=2.2.0
|
|
230
|
+
Requires-Dist: numpy>=1.26.0
|
|
231
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
232
|
+
Requires-Dist: structlog>=24.1.0
|
|
233
|
+
Requires-Dist: rich>=13.7.0
|
|
234
|
+
Requires-Dist: typer>=0.12.0
|
|
235
|
+
Provides-Extra: dev
|
|
236
|
+
Requires-Dist: pytest>=8.1.0; extra == "dev"
|
|
237
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
238
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
239
|
+
Requires-Dist: pytest-timeout>=2.3.0; extra == "dev"
|
|
240
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
241
|
+
Requires-Dist: black>=24.3.0; extra == "dev"
|
|
242
|
+
Requires-Dist: isort>=5.13.0; extra == "dev"
|
|
243
|
+
Requires-Dist: mypy>=1.9.0; extra == "dev"
|
|
244
|
+
Requires-Dist: pre-commit>=3.7.0; extra == "dev"
|
|
245
|
+
Provides-Extra: llm
|
|
246
|
+
Requires-Dist: transformers>=4.40.0; extra == "llm"
|
|
247
|
+
Requires-Dist: trl>=0.8.6; extra == "llm"
|
|
248
|
+
Requires-Dist: accelerate>=0.29.0; extra == "llm"
|
|
249
|
+
Requires-Dist: datasets>=2.19.0; extra == "llm"
|
|
250
|
+
Requires-Dist: sentencepiece>=0.2.0; extra == "llm"
|
|
251
|
+
Provides-Extra: all
|
|
252
|
+
Requires-Dist: pytest>=8.1.0; extra == "all"
|
|
253
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "all"
|
|
254
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "all"
|
|
255
|
+
Requires-Dist: pytest-timeout>=2.3.0; extra == "all"
|
|
256
|
+
Requires-Dist: ruff>=0.4.0; extra == "all"
|
|
257
|
+
Requires-Dist: black>=24.3.0; extra == "all"
|
|
258
|
+
Requires-Dist: isort>=5.13.0; extra == "all"
|
|
259
|
+
Requires-Dist: mypy>=1.9.0; extra == "all"
|
|
260
|
+
Requires-Dist: pre-commit>=3.7.0; extra == "all"
|
|
261
|
+
Requires-Dist: transformers>=4.40.0; extra == "all"
|
|
262
|
+
Requires-Dist: trl>=0.8.6; extra == "all"
|
|
263
|
+
Requires-Dist: accelerate>=0.29.0; extra == "all"
|
|
264
|
+
Requires-Dist: datasets>=2.19.0; extra == "all"
|
|
265
|
+
Requires-Dist: sentencepiece>=0.2.0; extra == "all"
|
|
266
|
+
Dynamic: license-file
|
|
267
|
+
|
|
268
|
+
<div align="center">
|
|
269
|
+
|
|
270
|
+
# CodeFix-Env
|
|
271
|
+
|
|
272
|
+
**A reinforcement learning environment for training LLM-driven agents to autonomously debug, localize, and repair code through sandboxed execution and feedback-driven learning.**
|
|
273
|
+
|
|
274
|
+
<p align="center">
|
|
275
|
+
<strong>Built for scalable agent evaluation on real-world software debugging tasks.</strong>
|
|
276
|
+
</p>
|
|
277
|
+
|
|
278
|
+
<p align="center">
|
|
279
|
+
<!-- Red -->
|
|
280
|
+
<a href="https://pytorch.org/">
|
|
281
|
+
<img src="https://img.shields.io/badge/PyTorch-EE4C2C?style=for-the-badge&logo=pytorch&logoColor=white" alt="PyTorch">
|
|
282
|
+
</a>
|
|
283
|
+
|
|
284
|
+
<!-- Orange -->
|
|
285
|
+
<a href="https://vllm.ai/">
|
|
286
|
+
<img src="https://img.shields.io/badge/vLLM-F97316?style=for-the-badge&logo=fastapi&logoColor=white" alt="vLLM">
|
|
287
|
+
</a>
|
|
288
|
+
|
|
289
|
+
<!-- Yellow -->
|
|
290
|
+
<a href="https://huggingface.co/">
|
|
291
|
+
<img src="https://img.shields.io/badge/HuggingFace-FFD21E?style=for-the-badge&logo=huggingface&logoColor=black" alt="HuggingFace">
|
|
292
|
+
</a>
|
|
293
|
+
|
|
294
|
+
<!-- Green -->
|
|
295
|
+
<a href="https://fastapi.tiangolo.com/">
|
|
296
|
+
<img src="https://img.shields.io/badge/FastAPI-009688?style=for-the-badge&logo=fastapi&logoColor=white" alt="FastAPI">
|
|
297
|
+
</a>
|
|
298
|
+
|
|
299
|
+
<!-- Blue -->
|
|
300
|
+
<a href="https://www.docker.com/">
|
|
301
|
+
<img src="https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=docker&logoColor=white" alt="Docker">
|
|
302
|
+
</a>
|
|
303
|
+
|
|
304
|
+
<!-- Indigo -->
|
|
305
|
+
<a href="https://github.com/">
|
|
306
|
+
<img src="https://img.shields.io/badge/CI/CD-181717?style=for-the-badge&logo=githubactions&logoColor=white" alt="CI/CD">
|
|
307
|
+
</a>
|
|
308
|
+
|
|
309
|
+
<!-- Violet -->
|
|
310
|
+
<a href="https://ollama.com/">
|
|
311
|
+
<img src="https://img.shields.io/badge/Ollama-7C3AED?style=for-the-badge&logo=llama&logoColor=white" alt="Ollama">
|
|
312
|
+
</a>
|
|
313
|
+
</p>
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
<p align="center">
|
|
317
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/Python-3.10%2B-3776ab?style=flat-square&logo=python&logoColor=white"></a>
|
|
318
|
+
<a href="https://pytorch.org/"><img src="https://img.shields.io/badge/PyTorch-2.2%2B-ee4c2c?style=flat-square&logo=pytorch&logoColor=white"></a>
|
|
319
|
+
<a href="https://fastapi.tiangolo.com/"><img src="https://img.shields.io/badge/FastAPI-0.110%2B-009688?style=flat-square&logo=fastapi&logoColor=white"></a>
|
|
320
|
+
<a href="https://gymnasium.farama.org/"><img src="https://img.shields.io/badge/Gymnasium-Compatible-4B8BBE?style=flat-square"></a>
|
|
321
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-green?style=flat-square"></a>
|
|
322
|
+
<a href="tests/"><img src="https://img.shields.io/badge/Tests-197%2F197%20Passing-brightgreen?style=flat-square"></a>
|
|
323
|
+
<a href="https://github.com/dhakarshailendra829/codefix-env"><img src="https://img.shields.io/github/stars/dhakarshailendra829/codefix-env?style=flat-square"></a>
|
|
324
|
+
</p>
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
### 📖 Overview
|
|
329
|
+
|
|
330
|
+
CodeFix-Env is a **Gymnasium-compatible RL environment** that simulates real-world Python code debugging workflows. It enables researchers and engineers to:
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
| Goal | Description |
|
|
334
|
+
| :--- | :--- |
|
|
335
|
+
| **Train** | Large language models (LLMs) on code repair tasks. |
|
|
336
|
+
| **Evaluate** | AI agents on real debugging scenarios. |
|
|
337
|
+
| **Benchmark** | Code generation and reasoning capabilities. |
|
|
338
|
+
| **Build** | Automated debugging systems. |
|
|
339
|
+
|
|
340
|
+
**Compatible with:** Qwen, Llama, CodeLlama, DeepSeek, and other leading LLMs.
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
</div>
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
### 🔴 The Challenge
|
|
349
|
+
Training Large Language Models (LLMs) for code generation and autonomous repair requires more than static data. Effective learning requires:
|
|
350
|
+
|
|
351
|
+
* **Authentic Scenarios:** Moving beyond synthetic examples to real-world debugging.
|
|
352
|
+
* **Tight Feedback Loops:** Providing immediate test results and error logs.
|
|
353
|
+
* **Measurable Progress:** Quantifiable metrics based on test pass rates.
|
|
354
|
+
* **Secure Execution:** Sandboxed environments to prevent unsafe code execution.
|
|
355
|
+
|
|
356
|
+
### 🟢 The Solution: CodeFix-Env
|
|
357
|
+
CodeFix-Env is a specialized environment designed for RL agents and LLMs to master code repair through:
|
|
358
|
+
|
|
359
|
+
* **Real-World Tasks:** 21 curated Python bugs ranging from logic errors to complex edge cases.
|
|
360
|
+
* **Test-Driven Feedback:** Agents receive granular execution data after every action.
|
|
361
|
+
* **Multi-Factor Rewards:** Reward signals based on test progress, code quality, and task completion.
|
|
362
|
+
* **Isolated Execution:** Built-in sandboxing with timeout protection for safe evaluations.
|
|
363
|
+
* **Structured Interaction:** Clean API for structured actions that LLMs can reliably generate.
|
|
364
|
+
|
|
365
|
+
### Workflow
|
|
366
|
+
```mermaid
|
|
367
|
+
graph TD
|
|
368
|
+
A[Agent receives buggy code] --> B[Analyze code & test failures]
|
|
369
|
+
B --> C[Generate action: e.g., edit_line]
|
|
370
|
+
C --> D[Environment executes action]
|
|
371
|
+
D --> E[Environment provides feedback]
|
|
372
|
+
|
|
373
|
+
subgraph Feedback Loop
|
|
374
|
+
E --> F[Test results & pass/fail counts]
|
|
375
|
+
E --> G[Code diff & change analysis]
|
|
376
|
+
E --> H[Shaped reward signals]
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
F & G & H --> I{Solution found?}
|
|
380
|
+
I -- No --> B
|
|
381
|
+
I -- Yes --> J[Task Complete]
|
|
382
|
+
```
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## Key Features
|
|
386
|
+
|
|
387
|
+
** Task Library**
|
|
388
|
+
- 21 carefully designed debugging tasks
|
|
389
|
+
- 3 difficulty levels: Easy (8), Medium (8), Hard (5)
|
|
390
|
+
- Each task includes buggy code, solution, test cases, and hints
|
|
391
|
+
- Covers real Python patterns: loops, recursion, algorithms, decorators
|
|
392
|
+
|
|
393
|
+
** LLM Integration**
|
|
394
|
+
- Works with HuggingFace Transformers ecosystem
|
|
395
|
+
- Compatible with training frameworks: SFT, DPO, GRPO, PPO
|
|
396
|
+
- Pre-built support for Qwen, Llama, CodeLlama, DeepSeek models
|
|
397
|
+
- Structured JSON action interface for LLM control
|
|
398
|
+
|
|
399
|
+
** Performance**
|
|
400
|
+
- Multiprocessing-based sandbox with timeout enforcement
|
|
401
|
+
- Per-test execution isolation
|
|
402
|
+
- 197 unit tests with 83% code coverage
|
|
403
|
+
- Automated CI/CD pipeline (Python 3.10, 3.11, 3.12)
|
|
404
|
+
|
|
405
|
+
** Developer Friendly**
|
|
406
|
+
- Gymnasium standard interface
|
|
407
|
+
- Async client for high-performance training
|
|
408
|
+
- Sync wrapper for notebooks
|
|
409
|
+
- FastAPI HTTP server for remote access
|
|
410
|
+
- Complete type hints and documentation
|
|
411
|
+
|
|
412
|
+
---
|
|
413
|
+
|
|
414
|
+
## Installation
|
|
415
|
+
|
|
416
|
+
### Step 1: Clone Repository
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
git clone https://github.com/dhakarshailendra829/codefix-env.git
|
|
420
|
+
cd codefix-env
|
|
421
|
+
```
|
|
422
|
+
### Step 2: Create virual Environment
|
|
423
|
+
```bash
|
|
424
|
+
python3.11 -m venv .venv
|
|
425
|
+
source .venv/bin/activate (On mac)
|
|
426
|
+
.venv/Scripts/activate (On Windows)
|
|
427
|
+
```
|
|
428
|
+
### Step 3: Intall Package
|
|
429
|
+
#### For Basic Usage
|
|
430
|
+
```bash
|
|
431
|
+
pip install -e .
|
|
432
|
+
```
|
|
433
|
+
---
|
|
434
|
+
#### For Developement
|
|
435
|
+
```bash
|
|
436
|
+
pip install -e ".[dev]"
|
|
437
|
+
```
|
|
438
|
+
---
|
|
439
|
+
#### For LLM training (includes transformers, TRL, datasets)
|
|
440
|
+
```bash
|
|
441
|
+
pip install -e ".[llm]"
|
|
442
|
+
```
|
|
443
|
+
---
|
|
444
|
+
#### For everything
|
|
445
|
+
```bash
|
|
446
|
+
pip install -e ".[dev,llm]"
|
|
447
|
+
```
|
|
448
|
+
### Step 4: Verify Installation
|
|
449
|
+
```bash
|
|
450
|
+
python -c "from codefix_env import CodeFixEnvironment; print(' Installation successful!')"
|
|
451
|
+
```
|
|
452
|
+
---
|
|
453
|
+
## Usage & Development Guide
|
|
454
|
+
|
|
455
|
+
### 1. Basic Environment Usage
|
|
456
|
+
```python
|
|
457
|
+
python << 'EOF'
|
|
458
|
+
from codefix_env import CodeFixEnvironment, CodeFixAction, ActionType
|
|
459
|
+
|
|
460
|
+
# Create environment
|
|
461
|
+
env = CodeFixEnvironment()
|
|
462
|
+
|
|
463
|
+
# Start episode with random easy task
|
|
464
|
+
obs = env.reset(difficulty="easy")
|
|
465
|
+
print(f"Task: {obs.task_id}")
|
|
466
|
+
print(f"Current Code:\n{obs.current_code}")
|
|
467
|
+
|
|
468
|
+
# Run tests to see failures
|
|
469
|
+
action = CodeFixAction(action_type=ActionType.RUN_TESTS)
|
|
470
|
+
result = env.step(action)
|
|
471
|
+
print(f"\nTest Results: {result.observation.tests_passed}/{result.observation.tests_total} passing")
|
|
472
|
+
print(f"Output:\n{result.observation.test_output}")
|
|
473
|
+
|
|
474
|
+
print(f"\nReward: {result.reward:.3f}")
|
|
475
|
+
print(f"Episode Done: {result.done}")
|
|
476
|
+
EOF
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### 2. Testing & Quality Assurance
|
|
480
|
+
To run the full suite:
|
|
481
|
+
```bash
|
|
482
|
+
cd codefix-env
|
|
483
|
+
PYTHONPATH=src pytest tests/ -v --timeout=60
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
To run specific Test Suite
|
|
487
|
+
```bash
|
|
488
|
+
PYTHONPATH=src pytest tests/test_tasks.py::TestSolutionCorrectness -v
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
To check code standards:
|
|
492
|
+
```bash
|
|
493
|
+
ruff check src/ tests/ examples/
|
|
494
|
+
black --check src/ tests/ examples/
|
|
495
|
+
mypy src/codefix_env/ --ignore-missing-imports
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### 3. API Server Deployment
|
|
499
|
+
```bash
|
|
500
|
+
cd codefix-env
|
|
501
|
+
uvicorn src.codefix_env.server.app:app --reload --port 8000
|
|
502
|
+
```
|
|
503
|
+
---
|
|
504
|
+
## Usage Examples
|
|
505
|
+
|
|
506
|
+
### 1. Core Debugging Workflow
|
|
507
|
+
A complete cycle from task initialization to final submission.
|
|
508
|
+
|
|
509
|
+
```python
|
|
510
|
+
from codefix_env import CodeFixEnvironment, CodeFixAction, ActionType
|
|
511
|
+
|
|
512
|
+
env = CodeFixEnvironment()
|
|
513
|
+
obs = env.reset(task_id="easy-001-missing-return")
|
|
514
|
+
|
|
515
|
+
# 1. Run tests to identify failures
|
|
516
|
+
result = env.step(CodeFixAction(action_type=ActionType.RUN_TESTS))
|
|
517
|
+
print(f"Tests: {result.observation.tests_passed}/{result.observation.tests_total} passing")
|
|
518
|
+
|
|
519
|
+
# 2. Apply a targeted fix
|
|
520
|
+
result = env.step(CodeFixAction(
|
|
521
|
+
action_type=ActionType.EDIT_LINE,
|
|
522
|
+
line_number=3,
|
|
523
|
+
new_content=" return result"
|
|
524
|
+
))
|
|
525
|
+
|
|
526
|
+
# 3. Final Verification & Submission
|
|
527
|
+
result = env.step(CodeFixAction(action_type=ActionType.SUBMIT_FIX))
|
|
528
|
+
print(f"Status: {'Solved' if result.observation.all_tests_pass else 'Failed'}")
|
|
529
|
+
print(f"Final Reward: {result.reward:.3f}")
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### 2. High-Level Task Management
|
|
533
|
+
Programmatically interact with the task database.
|
|
534
|
+
|
|
535
|
+
```python
|
|
536
|
+
from codefix_env import list_tasks, Difficulty, task_count
|
|
537
|
+
|
|
538
|
+
# Get environment stats
|
|
539
|
+
print(f"Total tasks by difficulty: {task_count()}")
|
|
540
|
+
|
|
541
|
+
# Bulk process specific difficulty levels
|
|
542
|
+
easy_tasks = list_tasks(difficulty=Difficulty.EASY)
|
|
543
|
+
for task in easy_tasks[:5]:
|
|
544
|
+
print(f"Loading {task.id}: {task.title}")
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
---
|
|
548
|
+
|
|
549
|
+
## LLM Training & Integration
|
|
550
|
+
|
|
551
|
+
### Server-Client Architecture
|
|
552
|
+
Deploy the environment as a service to scale LLM evaluations across multiple agents.
|
|
553
|
+
|
|
554
|
+
```bash
|
|
555
|
+
# Start the API server
|
|
556
|
+
uvicorn src.codefix_env.server.app:app --port 8000
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
### Building Training Datasets
|
|
560
|
+
Export environment states into `.jsonl` formats for fine-tuning models like Llama or Qwen.
|
|
561
|
+
|
|
562
|
+
```python
|
|
563
|
+
import json
|
|
564
|
+
from codefix_env import CodeFixClient
|
|
565
|
+
|
|
566
|
+
async def collect_trajectories():
|
|
567
|
+
async with CodeFixClient("http://localhost:8000") as client:
|
|
568
|
+
obs = await client.reset(difficulty="medium")
|
|
569
|
+
dataset_entry = {
|
|
570
|
+
"instruction": f"Fix the following code: {obs.current_code}",
|
|
571
|
+
"context": obs.test_output,
|
|
572
|
+
"metadata": {"task_id": obs.task_id}
|
|
573
|
+
}
|
|
574
|
+
# Append to training_data.jsonl....
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Zero-Shot Inference (HuggingFace)
|
|
578
|
+
Connect an LLM directly to the environment loop.
|
|
579
|
+
|
|
580
|
+
```python
|
|
581
|
+
from transformers import pipeline
|
|
582
|
+
from codefix_env import CodeFixEnvironment
|
|
583
|
+
|
|
584
|
+
# Load a coding model
|
|
585
|
+
fixer = pipeline("text-generation", model="Qwen/Qwen2.5-Coder-7B")
|
|
586
|
+
|
|
587
|
+
env = CodeFixEnvironment()
|
|
588
|
+
obs = env.reset(difficulty="easy")
|
|
589
|
+
|
|
590
|
+
# Generate a fix based on environment observation
|
|
591
|
+
prompt = f"Fix this Python code based on these errors: {obs.test_output}\nCode:\n{obs.current_code}"
|
|
592
|
+
suggestion = fixer(prompt)
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
---
|
|
596
|
+
|
|
597
|
+
## API Quick Reference
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
| Class / Method | Description |
|
|
601
|
+
| :--- | :--- |
|
|
602
|
+
| `CodeFixEnvironment` | Local execution engine for debugging tasks. |
|
|
603
|
+
| `CodeFixClient` | Async client for interacting with a remote server. |
|
|
604
|
+
| `env.step(action)` | Executes an `ActionType` (EDIT, RUN_TESTS, SUBMIT). |
|
|
605
|
+
| `Difficulty` | Enum: `EASY`, `MEDIUM`, `HARD`. |
|
|
606
|
+
| `BugCategory` | Categories: `SYNTAX`, `LOGIC`, `DATA_STRUCTURE`, `ALGORITHM`. |
|
|
607
|
+
|
|
608
|
+
---
|
|
609
|
+
|
|
610
|
+
## Development & CI/CD
|
|
611
|
+
Standard commands for maintaining the environment.
|
|
612
|
+
|
|
613
|
+
```bash
|
|
614
|
+
# Run full test suite with coverage
|
|
615
|
+
pytest tests/ -v --cov=src/codefix_env
|
|
616
|
+
|
|
617
|
+
# Static Analysis
|
|
618
|
+
ruff check src/ # Linting
|
|
619
|
+
black --check src/ # Formatting
|
|
620
|
+
mypy src/ # Type Checking
|
|
621
|
+
```
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
<div align="center">
|
|
625
|
+
|
|
626
|
+
# LLM Ecosystem & Infrastructure
|
|
627
|
+
|
|
628
|
+
### LLM Models
|
|
629
|
+
|
|
630
|
+
| Model | Description |
|
|
631
|
+
| :--- | :--- |
|
|
632
|
+
| 🟢 **Qwen 1.5B, 7B, 14B** | Alibaba's instruction models |
|
|
633
|
+
| 🟢 **Llama 2-7B-Chat** | Meta's foundation model |
|
|
634
|
+
| 🟢 **CodeLlama 7B, 13B, 34B** | Specialized for code |
|
|
635
|
+
| 🟢 **DeepSeek Coder 1.3B, 6.7B** | Chinese LLM for code |
|
|
636
|
+
| 🟢 **Mistral 7B** | Open-source efficient model |
|
|
637
|
+
|
|
638
|
+
<br/>
|
|
639
|
+
|
|
640
|
+
### ⚙️ Training Frameworks
|
|
641
|
+
|
|
642
|
+
| Framework | Method |
|
|
643
|
+
| :--- | :--- |
|
|
644
|
+
| 🟢 **SFT** | Supervised fine-tuning |
|
|
645
|
+
| 🟢 **DPO** | Direct preference optimization |
|
|
646
|
+
| 🟢 **GRPO** | Group relative policy optimization |
|
|
647
|
+
| 🟢 **PPO** | Proximal policy optimization |
|
|
648
|
+
|
|
649
|
+
<br/>
|
|
650
|
+
|
|
651
|
+
### 🏗️ Infrastructure
|
|
652
|
+
|
|
653
|
+
| Tool | Purpose |
|
|
654
|
+
| :--- | :--- |
|
|
655
|
+
| 🟢 **HuggingFace** | Model hub & training |
|
|
656
|
+
| 🟢 **vLLM** | Fast LLM serving |
|
|
657
|
+
| 🟢 **Ollama** | Local model deployment |
|
|
658
|
+
| 🟢 **Docker** | Containerization |
|
|
659
|
+
| 🟢 **GitHub Actions** | CI/CD |
|
|
660
|
+
|
|
661
|
+
</div>
|
|
662
|
+
---
|
|
663
|
+
## Note:- This is pure backend system not frontend, we are working on frontent very soon we will update.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
codefix_env/__init__.py,sha256=bQ1z10gnK6Gd1qELWUv2GslphoMflBJ0OeVc2tYIc-g,2335
|
|
2
|
+
codefix_env/cli.py,sha256=g0NFigNUP-BDNdsD61f9u9GAAGK3Q_Om4tkrRiw6QdA,2582
|
|
3
|
+
codefix_env/client.py,sha256=FOZ99LATSnM6KOfHBj-zXgrSDZJ8kaYof1GzG21KUBc,6850
|
|
4
|
+
codefix_env/env.py,sha256=NTPO1x1yon46hwznZSWb2wfdaj_boR-JOUhmY5VjNMY,18138
|
|
5
|
+
codefix_env/models.py,sha256=gEwvmd1EZzLFv3JAVtyrvpUYE_rpJoorJAtZB2hyPbs,7690
|
|
6
|
+
codefix_env/rewards.py,sha256=qsWoHTvWuE0wFHP1Ay-ey8qC3e-dCW5E8n3TMnTwz9k,5442
|
|
7
|
+
codefix_env/tasks/__init__.py,sha256=O7ZXfOOLqU7IQpsV1jSu3-6I7SB70wIbq87tHzNrPZA,2184
|
|
8
|
+
codefix_env/tasks/easy.py,sha256=NSWjz-jSfejMeq6uFVt8Ze3EcOG5chohDZcI7Rc5O7I,9392
|
|
9
|
+
codefix_env/tasks/hard.py,sha256=hZZCJQVcyK2KyLXB9H_019rM93xFtlP96lxmBO1Q5FE,12963
|
|
10
|
+
codefix_env/tasks/medium.py,sha256=lc0pb2l206Zo1QfqnEkwzutpuwGqm5_TgXgbqbJWkYg,12549
|
|
11
|
+
codefix_env/utils/__init__.py,sha256=T__yHZSirXUByiFJNC08RNtFY-xZEvdzH2XCNVwyG_o,927
|
|
12
|
+
codefix_env/utils/metrics.py,sha256=cmtXBfIwMQcTIQz5AlpUOkONvZyf9Y9yTDTe-nkkM88,5056
|
|
13
|
+
codefix_env/utils/reward_model.py,sha256=ayCMwYDfAOvDKKLvAmY2DmonUzavlxEjqdx_QVIo5LI,2280
|
|
14
|
+
codefix_env/utils/sandbox.py,sha256=ZB2MmIqBIy8tMEomB4SDv89t988sJzerhhpxwGNnsaE,11132
|
|
15
|
+
codefix_env-0.2.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
16
|
+
codefix_env-0.2.1.dist-info/METADATA,sha256=Q9MRQD6o1qTV7rhhfQBIvDDxlOk_uc0bOMycFNnXnnE,27953
|
|
17
|
+
codefix_env-0.2.1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
18
|
+
codefix_env-0.2.1.dist-info/entry_points.txt,sha256=Ery7S8tmzlASeB-r4lFm0Rl8uAmMZe5Petlv5nRCGq4,55
|
|
19
|
+
codefix_env-0.2.1.dist-info/top_level.txt,sha256=e1bmZ_ie2-V3TVMtJfvwXO8lXGYCRJpZ-D-1aCKmNCk,12
|
|
20
|
+
codefix_env-0.2.1.dist-info/RECORD,,
|