cldk 0.1.1__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.
- cldk-0.1.1/LICENSE +201 -0
- cldk-0.1.1/PKG-INFO +306 -0
- cldk-0.1.1/README.md +275 -0
- cldk-0.1.1/cldk/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/__init__.py +8 -0
- cldk-0.1.1/cldk/analysis/analysis_level.py +9 -0
- cldk-0.1.1/cldk/analysis/c/__init__.py +0 -0
- cldk-0.1.1/cldk/analysis/c/treesitter/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/c/treesitter/c_sitter.py +510 -0
- cldk-0.1.1/cldk/analysis/call_graph.py +69 -0
- cldk-0.1.1/cldk/analysis/go/__init__.py +0 -0
- cldk-0.1.1/cldk/analysis/go/treesitter/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/go/treesitter/go_sitter.py +451 -0
- cldk-0.1.1/cldk/analysis/java/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/java/codeanalyzer/__init__.py +9 -0
- cldk-0.1.1/cldk/analysis/java/codeanalyzer/bin/.gitignore +1 -0
- cldk-0.1.1/cldk/analysis/java/codeanalyzer/bin/__init__.py +0 -0
- cldk-0.1.1/cldk/analysis/java/codeanalyzer/codeanalyzer.py +927 -0
- cldk-0.1.1/cldk/analysis/java/codeanalyzer/jar/.gitignore +1 -0
- cldk-0.1.1/cldk/analysis/java/codeanalyzer/jar/__init__.py +0 -0
- cldk-0.1.1/cldk/analysis/java/codeanalyzer/jar/codeanalyzer.jar +0 -0
- cldk-0.1.1/cldk/analysis/java/codeql/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/java/codeql/backend.py +148 -0
- cldk-0.1.1/cldk/analysis/java/codeql/codeql.py +238 -0
- cldk-0.1.1/cldk/analysis/java/java.py +597 -0
- cldk-0.1.1/cldk/analysis/java/treesitter/__init__.py +2 -0
- cldk-0.1.1/cldk/analysis/java/treesitter/javasitter.py +444 -0
- cldk-0.1.1/cldk/analysis/javascript/__init__.py +0 -0
- cldk-0.1.1/cldk/analysis/javascript/treesitter/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/javascript/treesitter/javascript_sitter.py +457 -0
- cldk-0.1.1/cldk/analysis/program_dependence_graph.py +6 -0
- cldk-0.1.1/cldk/analysis/python/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/python/python.py +122 -0
- cldk-0.1.1/cldk/analysis/python/treesitter/__init__.py +3 -0
- cldk-0.1.1/cldk/analysis/python/treesitter/python_sitter.py +352 -0
- cldk-0.1.1/cldk/analysis/symbol_table.py +84 -0
- cldk-0.1.1/cldk/analysis/system_dependence_graph.py +6 -0
- cldk-0.1.1/cldk/core.py +149 -0
- cldk-0.1.1/cldk/models/__init__.py +0 -0
- cldk-0.1.1/cldk/models/c/__init__.py +0 -0
- cldk-0.1.1/cldk/models/c/models.py +111 -0
- cldk-0.1.1/cldk/models/go/__init__.py +0 -0
- cldk-0.1.1/cldk/models/go/models.py +101 -0
- cldk-0.1.1/cldk/models/java/__init__.py +18 -0
- cldk-0.1.1/cldk/models/java/constants_namespace.py +16 -0
- cldk-0.1.1/cldk/models/java/models.py +368 -0
- cldk-0.1.1/cldk/models/javascript/__init__.py +0 -0
- cldk-0.1.1/cldk/models/javascript/models.py +95 -0
- cldk-0.1.1/cldk/models/python/__init__.py +0 -0
- cldk-0.1.1/cldk/models/python/models.py +65 -0
- cldk-0.1.1/cldk/models/treesitter/__init__.py +3 -0
- cldk-0.1.1/cldk/models/treesitter/models.py +52 -0
- cldk-0.1.1/cldk/utils/__init__.py +0 -0
- cldk-0.1.1/cldk/utils/analysis_engine.py +4 -0
- cldk-0.1.1/cldk/utils/exceptions/__init__.py +13 -0
- cldk-0.1.1/cldk/utils/exceptions/exceptions.py +40 -0
- cldk-0.1.1/cldk/utils/logging.py +0 -0
- cldk-0.1.1/cldk/utils/sanitization/__init__.py +0 -0
- cldk-0.1.1/cldk/utils/sanitization/java/TreesitterSanitizer.py +323 -0
- cldk-0.1.1/cldk/utils/sanitization/java/TreesitterUtils.py +505 -0
- cldk-0.1.1/cldk/utils/sanitization/java/__init__.py +1 -0
- cldk-0.1.1/cldk/utils/treesitter/__init__.py +0 -0
- cldk-0.1.1/cldk/utils/treesitter/tree_sitter_utils.py +48 -0
- cldk-0.1.1/pyproject.toml +49 -0
cldk-0.1.1/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
cldk-0.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: cldk
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: codellm-devkit: A python library for seamless interation with LLMs.
|
|
5
|
+
License: Apache 2.0
|
|
6
|
+
Author: Rahul Krishna
|
|
7
|
+
Author-email: i.m.ralk@gmail.com
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Classifier: License :: Other/Proprietary License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Requires-Dist: ipdb (>=0.13.13,<0.14.0)
|
|
15
|
+
Requires-Dist: networkx (>=3.2.1,<4.0.0)
|
|
16
|
+
Requires-Dist: pandas (>=2.2.0,<3.0.0)
|
|
17
|
+
Requires-Dist: pyarrow (>=15.0.0,<16.0.0)
|
|
18
|
+
Requires-Dist: pydantic (>=2.6.1,<3.0.0)
|
|
19
|
+
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
20
|
+
Requires-Dist: rich (>=13.7.1,<14.0.0)
|
|
21
|
+
Requires-Dist: tree-sitter (>=0.22.3,<0.23.0)
|
|
22
|
+
Requires-Dist: tree-sitter-c (>=0.21.0,<0.22.0)
|
|
23
|
+
Requires-Dist: tree-sitter-go (>=0.21.0,<0.22.0)
|
|
24
|
+
Requires-Dist: tree-sitter-java (>=0.21.0,<0.22.0)
|
|
25
|
+
Requires-Dist: tree-sitter-javascript (>=0.21.0,<0.22.0)
|
|
26
|
+
Requires-Dist: tree-sitter-languages (>=1.10.2,<2.0.0)
|
|
27
|
+
Requires-Dist: tree-sitter-python (==0.23.2)
|
|
28
|
+
Requires-Dist: wget (>=3.2,<4.0)
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# CodeLLM-Devkit: A Python library for seamless interaction with CodeLLMs
|
|
32
|
+
|
|
33
|
+

