Skip to content

Commit 07a9a25

Browse files
committed
feat(protocol): add typed descriptor models
1 parent d44c84b commit 07a9a25

6 files changed

Lines changed: 159 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2018-present, easy-4-java.
3+
* Licensed under the Apache License, Version 2.0.
4+
*/
5+
package io.github.easy4j.kimi.model;
6+
7+
import java.util.Map;
8+
import tools.jackson.databind.JsonNode;
9+
10+
public final class KimiError {
11+
private final JsonNode code;
12+
private final String message;
13+
private final JsonNode data;
14+
private final Map<String, JsonNode> extensions;
15+
16+
KimiError(JsonNode code, String message, JsonNode data, Map<String, JsonNode> extensions) {
17+
this.code = code == null ? null : code.deepCopy();
18+
this.message = message;
19+
this.data = data == null ? null : data.deepCopy();
20+
this.extensions = KimiSession.immutableExtensions(extensions);
21+
}
22+
23+
public JsonNode getCode() { return code == null ? null : code.deepCopy(); }
24+
public String getMessage() { return message; }
25+
public JsonNode getData() { return data == null ? null : data.deepCopy(); }
26+
public Map<String, JsonNode> getExtensions() { return extensions; }
27+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2018-present, easy-4-java.
3+
* Licensed under the Apache License, Version 2.0.
4+
*/
5+
package io.github.easy4j.kimi.model;
6+
7+
import java.util.Map;
8+
import tools.jackson.databind.JsonNode;
9+
10+
public final class KimiMode {
11+
private final String id;
12+
private final String name;
13+
private final Map<String, JsonNode> extensions;
14+
15+
KimiMode(String id, String name, Map<String, JsonNode> extensions) {
16+
this.id = id; this.name = name;
17+
this.extensions = KimiSession.immutableExtensions(extensions);
18+
}
19+
public String getId() { return id; }
20+
public String getName() { return name; }
21+
public Map<String, JsonNode> getExtensions() { return extensions; }
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2018-present, easy-4-java.
3+
* Licensed under the Apache License, Version 2.0.
4+
*/
5+
package io.github.easy4j.kimi.model;
6+
7+
import java.util.Map;
8+
import tools.jackson.databind.JsonNode;
9+
10+
public final class KimiModel {
11+
private final String id;
12+
private final String name;
13+
private final Map<String, JsonNode> extensions;
14+
15+
KimiModel(String id, String name, Map<String, JsonNode> extensions) {
16+
this.id = id; this.name = name;
17+
this.extensions = KimiSession.immutableExtensions(extensions);
18+
}
19+
public String getId() { return id; }
20+
public String getName() { return name; }
21+
public Map<String, JsonNode> getExtensions() { return extensions; }
22+
}

‎src/main/java/io/github/easy4j/kimi/model/KimiProtocolMapper.java‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,45 @@ public KimiPromptResult readPromptResult(String json) {
9090
extensions);
9191
}
9292

93+
public KimiToolCall readToolCall(String json) {
94+
JsonNode root = readObject(json, "Kimi tool call");
95+
return new KimiToolCall(root.path("id").asText(null),
96+
root.path("name").asText(null),
97+
root.path("arguments").deepCopy(),
98+
extensions(root, "id", "name", "arguments"));
99+
}
100+
101+
public KimiError readError(String json) {
102+
JsonNode root = readObject(json, "Kimi error");
103+
JsonNode code = root.path("code").isMissingNode() ? null : root.path("code").deepCopy();
104+
JsonNode data = root.path("data").isMissingNode() ? null : root.path("data").deepCopy();
105+
return new KimiError(code,
106+
root.path("message").asText(null),
107+
data,
108+
extensions(root, "code", "message", "data"));
109+
}
110+
111+
public KimiModel readModel(String json) {
112+
JsonNode root = readObject(json, "Kimi model");
113+
return new KimiModel(root.path("id").asText(null),
114+
root.path("name").asText(null),
115+
extensions(root, "id", "name"));
116+
}
117+
118+
public KimiMode readMode(String json) {
119+
JsonNode root = readObject(json, "Kimi mode");
120+
return new KimiMode(root.path("id").asText(null),
121+
root.path("name").asText(null),
122+
extensions(root, "id", "name"));
123+
}
124+
125+
public KimiProvider readProvider(String json) {
126+
JsonNode root = readObject(json, "Kimi provider");
127+
return new KimiProvider(root.path("id").asText(null),
128+
root.path("name").asText(null),
129+
extensions(root, "id", "name"));
130+
}
131+
93132
private JsonNode readObject(String json, String what) {
94133
if (json == null) {
95134
throw new NullPointerException("json");
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2018-present, easy-4-java.
3+
* Licensed under the Apache License, Version 2.0.
4+
*/
5+
package io.github.easy4j.kimi.model;
6+
7+
import java.util.Map;
8+
import tools.jackson.databind.JsonNode;
9+
10+
public final class KimiProvider {
11+
private final String id;
12+
private final String name;
13+
private final Map<String, JsonNode> extensions;
14+
15+
KimiProvider(String id, String name, Map<String, JsonNode> extensions) {
16+
this.id = id; this.name = name;
17+
this.extensions = KimiSession.immutableExtensions(extensions);
18+
}
19+
public String getId() { return id; }
20+
public String getName() { return name; }
21+
public Map<String, JsonNode> getExtensions() { return extensions; }
22+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2018-present, easy-4-java.
3+
* Licensed under the Apache License, Version 2.0.
4+
*/
5+
package io.github.easy4j.kimi.model;
6+
7+
import java.util.Map;
8+
import tools.jackson.databind.JsonNode;
9+
10+
public final class KimiToolCall {
11+
private final String id;
12+
private final String name;
13+
private final JsonNode arguments;
14+
private final Map<String, JsonNode> extensions;
15+
16+
KimiToolCall(String id, String name, JsonNode arguments, Map<String, JsonNode> extensions) {
17+
this.id = id;
18+
this.name = name;
19+
this.arguments = arguments == null ? null : arguments.deepCopy();
20+
this.extensions = KimiSession.immutableExtensions(extensions);
21+
}
22+
23+
public String getId() { return id; }
24+
public String getName() { return name; }
25+
public JsonNode getArguments() { return arguments == null ? null : arguments.deepCopy(); }
26+
public Map<String, JsonNode> getExtensions() { return extensions; }
27+
}

0 commit comments

Comments
 (0)