Skip to content

Commit ea067a7

Browse files
committed
refactor: add lost executeScript for prompt script
1 parent 150c7d1 commit ea067a7

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

llm-modules/prompt-script/src/main/kotlin/cc/unitmesh/prompt/PromptScriptCommand.kt

+32-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,38 @@ class PromptScriptCommand : CliktCommand(help = HELP_TEXT) {
2626
}
2727

2828
// check input file exits
29-
val file = File(input)
30-
if (!file.exists()) {
31-
throw Exception("input file not found: $input")
32-
}
33-
34-
// execute script
35-
val executor = ScriptExecutor(file)
36-
executor.execute()
29+
executeScript(input)
3730

3831
logger.debug("execute script success: $input")
3932
}
40-
}
33+
}
34+
35+
/**
36+
* Execute script is a method used for running Kotlin Scripting mods.
37+
*
38+
* @param input the path to the input file containing the script to be executed
39+
* @throws Exception if the input file is not found
40+
*
41+
* Example usage:
42+
* ```kotlin
43+
* @file:DependsOn("cc.unitmesh:prompt-script:0.3.8")
44+
*
45+
* import cc.unitmesh.prompt.executeScript
46+
*
47+
* executeScript("config/prompt.unit-mesh.yml")
48+
* ```
49+
*
50+
* This method takes a string input representing the path to the input file containing the script to be executed.
51+
* It checks if the file exists, and if not, throws an exception indicating that the input file was not found.
52+
* If the file exists, it creates a ScriptExecutor object with the input file and executes the script using the execute() method of the ScriptExecutor class.
53+
*/
54+
fun executeScript(input: String) {
55+
val file = File(input)
56+
if (!file.exists()) {
57+
throw Exception("input file not found: ${input}")
58+
}
59+
60+
// execute script
61+
val executor = ScriptExecutor(file)
62+
executor.execute()
63+
}

0 commit comments

Comments
 (0)