|
|
34
|
+
[](https://www.python.org/downloads/release/python-3110/)
|
|
35
|
+
|
|
36
|
+
Codellm-devkit (CLDK) is a multilingual program analysis framework that bridges the gap between traditional static analysis tools and Large Language Models (LLMs) specialized for code (CodeLLMs). Codellm-devkit allows developers to streamline the process of transforming raw code into actionable insights by providing a unified interface for integrating outputs from various analysis tools and preparing them for effective use by CodeLLMs.
|
|
37
|
+
|
|
38
|
+
Codellm-devkit simplifies the complex process of analyzing codebases that span multiple programming languages, making it easier to extract meaningful insights and drive LLM-based code analysis. `CLDK` achieves this through an open-source Python library that abstracts the intricacies of program analysis and LLM interactions. With this library, developer can streamline the process of transforming raw code into actionable insights by providing a unified interface for integrating outputs from various analysis tools and preparing them for effective use by CodeLLMs.
|
|
39
|
+
|
|
40
|
+
**The purpose of Codellm-devkit is to enable the development and experimentation of robust analysis pipelines that harness the power of both traditional program analysis tools and CodeLLMs.**
|
|
41
|
+
By providing a consistent and extensible framework, Codellm-devkit aims to reduce the friction associated with multi-language code analysis and ensure compatibility across different analysis tools and LLM platforms.
|
|
42
|
+
|
|
43
|
+
Codellm-devkit is designed to integrate seamlessly with a variety of popular analysis tools, such as WALA, Tree-sitter, LLVM, and CodeQL, each implemented in different languages. Codellm-devkit acts as a crucial intermediary layer, enabling efficient and consistent communication between these tools and the CodeLLMs.
|
|
44
|
+
|
|
45
|
+
Codellm-devkit is constantly evolving to include new tools and frameworks, ensuring it remains a versatile solution for code analysis and LLM integration.
|
|
46
|
+
|
|
47
|
+
Codellm-devkit is:
|
|
48
|
+
|
|
49
|
+
- **Unified**: Provides a single framework for integrating multiple analysis tools and CodeLLMs, regardless of the programming languages involved.
|
|
50
|
+
- **Extensible**: Designed to support new analysis tools and LLM platforms, making it adaptable to the evolving landscape of code analysis.
|
|
51
|
+
- **Streamlined**: Simplifies the process of transforming raw code into structured, LLM-ready inputs, reducing the overhead typically associated with multi-language analysis.
|
|
52
|
+
|
|
53
|
+
Codellm-devkit is an ongoing project, developed at IBM Research.
|
|
54
|
+
|
|
55
|
+
## Contact
|
|
56
|
+
|
|
57
|
+
For any questions, feedback, or suggestions, please contact the authors:
|
|
58
|
+
|
|
59
|
+
| Name | Email |
|
|
60
|
+
| ---- | ----- |
|
|
61
|
+
| Rahul Krishna | [i.m.ralk@gmail.com](mailto:i.m.ralk@gmail.com) |
|
|
62
|
+
| Rangeet Pan | [rangeet.pan@ibm.com](mailto:rangeet.pan@gmail.com) |
|
|
63
|
+
| Saurabh Sihna | [sinhas@us.ibm.com](mailto:sinhas@us.ibm.com) |
|
|
64
|
+
## Table of Contents
|
|
65
|
+
|
|
66
|
+
- [CodeLLM-Devkit: A Python library for seamless interaction with CodeLLMs](#codellm-devkit-a-python-library-for-seamless-interaction-with-codellms)
|
|
67
|
+
- [Contact](#contact)
|
|
68
|
+
- [Table of Contents](#table-of-contents)
|
|
69
|
+
- [Architectural and Design Overview](#architectural-and-design-overview)
|
|
70
|
+
- [Quick Start: Example Walkthrough](#quick-start-example-walkthrough)
|
|
71
|
+
- [Prerequisites](#prerequisites)
|
|
72
|
+
- [Step 1: Set up an Ollama server](#step-1--set-up-an-ollama-server)
|
|
73
|
+
- [Pull the latest version of Granite 8b instruct model from ollama](#pull-the-latest-version-of-granite-8b-instruct-model-from-ollama)
|
|
74
|
+
- [Step 2: Install CLDK](#step-2--install-cldk)
|
|
75
|
+
- [Step 3: Build a code summarization pipeline](#step-3--build-a-code-summarization-pipeline)
|
|
76
|
+
|
|
77
|
+
## Architectural and Design Overview
|
|
78
|
+
|
|
79
|
+
Below is a very high-level overview of the architectural of CLDK:
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
```mermaid
|
|
83
|
+
graph TD
|
|
84
|
+
User <--> A[CLDK]
|
|
85
|
+
A --> 15[Retrieval ‡]
|
|
86
|
+
A --> 16[Prompting ‡]
|
|
87
|
+
A[CLDK] <--> B[Languages]
|
|
88
|
+
B --> C[Java, Python, Go ‡, C ‡, JavaScript ‡, TypeScript ‡, Rust ‡]
|
|
89
|
+
C --> D[Data Models]
|
|
90
|
+
D --> 13{Pydantic}
|
|
91
|
+
13 --> 7
|
|
92
|
+
C --> 7{backends}
|
|
93
|
+
7 <--> 9[WALA]
|
|
94
|
+
9 <--> 14[Analysis]
|
|
95
|
+
7 <--> 10[Tree-sitter]
|
|
96
|
+
10 <--> 14[Analysis]
|
|
97
|
+
7 <--> 11[LLVM ‡]
|
|
98
|
+
11 <--> 14[Analysis]
|
|
99
|
+
7 <--> 12[CodeQL ‡]
|
|
100
|
+
12 <--> 14[Analysis]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
X[‡ Yet to be implemented]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The user interacts by invoking the CLDK API. The CLDK API is responsible for handling the user requests and delegating them to the appropriate language-specific modules.
|
|
108
|
+
|
|
109
|
+
Each language comprises of two key components: data models and backends.
|
|
110
|
+
|
|
111
|
+
1. **Data Models:** These are high level abstractions that represent the various language constructs and componentes in a structured format using pydantic. This confers a high degree of flexibility and extensibility to the models as well as allowing for easy accees of various data components via a simple dot notation. In addition, the data models are designed to be easily serializable and deserializable, making it easy to store and retrieve data from various sources.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
2. **Analysis Backends:** These are the components that are responsible for interfacing with the various program analysis tools. The core backends are Treesitter, Javaparse, WALA, LLVM, and CodeQL. The backends are responsible for handling the user requests and delegating them to the appropriate analysis tools. The analysis tools perfrom the requisite analysis and return the results to the user. The user merely calls one of several high-level API functions such as `get_method_body`, `get_method_signature`, `get_call_graph`, etc. and the backend takes care of the rest.
|
|
115
|
+
|
|
116
|
+
Some langugages may have multiple backends. For example, Java has WALA, Javaparser, Treesitter, and CodeQL backends. The user has freedom to choose the backend that best suits their needs.
|
|
117
|
+
|
|
118
|
+
We are currently working on implementing the retrieval and prompting components. The retrieval component will be responsible for retrieving the relevant code snippets from the codebase for RAG usecases. The prompting component will be responsible for generating the prompts for the CodeLLMs using popular prompting frameworks such as `PDL`, `Guidance`, or `LMQL`.
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Quick Start: Example Walkthrough
|
|
122
|
+
|
|
123
|
+
In this section, we will walk through a simple example to demonstrate how to use CLDK. We will:
|
|
124
|
+
|
|
125
|
+
* Set up a local ollama server to interact with CodeLLMs
|
|
126
|
+
* Build a simple code summarization pipeline for a Java and a Python application.
|
|
127
|
+
|
|
128
|
+
### Prerequisites
|
|
129
|
+
|
|
130
|
+
Before we begin, make sure you have the following prerequisites installed:
|
|
131
|
+
|
|
132
|
+
* Python 3.11 or later
|
|
133
|
+
* Ollama v0.3.4 or later
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
### Step 1: Set up an Ollama server
|
|
137
|
+
|
|
138
|
+
If don't already have ollama, please download and install it from here: [Ollama](https://ollama.com/download).
|
|
139
|
+
|
|
140
|
+
Once you have ollama, start the server and make sure it is running.
|
|
141
|
+
|
|
142
|
+
If you're on MacOS, Linux, or WSL, you can check to make sure the server is running by running the following command:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
sudo systemctl status ollama
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
You should see an output similar to the following:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
➜ sudo systemctl status ollama
|
|
152
|
+
● ollama.service - Ollama Service
|
|
153
|
+
Loaded: loaded (/etc/systemd/system/ollama.service; enabled; preset: enabled)
|
|
154
|
+
Active: active (running) since Sat 2024-08-10 20:39:56 EDT; 17s ago
|
|
155
|
+
Main PID: 23069 (ollama)
|
|
156
|
+
Tasks: 19 (limit: 76802)
|
|
157
|
+
Memory: 1.2G (peak: 1.2G)
|
|
158
|
+
CPU: 6.745s
|
|
159
|
+
CGroup: /system.slice/ollama.service
|
|
160
|
+
└─23069 /usr/local/bin/ollama serve
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
If not, you may have to start the server manually. You can do this by running the following command:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
sudo systemctl start ollama
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Pull the latest version of Granite 8b instruct model from ollama
|
|
170
|
+
|
|
171
|
+
To pull the latest version of the Granite 8b instruct model from ollama, run the following command:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
ollama pull granite-code:8b-instruct
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Check to make sure the model was successfully pulled by running the following command:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
ollama run granite-code:8b-instruct 'Write a function to print hello world in python'
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
The output should be similar to the following:
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
➜ ollama run granite-code:8b-instruct 'Write a function to print hello world in python'
|
|
187
|
+
|
|
188
|
+
def say_hello():
|
|
189
|
+
print("Hello World!")
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Step 2: Install CLDK
|
|
193
|
+
|
|
194
|
+
You may install the latest version of CLDK from our GitHub repository:
|
|
195
|
+
|
|
196
|
+
```python
|
|
197
|
+
pip install git+https://github.com/IBM/codellm-devkit.git
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Once CLDK is installed, you can import it into your Python code:
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from cldk import CLDK
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Step 3: Build a code summarization pipeline
|
|
207
|
+
|
|
208
|
+
Now that we have set up the ollama server and installed CLDK, we can build a simple code summarization pipeline for a Java application.
|
|
209
|
+
|
|
210
|
+
1. Let's download a sample Java (apache-commons-cli):
|
|
211
|
+
|
|
212
|
+
* Download and unzip the sample Java application:
|
|
213
|
+
```bash
|
|
214
|
+
wget https://github.com/apache/commons-cli/archive/refs/tags/rel/commons-cli-1.7.0.zip -O commons-cli-1.7.0.zip && unzip commons-cli-1.7.0.zip
|
|
215
|
+
```
|
|
216
|
+
* Record the path to the sample Java application:
|
|
217
|
+
```bash
|
|
218
|
+
export JAVA_APP_PATH=/path/to/commons-cli-1.7.0
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
Below is a simple code summarization pipeline for a Java application using CLDK. It does the following things:
|
|
223
|
+
|
|
224
|
+
* Creates a new instance of the CLDK class (see comment `# (1)`)
|
|
225
|
+
* Creates an analysis object over the Java application (see comment `# (2)`)
|
|
226
|
+
* Iterates over all the files in the project (see comment `# (3)`)
|
|
227
|
+
* Iterates over all the classes in the file (see comment `# (4)`)
|
|
228
|
+
* Iterates over all the methods in the class (see comment `# (5)`)
|
|
229
|
+
* Gets the code body of the method (see comment `# (6)`)
|
|
230
|
+
* Initializes the treesitter utils for the class file content (see comment `# (7)`)
|
|
231
|
+
* Sanitizes the class for analysis (see comment `# (8)`)
|
|
232
|
+
* Formats the instruction for the given focal method and class (see comment `# (9)`)
|
|
233
|
+
* Prompts the local model on Ollama (see comment `# (10)`)
|
|
234
|
+
* Prints the instruction and LLM output (see comment `# (11)`)
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
# code_summarization_for_java.py
|
|
238
|
+
|
|
239
|
+
from cldk import CLDK
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def format_inst(code, focal_method, focal_class):
|
|
243
|
+
"""
|
|
244
|
+
Format the instruction for the given focal method and class.
|
|
245
|
+
"""
|
|
246
|
+
inst = f"Question: Can you write a brief summary for the method `{focal_method}` in the class `{focal_class}` below?\n"
|
|
247
|
+
|
|
248
|
+
inst += "\n"
|
|
249
|
+
inst += f"```{language}\n"
|
|
250
|
+
inst += code
|
|
251
|
+
inst += "```" if code.endswith("\n") else "\n```"
|
|
252
|
+
inst += "\n"
|
|
253
|
+
return inst
|
|
254
|
+
|
|
255
|
+
def prompt_ollama(message: str, model_id: str = "granite-code:8b-instruct") -> str:
|
|
256
|
+
"""Prompt local model on Ollama"""
|
|
257
|
+
response_object = ollama.generate(model=model_id, prompt=message)
|
|
258
|
+
return response_object["response"]
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
if __name__ == "__main__":
|
|
262
|
+
# (1) Create a new instance of the CLDK class
|
|
263
|
+
cldk = CLDK(language="java")
|
|
264
|
+
|
|
265
|
+
# (2) Create an analysis object over the java application
|
|
266
|
+
analysis = cldk.analysis(project_path=os.getenv("JAVA_APP_PATH"))
|
|
267
|
+
|
|
268
|
+
# (3) Iterate over all the files in the project
|
|
269
|
+
for file_path, class_file in analysis.get_symbol_table().items():
|
|
270
|
+
class_file_path = Path(file_path).absolute().resolve()
|
|
271
|
+
# (4) Iterate over all the classes in the file
|
|
272
|
+
for type_name, type_declaration in class_file.type_declarations.items():
|
|
273
|
+
# (5) Iterate over all the methods in the class
|
|
274
|
+
for method in type_declaration.callable_declarations.values():
|
|
275
|
+
|
|
276
|
+
# (6) Get code body of the method
|
|
277
|
+
code_body = class_file_path.read_text()
|
|
278
|
+
|
|
279
|
+
# (7) Initialize the treesitter utils for the class file content
|
|
280
|
+
tree_sitter_utils = cldk.tree_sitter_utils(source_code=code_body)
|
|
281
|
+
|
|
282
|
+
# (8) Sanitize the class for analysis
|
|
283
|
+
sanitized_class = tree_sitter_utils.sanitize_focal_class(method.declaration)
|
|
284
|
+
|
|
285
|
+
# (9) Format the instruction for the given focal method and class
|
|
286
|
+
instruction = format_inst(
|
|
287
|
+
code=sanitized_class,
|
|
288
|
+
focal_method=method.declaration,
|
|
289
|
+
focal_class=type_name,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
# (10) Prompt the local model on Ollama
|
|
293
|
+
llm_output = prompt_ollama(
|
|
294
|
+
message=instruction,
|
|
295
|
+
model_id="granite-code:20b-instruct",
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
# (11) Print the instruction and LLM output
|
|
299
|
+
print(f"Instruction:\n{instruction}")
|
|
300
|
+
print(f"LLM Output:\n{llm_output}")
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### Publication (papers and blogs related to CLDK)
|
|
304
|
+
1. Pan, Rangeet, Myeongsoo Kim, Rahul Krishna, Raju Pavuluri, and Saurabh Sinha. "[Multi-language Unit Test Generation using LLMs.](https://arxiv.org/abs/2409.03093)" arXiv preprint arXiv:2409.03093 (2024).
|
|
305
|
+
2. Pan, Rangeet, Rahul Krishna, Raju Pavuluri, Saurabh Sinha, and Maja Vukovic., "[Simplify your Code LLM solutions using CodeLLM Dev Kit (CLDK).](https://www.linkedin.com/pulse/simplify-your-code-llm-solutions-using-codellm-dev-kit-rangeet-pan-vnnpe/?trackingId=kZ3U6d8GSDCs8S1oApXZgg%3D%3D)", Blog.
|
|
306
|
+
|