You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/examples/java/generate_unit_tests.ipynb
+1-2Lines changed: 1 addition & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,6 @@
19
19
"execution_count": null,
20
20
"outputs": [],
21
21
"source": [
22
-
"from pathlib import Path\n",
23
22
"import ollama\n",
24
23
"from cldk import CLDK\n",
25
24
"from cldk.analysis import AnalysisLevel"
@@ -94,7 +93,7 @@
94
93
{
95
94
"cell_type": "markdown",
96
95
"source": [
97
-
"(Step 3) Third, collect all the information needed for each method. "
96
+
"(Step 4) Fourth, collect all the information needed for each method. In this process, we go through all the classes in the application, and then for each class, we collect the signature of all the constructors. If there is no constructor present, we add the signature of the default constructor. Then, we go through all the non-private methods of the class and formulate the prompt using the constructor and the method information. Finally, we use the prompt to call LLM and get the final output."
Copy file name to clipboardExpand all lines: docs/examples/java/validating_code_translation.ipynb
+77-3Lines changed: 77 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,88 @@
1
1
{
2
2
"cells": [
3
+
{
4
+
"cell_type": "markdown",
5
+
"source": [
6
+
"Code translation aims to convert source code from one programming language (PL) to another. Given the promising abilities of large language models (LLMs) in code synthesis, researchers are exploring their potential to automate code translation. In our recent paper [https://dl.acm.org/doi/10.1145/3597503.3639226] published at ICSE'24, we found that LLM-based code translation is very promising. In this example, we will walk through the steps of translating each Java class to Python and checking various properties of translated code, such as the number of methods, number of fields, formal arguments, etc.\n",
7
+
"\n",
8
+
"(Step 1) First, we will import all the necessary libraries"
9
+
],
10
+
"metadata": {
11
+
"collapsed": false
12
+
},
13
+
"id": "47af1410ab0a3b4d"
14
+
},
15
+
{
16
+
"cell_type": "code",
17
+
"execution_count": null,
18
+
"outputs": [],
19
+
"source": [
20
+
"import ollama\n",
21
+
"from cldk import CLDK\n",
22
+
"from cldk.analysis import AnalysisLevel"
23
+
],
24
+
"metadata": {
25
+
"collapsed": false
26
+
},
27
+
"id": "47a78f61a53b2b55"
28
+
},
29
+
{
30
+
"cell_type": "markdown",
31
+
"source": [
32
+
"(Step 2) Second, we will form the prompt for the model, which will include the body of the Java class after removing all the comments and the import statements."
" Format the instruction for the given focal method and class.\n",
47
+
"\"\"\"\n",
48
+
" inst = f\"Question: Can you translate the Java class `{focal_class}` below to Python and generate under code block (```)?\\n\"\n",
49
+
"\n",
50
+
" inst += \"\\n\"\n",
51
+
" inst += f\"```{language}\\n\"\n",
52
+
" inst += code\n",
53
+
" inst += \"```\" if code.endswith(\"\\n\") else \"\\n```\"\n",
54
+
" inst += \"\\n\"\n",
55
+
" return inst"
56
+
],
57
+
"metadata": {
58
+
"collapsed": false
59
+
},
60
+
"id": "dc1ec56e92e90c15"
61
+
},
62
+
{
63
+
"cell_type": "markdown",
64
+
"source": [
65
+
"(Step 3) Create a function to call LLM. There are various ways to achieve that. However, for illustrative purpose, we use ollama, a library to communicate with models downloaded locally."
0 commit comments