Skip to content

Commit fb77695

Browse files
authored
Merge pull request #195 from pwgit-create/develop
Version 2.1
2 parents 798e36a + aaa90b4 commit fb77695

File tree

18 files changed

+132
-37
lines changed

18 files changed

+132
-37
lines changed

AppWish/AppWish/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>pn.dev</groupId>
55
<artifactId>code-generator-gui-ollama</artifactId>
66
<name>CodeGenerator-GUI</name>
7-
<version>2.0.5</version>
7+
<version>2.1</version>
88
<description>The GUI interface for the pn.dev.code-generator-ollama library</description>
99
<inceptionYear>2024</inceptionYear>
1010
<developers>

AppWish/AppWish/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>pn.dev</groupId>
77
<artifactId>code-generator-gui-ollama</artifactId>
8-
<version>2.0.5</version>
8+
<version>2.1</version>
99
<name>CodeGenerator-GUI</name>
1010

1111

@@ -52,7 +52,7 @@
5252
<dependency>
5353
<groupId>pn.dev</groupId>
5454
<artifactId>code-generator-ollama</artifactId>
55-
<version>2.0.5</version>
55+
<version>2.1</version>
5656
</dependency>
5757
<dependency>
5858
<groupId>org.openjfx</groupId>

AppWish/AppWish/src/main/java/pn/app_wish/constant/AboutConstants.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
public record AboutConstants() {
55

6-
private static final String APP_WISH_VERSION = "Appwish Enterprise 2.0.5";
7-
private static final String ABOUT_APP_WISH = "AppWish (2) is a open source project that creates Java applications from text input with the help of AI models";
6+
private static final String APP_WISH_VERSION = "Appwish Enterprise 2.1";
7+
private static final String ABOUT_APP_WISH = "AppWish 2 is a open source project that creates Java applications from text input with the help of AI models";
88
private static final String DEVELOPED_BY = "Pwgit-Create / Peter Westin";
99
private static final String CONTACT = "\nEmail: snow_900@outlook.com";
1010
private static final String LINK_TO_DISCUSSION = "https://github.com/pwgit-create/APPWISH_OLLAMA/discussions";

AppWish/AppWish/src/main/java/pn/app_wish/constant/StaticAppWishConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
public record StaticAppWishConstants() {
44
public static final String BASH_PATH = "/bin/bash";
55
public static final String C_ARGUMENT = "-c";
6+
public static final String CP_ARGUMENT="-cp ";
67
public static final String JAVA_TEXT = "java ";
78

9+
public static final String CP_PATH= ".:external_libs/* " ;
10+
811

912
public static final String MAIN_TEXT="Main";
1013
public static final String MAIN_DOT_JAVA="Main.java";

AppWish/AppWish/src/main/java/pn/app_wish/controller/AppHistoryController.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import pn.app_wish.AppWish;
1818
import pn.app_wish.constant.AboutConstants;
1919
import pn.app_wish.constant.GUIConstants;
20-
import pn.app_wish.constant.StaticAppWishConstants;
20+
21+
import pn.app_wish.model.AppCmd;
2122
import pn.app_wish.util.AppWishUtil;
2223
import pn.cg.datastorage.constant.PathConstants;
2324

@@ -26,7 +27,7 @@
2627
import java.net.URL;
2728

2829
import java.nio.file.Files;
29-
import java.nio.file.Path;
30+
3031
import java.util.*;
3132
import java.util.stream.Collectors;
3233

@@ -85,7 +86,8 @@ private void handleSelectButtonAction(ActionEvent ae) {
8586
final String r2 = ".java";
8687
final String executePath = selectedFile.getAbsolutePath().replace(r1, r2);
8788

88-
processBuilder = new ProcessBuilder(BASH_PATH, C_ARGUMENT, JAVA_TEXT + executePath);
89+
90+
processBuilder = new ProcessBuilder(new AppCmd(executePath).GetCMDForRunningApp_Application());
8991
executingJavaAppProcess = processBuilder.inheritIO().start();
9092
} catch (IOException e) {
9193
System.out.println("RuntimeException while starting Java executable");
@@ -195,7 +197,7 @@ private void deleteJavaApp(File classFileOfApplication) {
195197
try {
196198

197199
// Delete the Class File of the chosen application
198-
Files.delete(classFileOfApplication.toPath());
200+
Files.deleteIfExists(classFileOfApplication.toPath());
199201
log.info("The class file of your selected application has been deleted");
200202
} catch (IOException e) {
201203

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
package pn.app_wish.model;
2+
23
import pn.app_wish.constant.StaticAppWishConstants;
4+
import pn.app_wish.util.AppWishUtil;
5+
36

47
public record AppCmd(String javaExecutablePath) {
58

69
public final String[] GetCMDForRunningApp_Application() {
710

8-
return new String[]{StaticAppWishConstants.BASH_PATH,StaticAppWishConstants.C_ARGUMENT, StaticAppWishConstants.JAVA_TEXT + javaExecutablePath};
11+
boolean isExternalLibraries = AppWishUtil.isExternalLibrariesBeingUsed();
12+
if (isExternalLibraries) {
13+
return new String[]{StaticAppWishConstants.BASH_PATH, StaticAppWishConstants.C_ARGUMENT, StaticAppWishConstants.JAVA_TEXT + StaticAppWishConstants.CP_ARGUMENT + StaticAppWishConstants.CP_PATH + javaExecutablePath};
14+
15+
} else {
16+
return new String[]{StaticAppWishConstants.BASH_PATH, StaticAppWishConstants.C_ARGUMENT, StaticAppWishConstants.JAVA_TEXT + javaExecutablePath};
17+
18+
}
919
}
1020
}

AppWish/AppWish/src/main/java/pn/app_wish/util/AppWishUtil.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package pn.app_wish.util;
22

3+
import pn.cg.datastorage.CodeGeneratorConfig;
34
import pn.cg.datastorage.DataStorage;
45
import pn.cg.datastorage.constant.PathConstants;
56

@@ -80,5 +81,20 @@ public final static void deleteTmpCodeBaseFiles(){
8081
}
8182
});
8283
}}
84+
85+
/**
86+
* See if external libraries are used or not. Will also create a new CodeGenerator config
87+
* in case no code generation has occurred in the session previously
88+
* @return boolean
89+
*/
90+
public final static boolean isExternalLibrariesBeingUsed(){
91+
92+
if(DataStorage.getInstance().getCodeGeneratorConfig() == null) {
93+
final CodeGeneratorConfig codeGeneratorConfig = new CodeGeneratorConfig();
94+
DataStorage.getInstance().setCodeGeneratorConfig(codeGeneratorConfig);}
95+
96+
return DataStorage.getInstance().getCodeGeneratorConfig().isUSE_EXTERNAL_LIBRARIES();
8397
}
8498

99+
}
100+

