Skip to content

Commit 8a9bd19

Browse files
committed
feat: add more options
1 parent cdc8968 commit 8a9bd19

19 files changed

Lines changed: 105 additions & 33 deletions

File tree

code-generator/cli/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.javaaidev.easyllmtools</groupId>
88
<artifactId>code-generator</artifactId>
9-
<version>0.1.7</version>
9+
<version>0.1.8</version>
1010
</parent>
1111

1212
<artifactId>code-generator-cli</artifactId>

code-generator/cli/src/main/kotlin/com/javaaidev/easyllmtools/codegenerator/cli/CodeGeneratorCli.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlin.system.exitProcess
88
@CommandLine.Command(
99
name = "easy-llm-tools",
1010
mixinStandardHelpOptions = true,
11-
version = ["0.1.7"],
11+
version = ["0.1.8"],
1212
description = ["Generate code for LLM tools"],
1313
scope = CommandLine.ScopeType.INHERIT,
1414
subcommands = [

code-generator/openapi/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.javaaidev.easyllmtools</groupId>
88
<artifactId>code-generator</artifactId>
9-
<version>0.1.7</version>
9+
<version>0.1.8</version>
1010
</parent>
1111

1212
<artifactId>code-generator-openapi</artifactId>

code-generator/openapi/src/main/resources/Java/libraries/okhttp-gson/pom.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@
392392
<dependency>
393393
<groupId>com.javaaidev.easyllmtools</groupId>
394394
<artifactId>llm-tool-spec</artifactId>
395-
<version>0.1.7</version>
395+
<version>0.1.8</version>
396396
</dependency>
397397
<!-- test dependencies -->
398398
<dependency>

code-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.javaaidev.easyllmtools</groupId>
88
<artifactId>easyllmtools-parent</artifactId>
9-
<version>0.1.7</version>
9+
<version>0.1.8</version>
1010
</parent>
1111

1212
<artifactId>code-generator</artifactId>

code-generator/shared/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.javaaidev.easyllmtools</groupId>
88
<artifactId>code-generator</artifactId>
9-
<version>0.1.7</version>
9+
<version>0.1.8</version>
1010
</parent>
1111

1212
<artifactId>code-generator-shared</artifactId>

code-generator/simple/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.javaaidev.easyllmtools</groupId>
88
<artifactId>code-generator</artifactId>
9-
<version>0.1.7</version>
9+
<version>0.1.8</version>
1010
</parent>
1111

1212
<artifactId>code-generator-simple</artifactId>

code-generator/simple/src/main/kotlin/com/javaaidev/easyllmtools/codegenerator/simple/SimpleCodeGenerator.kt

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ data class GeneratedFile(
5252
val templateName: String,
5353
val dir: Path,
5454
val overwrite: Boolean = true,
55+
val skip: Boolean = false,
5556
val fileNameSupplier: Supplier<String>,
5657
)
5758

@@ -79,16 +80,23 @@ object SimpleCodeGenerator {
7980
overwriteToolImplementation: Boolean,
8081
overwritePomFile: Boolean,
8182
toolIdPrefix: String,
83+
modelFilesOnly: Boolean,
84+
noModelFiles: Boolean,
8285
parentGroupId: String,
8386
parentArtifactId: String,
8487
parentArtifactVersion: String,
88+
customToolName: String,
89+
toolDescription: String,
90+
customModelPackageName: String,
8591
) {
8692
logger.info("Generate code from {}", inputSpec.toPath().toAbsolutePath().normalize())
8793
val jsonNode = objectMapper.readTree(inputSpec)
8894
val definitionNode =
8995
jsonNode.get("definition") ?: throw InvalidToolSpecException("Definition is a required")
90-
val name = definitionNode.get("name")?.textValue() ?: ""
91-
val description = definitionNode.get("description")?.textValue() ?: ""
96+
val name =
97+
customToolName.ifBlank { definitionNode.get("name")?.textValue() ?: "" }
98+
val description =
99+
toolDescription.ifBlank { definitionNode.get("description")?.textValue() ?: "" }
92100
val output = Files.createTempDirectory("tool_")
93101
val sourceRootDir = outputDir.resolve(Path.of("src", "main", "java"))
94102
val resourcesRootDir = outputDir.resolve(Path.of("src", "main", "resources"))
@@ -98,7 +106,7 @@ object SimpleCodeGenerator {
98106
val returnTypeJson = jsonNodeString(definitionNode.get("returnType"))
99107
val examplesJson = jsonNodeString(definitionNode.get("examples"))
100108
val configurationJson = jsonNodeString(jsonNode.get("configuration"))
101-
val modelPackageName = "$packageName.model"
109+
val modelPackageName = customModelPackageName.ifBlank { "$packageName.model" }
102110
val toolName = CaseUtils.toCamelCase(name, true)
103111
val toolId = toolIdPrefix + (definitionNode.get("id")?.textValue() ?: toolName)
104112
val hasConfiguration = notEmptyJson(configurationJson)
@@ -108,7 +116,7 @@ object SimpleCodeGenerator {
108116
if (notEmptyJson(parametersJson)) "${toolName}Parameters" else "Void"
109117
val returnTypeClassName =
110118
if (notEmptyJson(returnTypeJson)) "${toolName}ReturnType" else "Void"
111-
if (notEmptyJson(parametersJson)) {
119+
if (!noModelFiles && notEmptyJson(parametersJson)) {
112120
jsonNodeToCode(
113121
output,
114122
sourceRootDir,
@@ -117,7 +125,7 @@ object SimpleCodeGenerator {
117125
modelPackageName
118126
)
119127
}
120-
if (notEmptyJson(returnTypeJson)) {
128+
if (!noModelFiles && notEmptyJson(returnTypeJson)) {
121129
jsonNodeToCode(
122130
output,
123131
sourceRootDir,
@@ -126,7 +134,7 @@ object SimpleCodeGenerator {
126134
modelPackageName
127135
)
128136
}
129-
if (hasConfiguration) {
137+
if (!noModelFiles && hasConfiguration) {
130138
jsonNodeToCode(
131139
output,
132140
sourceRootDir,
@@ -161,26 +169,40 @@ object SimpleCodeGenerator {
161169
parametersJson,
162170
returnTypeJson,
163171
examplesJson,
164-
)
172+
),
165173
)
166174

167175
val sourceDir = sourceRootDir.resolve(Path.of(".", *packageName.split(".").toTypedArray()))
168176
val servicesDir = resourcesRootDir.resolve("META-INF").resolve("services")
169-
Files.createDirectories(servicesDir)
170177
val files = listOf(
171-
GeneratedFile("abstractTool", sourceDir) { "Abstract${toolName}.java" },
172-
GeneratedFile("toolFactory", sourceDir) { "${toolName}Factory.java" },
173-
GeneratedFile("tool", sourceDir, overwriteToolImplementation) { "${toolName}.java" },
178+
GeneratedFile(
179+
"abstractTool",
180+
sourceDir,
181+
skip = modelFilesOnly
182+
) { "Abstract${toolName}.java" },
183+
GeneratedFile(
184+
"toolFactory",
185+
sourceDir,
186+
skip = modelFilesOnly
187+
) { "${toolName}Factory.java" },
188+
GeneratedFile(
189+
"tool",
190+
sourceDir,
191+
overwriteToolImplementation,
192+
modelFilesOnly
193+
) { "${toolName}.java" },
174194
GeneratedFile("pom", outputDir, overwritePomFile) { "pom.xml" },
175195
GeneratedFile(
176196
"services",
177-
servicesDir
197+
servicesDir,
198+
skip = modelFilesOnly,
178199
) { "com.javaaidev.easyllmtools.llmtoolspec.ToolFactory" },
179200
)
180201

181202
files.forEach { file ->
203+
Files.createDirectories(file.dir)
182204
val outputFile = file.dir.resolve(file.fileNameSupplier.get())
183-
if (outputFile.exists() && !file.overwrite) {
205+
if (file.skip || (outputFile.exists() && !file.overwrite)) {
184206
logger.info("Skip generation of file {}", outputFile)
185207
return@forEach
186208
}

code-generator/simple/src/main/kotlin/com/javaaidev/easyllmtools/codegenerator/simple/SimpleCodeGeneratorCommand.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,41 @@ class SimpleCodeGeneratorCommand : Callable<Int> {
3131
)
3232
var toolIdPrefix = ""
3333

34+
@CommandLine.Option(
35+
names = ["--model-files-only"],
36+
defaultValue = "false",
37+
description = ["Only generate model files"]
38+
)
39+
var modelFilesOnly: Boolean = false
40+
41+
@CommandLine.Option(
42+
names = ["--no-model-files"],
43+
defaultValue = "false",
44+
description = ["Skip generation of model files"]
45+
)
46+
var noModelFiles: Boolean = false
47+
48+
@CommandLine.Option(
49+
names = ["--tool-name"],
50+
defaultValue = "",
51+
description = ["Override tool name in the spec file"]
52+
)
53+
var toolName: String = ""
54+
55+
@CommandLine.Option(
56+
names = ["--tool-description"],
57+
defaultValue = "",
58+
description = ["Override tool description in the spec file"]
59+
)
60+
var toolDescription: String = ""
61+
62+
@CommandLine.Option(
63+
names = ["--model-package-name"],
64+
defaultValue = "",
65+
description = ["Override default model package name"]
66+
)
67+
var modelPackageName: String = ""
68+
3469
override fun call(): Int {
3570
SimpleCodeGenerator.generate(
3671
options.inputSpec,
@@ -42,9 +77,14 @@ class SimpleCodeGeneratorCommand : Callable<Int> {
4277
overwriteToolImplementation,
4378
overwritePomFile,
4479
toolIdPrefix,
80+
modelFilesOnly,
81+
noModelFiles,
4582
options.parentGroupId,
4683
options.parentArtifactId,
4784
options.parentArtifactVersion,
85+
toolName,
86+
toolDescription,
87+
modelPackageName,
4888
)
4989
return 0
5090
}

code-generator/simple/src/main/resources/template/pom.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
<dependency>
3030
<groupId>com.javaaidev.easyllmtools</groupId>
3131
<artifactId>llm-tool-spec</artifactId>
32-
<version>0.1.7</version>
32+
<version>0.1.8</version>
3333
</dependency>
3434
</dependencies>
3535

3636
<build>
37+
<sourceDirectory>src/main/java</sourceDirectory>
3738
<plugins>
3839
<plugin>
3940
<groupId>org.apache.maven.plugins</groupId>

0 commit comments

Comments
 (0)