-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
Description
Issue
Currently, the keep-alive option is handled inconsistently between models.
- In OllamaEmbeddingModel, a duration parser is used to process the keep-alive option.
- In OllamaChatModel, the raw user input is passed directly without parsing.
Lines 203 to 232 in d83c826
| public static class DurationParser { | |
| private static final Pattern PATTERN = Pattern.compile("(-?\\d+)(ms|s|m|h)"); | |
| public static Duration parse(String input) { | |
| if (!StringUtils.hasText(input)) { | |
| return null; | |
| } | |
| Matcher matcher = PATTERN.matcher(input); | |
| if (matcher.matches()) { | |
| long value = Long.parseLong(matcher.group(1)); | |
| String unit = matcher.group(2); | |
| return switch (unit) { | |
| case "ms" -> Duration.ofMillis(value); | |
| case "s" -> Duration.ofSeconds(value); | |
| case "m" -> Duration.ofMinutes(value); | |
| case "h" -> Duration.ofHours(value); | |
| default -> throw new IllegalArgumentException("Unsupported time unit: " + unit); | |
| }; | |
| } | |
| else { | |
| throw new IllegalArgumentException("Invalid duration format: " + input); | |
| } | |
| } | |
| } |
Proposed Solution
For better consistency, we should either:
- Remove the duration parser from OllamaEmbeddingModel, or
- Apply the duration parser to OllamaChatModel as well.