AppWish/AppWish/src/main/resources/config.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ NUM_CTX=2048
22
TOP_K=40
33
NUM_PREDICT=-1
44
TEMPERATURE=0.8
5+
USE_EXTERNAL_LIBRARIES=off
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
javac -cp .:external_libs/* $1 2>&1 | tee
3+

cg/CodeGenerator/CodeGenerator/dependency-reduced-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>pn.dev</groupId>
55
<artifactId>code-generator-ollama</artifactId>
6-
<version>2.0.5</version>
6+
<version>2.1</version>
77
<description>The Java Application-Generator (pn.dev.code-generator-ollama) creates applications by giving a string of your desired features for a Java application, like this: AppSystem.StartCodeGenerator(String appWish)</description>
88
<inceptionYear>2024</inceptionYear>
99
<developers>

cg/CodeGenerator/CodeGenerator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>pn.dev</groupId>
88
<artifactId>code-generator-ollama</artifactId>
9-
<version>2.0.5</version>
9+
<version>2.1</version>
1010

1111

1212
<description>The Java Application-Generator (pn.dev.code-generator-ollama) creates applications by giving a string of your desired features for a Java application, like this: AppSystem.StartCodeGenerator(String appWish)</description>

cg/CodeGenerator/CodeGenerator/src/main/java/pn/cg/app_system/code_generation/ClassCompiler.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import pn.cg.util.TaskUtil;
1212

1313

14-
import java.nio.file.Path;
1514
import java.util.concurrent.ExecutorService;
1615

1716
public class ClassCompiler {
@@ -23,7 +22,8 @@ public ClassCompiler() {
2322

2423
/**
2524
* Tries to compile a file with java source code into byte code
26-
* @param className Class name of the class that we will try to compile
25+
*
26+
* @param className Class name of the class that we will try to compile
2727
* @param superAppDir A String path that will be provided if it is a super app generation and left as null if not
2828
*/
2929
private final void compile(String className, String superAppDir) {
@@ -35,35 +35,49 @@ private final void compile(String className, String superAppDir) {
3535

3636
ExecutorService executor = ThreadPoolMaster.getInstance().getExecutor();
3737

38-
if(isSuperAppGeneration)
38+
if (isSuperAppGeneration)
3939
log.info("Compiler path -> {}", TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName()));
40-
else
41-
log.info("Compiler path -> {}", TaskUtil.addFilePathToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION));
40+
else
41+
log.info("Compiler path -> {}", TaskUtil.addFilePathToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION));
42+
43+
String regularCompileScript = ScriptConstants.JAVAC_SCRIPT_NAME;
44+
String compileScriptWithAddedClassPath = ScriptConstants.JAVAC_WITH_ADDED_CLASS_PATH_TO_EXTERNAL_LIBRARIES;
45+
46+
final boolean useExternalLibraries = DataStorage.getInstance().getCodeGeneratorConfig().isUSE_EXTERNAL_LIBRARIES();
47+
48+
if (isSuperAppGeneration) {
4249

43-
String scriptToUse = ScriptConstants.JAVAC_SCRIPT_NAME;
44-
log.debug("script used when compiling -> {}", scriptToUse);
50+
if (useExternalLibraries) {
51+
executor.execute(new CompileClassTask(compileScriptWithAddedClassPath, new String[]{TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName())}));
52+
} else {
53+
executor.execute(new CompileClassTask(regularCompileScript, new String[]{TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION, DataStorage.getInstance().getSuperAppDirectoryName())}));
54+
}
55+
} else {
4556

46-
if(isSuperAppGeneration)
47-
executor.execute(new CompileClassTask(scriptToUse,new String[]{TaskUtil.addFilePathOfSuperAppToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION,DataStorage.getInstance().getSuperAppDirectoryName())}));
48-
else
49-
executor.execute(new CompileClassTask(scriptToUse, new String[]{TaskUtil.addFilePathToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION)}));
57+
if (useExternalLibraries) {
58+
executor.execute(new CompileClassTask(compileScriptWithAddedClassPath, new String[]{TaskUtil.addFilePathToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION)}));
5059

