|
5 | 5 | import java.nio.file.Paths;
|
6 | 6 |
|
7 | 7 | public record Options(Path modelPath, String prompt, String systemPrompt, String suffix, boolean interactive, float temperature, float topp, long seed, int maxTokens, boolean stream, boolean echo,
|
8 |
| - boolean useTornadovm) { |
| 8 | + boolean useTornadovm, boolean serviceMode) { |
9 | 9 |
|
10 | 10 | public static final int DEFAULT_MAX_TOKENS = 1024;
|
11 | 11 |
|
12 | 12 | public Options {
|
13 |
| - require(interactive || prompt != null, "Missing argument: --prompt is required in --instruct mode e.g. --prompt \"Why is the sky blue?\""); |
| 13 | + // Skip prompt validation in service mode |
| 14 | + if (!serviceMode) { |
| 15 | + require(interactive || prompt != null, "Missing argument: --prompt is required in --instruct mode e.g. --prompt \"Why is the sky blue?\""); |
| 16 | + } |
14 | 17 | require(0 <= temperature, "Invalid argument: --temperature must be non-negative");
|
15 | 18 | require(0 <= topp && topp <= 1, "Invalid argument: --top-p must be within [0, 1]");
|
16 | 19 | }
|
@@ -61,7 +64,7 @@ public static Options getDefaultOptions() {
|
61 | 64 | boolean echo = false;
|
62 | 65 | boolean useTornadoVM = getDefaultTornadoVM();
|
63 | 66 |
|
64 |
| - return new Options(modelPath, prompt, systemPrompt, suffix, interactive, temperature, topp, seed, maxTokens, stream, echo, useTornadoVM); |
| 67 | + return new Options(modelPath, prompt, systemPrompt, suffix, interactive, temperature, topp, seed, maxTokens, stream, echo, useTornadoVM, false); |
65 | 68 | }
|
66 | 69 |
|
67 | 70 | public static Options parseOptions(String[] args) {
|
@@ -123,6 +126,52 @@ public static Options parseOptions(String[] args) {
|
123 | 126 | useTornadovm = getDefaultTornadoVM();
|
124 | 127 | }
|
125 | 128 |
|
126 |
| - return new Options(modelPath, prompt, systemPrompt, suffix, interactive, temperature, topp, seed, maxTokens, stream, echo, useTornadovm); |
| 129 | + return new Options(modelPath, prompt, systemPrompt, suffix, interactive, temperature, topp, seed, maxTokens, stream, echo, useTornadovm, false); |
| 130 | + } |
| 131 | + |
| 132 | + public static Options parseServiceOptions(String[] args) { |
| 133 | + Path modelPath = null; |
| 134 | + int maxTokens = 512; // Default context length |
| 135 | + |
| 136 | + for (int i = 0; i < args.length; i++) { |
| 137 | + String optionName = args[i]; |
| 138 | + require(optionName.startsWith("-"), "Invalid option %s", optionName); |
| 139 | + |
| 140 | + String nextArg; |
| 141 | + if (optionName.contains("=")) { |
| 142 | + String[] parts = optionName.split("=", 2); |
| 143 | + optionName = parts[0]; |
| 144 | + nextArg = parts[1]; |
| 145 | + } else { |
| 146 | + if (i + 1 >= args.length) continue; // Skip if no next arg |
| 147 | + nextArg = args[i + 1]; |
| 148 | + i += 1; // skip arg |
| 149 | + } |
| 150 | + |
| 151 | + // Only parse these options in service mode |
| 152 | + switch (optionName) { |
| 153 | + case "--model", "-m" -> modelPath = Paths.get(nextArg); |
| 154 | + case "--max-tokens", "-n" -> maxTokens = Integer.parseInt(nextArg); |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + require(modelPath != null, "Missing argument: --model <path> is required"); |
| 159 | + |
| 160 | + // Create service-mode Options object |
| 161 | + return new Options( |
| 162 | + modelPath, |
| 163 | + null, // prompt - not used in service |
| 164 | + null, // systemPrompt - handled per request |
| 165 | + null, // suffix - not used |
| 166 | + false, // interactive - not used in service |
| 167 | + 0.7f, // temperature - default, overridden per request |
| 168 | + 0.9f, // topp - default, overridden per request |
| 169 | + System.nanoTime(), // seed - default |
| 170 | + maxTokens, |
| 171 | + false, // stream - handled per request |
| 172 | + false, // echo - not used in service |
| 173 | + getDefaultTornadoVM(), |
| 174 | + true |
| 175 | + ); |
127 | 176 | }
|
128 | 177 | }
|
0 commit comments