fix: support freeform stopReason in sampling (#327)
- Add string values and JsonCreator method to StopReason enum
- Map unknown stop reason values to UNKNOWN constant for forward compatibility
- Add test coverage for unknown stop reason deserialization
Spec: f5ccad944f/schema/2024-11-05/schema.ts (L807)
Resolves #328
This commit is contained in:
parent
6c330db5ad
commit
aff24fdf2f
1 changed files with 37 additions and 3 deletions
|
|
@ -6,10 +6,12 @@ package io.modelcontextprotocol.spec;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
|
@ -1136,9 +1138,24 @@ public final class McpSchema {
|
|||
@JsonProperty("stopReason") StopReason stopReason) {
|
||||
|
||||
public enum StopReason {
|
||||
@JsonProperty("endTurn") END_TURN,
|
||||
@JsonProperty("stopSequence") STOP_SEQUENCE,
|
||||
@JsonProperty("maxTokens") MAX_TOKENS
|
||||
@JsonProperty("endTurn") END_TURN("endTurn"),
|
||||
@JsonProperty("stopSequence") STOP_SEQUENCE("stopSequence"),
|
||||
@JsonProperty("maxTokens") MAX_TOKENS("maxTokens"),
|
||||
@JsonProperty("unknown") UNKNOWN("unknown");
|
||||
|
||||
private final String value;
|
||||
|
||||
StopReason(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
private static StopReason of(String value) {
|
||||
return Arrays.stream(StopReason.values())
|
||||
.filter(stopReason -> stopReason.value.equals(value))
|
||||
.findFirst()
|
||||
.orElse(StopReason.UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue