Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/main/java/com/llmproxy/model/TaskType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.llmproxy.model;

import java.util.Map;
import java.util.HashMap;

public enum TaskType {
TEXT_GENERATION("text_generation"),
SUMMARIZATION("summarization"),
Expand All @@ -9,6 +12,15 @@ public enum TaskType {

private final String value;

// Cache for fromString method to improve performance
private static final Map<String, TaskType> STRING_TO_ENUM_MAP = new HashMap<>();

static {
for (TaskType type : values()) {
STRING_TO_ENUM_MAP.put(type.value.toLowerCase(), type);
}
}

TaskType(String value) {
this.value = value;
}
Expand All @@ -18,16 +30,15 @@ public String getValue() {
}

public static TaskType fromString(String text) {
for (TaskType type : TaskType.values()) {
if (type.value.equalsIgnoreCase(text)) {
return type;
}
if (text == null) {
return OTHER; // Or throw IllegalArgumentException, depending on desired behavior
}
return OTHER;
TaskType type = STRING_TO_ENUM_MAP.get(text.toLowerCase());
return type != null ? type : OTHER;
}

@Override
public String toString() {
return value;
}
}
}