Skip to content

Commit 7bab2d4

Browse files
Add serviceMode Options field and parseServiceOptions method
1 parent ce65bfd commit 7bab2d4

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

src/main/java/org/beehive/gpullama3/Options.java

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import java.nio.file.Paths;
66

77
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) {
99

1010
public static final int DEFAULT_MAX_TOKENS = 1024;
1111

1212
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+
}
1417
require(0 <= temperature, "Invalid argument: --temperature must be non-negative");
1518
require(0 <= topp && topp <= 1, "Invalid argument: --top-p must be within [0, 1]");
1619
}
@@ -61,7 +64,7 @@ public static Options getDefaultOptions() {
6164
boolean echo = false;
6265
boolean useTornadoVM = getDefaultTornadoVM();
6366

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);
6568
}
6669

6770
public static Options parseOptions(String[] args) {
@@ -123,6 +126,52 @@ public static Options parseOptions(String[] args) {
123126
useTornadovm = getDefaultTornadoVM();
124127
}
125128

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+
);
127176
}
128177
}

0 commit comments

Comments
 (0)