60+
} else {
61+
executor.execute(new CompileClassTask(regularCompileScript, new String[]{TaskUtil.addFilePathToClassName(className + CommonStringConstants.JAVA_FILE_EXTENSION)}));
62+
}
63+
}
5164
}
65+
5266
/**
5367
* Tries to compile a file with java source code into byte code
68+
*
5469
* @param className Class name of the class that we will try to compile
5570
*/
56-
public void compileClass(String className){
57-
compile(className,null);
71+
public void compileClass(String className) {
72+
compile(className, null);
5873
}
5974

6075
/**
61-
*
62-
* @param className Class name of the class that we will try to compile
76+
* @param className Class name of the class that we will try to compile
6377
* @param superAppDir The path to the directory of the super app
6478
*/
65-
public void compileSuperClass(String className, String superAppDir){
66-
compile(className,superAppDir);
79+
public void compileSuperClass(String className, String superAppDir) {
80+
compile(className, superAppDir);
6781

6882
}
6983

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package pn.cg.app_system.code_generation.model;
22

33
/**
4-
* Record for the Ollama config options that you can edit in appwish
4+
* Record for the Ollama config options that you can edit in app wish
55
* @param num_ctx
66
* @param top_k
77
* @param num_predict
88
* @param temperature
9+
* @param useExternalLibraries
910
*/
10-
public record OllamaConfig(int num_ctx,int top_k,int num_predict,float temperature){}
11+
public record OllamaConfig(int num_ctx,int top_k,int num_predict,float temperature,boolean useExternalLibraries){}

cg/CodeGenerator/CodeGenerator/src/main/java/pn/cg/datastorage/CodeGeneratorConfig.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class CodeGeneratorConfig {
1919

2020
/**
2121
* @OllamaDocs Size of context window (default 2048)
22-
* @use-info Remember that a high context window demands more compute resources
23-
* @use-info It is important to check the documentation of the AI-Model you are using regarding the supported context window sizes
22+
* @use-info Remember that a high context window demands more compute resources
23+
* @use-info It is important to check the documentation of the AI-Model you are using regarding the supported context window sizes
2424
*/
2525
private final int NUM_CTX;
2626

@@ -39,6 +39,11 @@ public class CodeGeneratorConfig {
3939
*/
4040
private final float TEMPERATURE;
4141

42+
/**
43+
* This config states wherever external libraries should be added to the classpath or not
44+
*/
45+
private final boolean USE_EXTERNAL_LIBRARIES;
46+
4247
public CodeGeneratorConfig() {
4348
// This method should only be called once (when app is initializing) constructor
4449
this.OLLAMA_MODEL = GetOllamaModelNameFromPropFile();
@@ -51,10 +56,12 @@ public CodeGeneratorConfig() {
5156
this.TOP_K = ollamaConfig.top_k();
5257
this.NUM_PREDICT = ollamaConfig.num_predict();
5358
this.TEMPERATURE = ollamaConfig.temperature();
59+
this.USE_EXTERNAL_LIBRARIES = ollamaConfig.useExternalLibraries();
5460
}
5561

5662
/**
5763
* Get the value from the "ollama_model.props"
64+
*
5865
* @return String that contains the model name
5966
*/
6067
private final String GetOllamaModelNameFromPropFile() {
@@ -77,8 +84,9 @@ private final String GetOllamaModelNameFromPropFile() {
7784

7885
/**
7986
* Creates an OllamaConfigDTO.
80-
* @use-info In the event of an error, the record returned will only contain the default values
87+
*
8188
* @return Record with Ollama config options that are editable in appwish
89+
* @use-info In the event of an error, the record returned will only contain the default values
8290
*/
8391
private final OllamaConfig CreateOllamaConfigDTOFromPropFile() {
8492
OllamaConfig newOllamaConfigRecord;
@@ -96,23 +104,26 @@ private final OllamaConfig CreateOllamaConfigDTOFromPropFile() {
96104
final String PROPERTY_NAME_TOP_K = "TOP_K";
97105
final String PROPERTY_NAME_NUM_PREDICT = "NUM_PREDICT";
98106
final String PROPERTY_NAME_TEMPERATURE = "TEMPERATURE";
107+
final String PROPERTY_NAME_USE_EXTERNAL_LIBRARIES = "USE_EXTERNAL_LIBRARIES";
99108

100109
final Properties properties = PropUtil.ReadPropertiesFile(PROPERTIES_FILE_NAME_FOR_CONFIG);
101110

102111
newOllamaConfigRecord = new OllamaConfig(Integer.parseInt(properties.getProperty(PROPERTY_NAME_NUM_CTX)),
103112
Integer.parseInt(properties.getProperty(PROPERTY_NAME_TOP_K)),
104113
Integer.parseInt(properties.getProperty(PROPERTY_NAME_NUM_PREDICT)),
105-
Float.parseFloat(properties.getProperty(PROPERTY_NAME_TEMPERATURE)));
114+
Float.parseFloat(properties.getProperty(PROPERTY_NAME_TEMPERATURE)),
115+
convertExternalLibConfigIntoBooleanValue(properties.getProperty(PROPERTY_NAME_USE_EXTERNAL_LIBRARIES)));
106116
} catch (IOException e) {
107117
System.err.println("Error when fetching the ollama config file\nSetting default values for all config parameters..");
108118
// Default values should be returned if the ollama config file is corrupted
109-
newOllamaConfigRecord = new OllamaConfig(2048, 40, 128, 0.8f);
119+
newOllamaConfigRecord = new OllamaConfig(2048, 40, 128, 0.8f, false);
110120
}
111121
return newOllamaConfigRecord;
112122
}
113123

114124
/**
115125
* Retrieves the name of the AI model that is being used with AppWish
126+
*
116127
* @return String
117128
*/
118129
public final String getOllamaModel() {
@@ -121,6 +132,7 @@ public final String getOllamaModel() {
121132

122133
/**
123134
* Get the value of the context window
135+
*
124136
* @return int
125137
*/
126138
public final int getNUM_CTX() {
@@ -129,6 +141,7 @@ public final int getNUM_CTX() {
129141

130142
/**
131143
* Get the TOP_K value
144+
*
132145
* @return int
133146
*/
134147
public final int getTOP_K() {
@@ -137,6 +150,7 @@ public final int getTOP_K() {
137150

138151
/**
139152
* Get the number of tokens to predict
153+
*
140154
* @return int
141155
*/
142156
public final int getNUM_PREDICT() {
@@ -145,9 +159,20 @@ public final int getNUM_PREDICT() {
145159

146160
/**
147161
* Get the temperature that the AI Model uses
162+
*
148163
* @return float
149164
*/
150165
public final float getTEMPERATURE() {
151166
return TEMPERATURE;
152167
}
168+
169+
public boolean isUSE_EXTERNAL_LIBRARIES() {
170+
return USE_EXTERNAL_LIBRARIES;
171+
}
172+
173+
private final boolean convertExternalLibConfigIntoBooleanValue(String value) {
174+
175+
return value.equalsIgnoreCase("On");
176+
177+
}
153178
}

0 commit comments

Comments
 (0)