Skip to content

Commit 7913423

Browse files
authored
feat: 优化泛型定义;添加模型测试参数获取 (jetlinks#114)
1 parent b928b6a commit 7913423

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

jetlinks-sdk-api/src/main/java/org/jetlinks/sdk/server/ai/InternalCVTaskTarget.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import lombok.AllArgsConstructor;
44
import lombok.Getter;
55
import lombok.NoArgsConstructor;
6+
import lombok.Setter;
67
import org.hswebframework.web.i18n.LocaleUtils;
78
import org.jetlinks.sdk.server.ai.cv.ComputerVisionCommand;
89
import org.jetlinks.sdk.server.ai.cv.ObjectDetectionCommand;
@@ -87,6 +88,7 @@ public static SimpleComputerVisionCommand createCommand(TaskTarget target) {
8788
return new SimpleComputerVisionCommand(target.getValue());
8889
}
8990

91+
@Setter
9092
@Getter
9193
@AllArgsConstructor
9294
@NoArgsConstructor

jetlinks-sdk-api/src/main/java/org/jetlinks/sdk/server/ai/SimpleGenericAiOutput.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import lombok.Getter;
44
import lombok.Setter;
5-
import lombok.SneakyThrows;
65
import org.apache.commons.collections4.CollectionUtils;
76
import org.jetlinks.core.utils.SerializeUtils;
87
import org.jetlinks.sdk.server.file.FileData;
@@ -19,7 +18,7 @@
1918

2019
@Getter
2120
@Setter
22-
public abstract class SimpleGenericAiOutput<T extends FileData> extends GenericAiOutput<SimpleGenericAiOutput<T>> {
21+
public abstract class SimpleGenericAiOutput<T extends FileData, SELF extends SimpleGenericAiOutput<T, SELF>> extends GenericAiOutput<SELF> {
2322

2423
private Integer hitValue;
2524

@@ -83,7 +82,7 @@ public void writeExternal(ObjectOutput out) throws IOException {
8382
}
8483

8584
@Override
86-
public void readExternal(ObjectInput in) throws IOException,ClassNotFoundException {
85+
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
8786
hitValue = readNullable(in, () -> {
8887
try {
8988
return in.readInt();

jetlinks-sdk-api/src/main/java/org/jetlinks/sdk/server/ai/SimpleImageGenericAiOutput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.function.Supplier;
66

77

8-
public class SimpleImageGenericAiOutput extends SimpleGenericAiOutput<ImageData> {
8+
public class SimpleImageGenericAiOutput extends SimpleGenericAiOutput<ImageData, SimpleImageGenericAiOutput> {
99

1010
public Supplier<ImageData> newFileDataSupplier() {
1111
return ImageData::new;

jetlinks-sdk-api/src/main/java/org/jetlinks/sdk/server/ai/cv/ObjectDetectionResult.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
public class ObjectDetectionResult extends AiCommandResult<ObjectDetectionResult> {
2323

2424
public static final String IMAGES = "images";
25+
public static final String OBJECTS = "objects";
2526

2627
@Schema(title = "图像数据")
2728
private List<ImageData> images;
@@ -39,7 +40,7 @@ public List<? extends FileData> files() {
3940

4041
@Override
4142
public Map<String, Object> schemaMap() {
42-
return Collections.singletonMap("objects", objects);
43+
return Collections.singletonMap(OBJECTS, objects);
4344
}
4445

4546
@Override

jetlinks-sdk-api/src/main/java/org/jetlinks/sdk/server/ai/model/AiModelPortrait.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import org.jetlinks.core.metadata.DataType;
99
import org.jetlinks.core.utils.SerializeUtils;
1010

11-
import javax.annotation.Nullable;
1211
import java.io.Externalizable;
1312
import java.io.IOException;
1413
import java.io.ObjectInput;
@@ -25,6 +24,9 @@ public class AiModelPortrait implements Externalizable {
2524
@Schema(description = "入参及文档")
2625
private ConfigMetadata input;
2726

27+
@Schema(description = "测试入参及文档")
28+
private ConfigMetadata testInput;
29+
2830
@Deprecated
2931
@Schema(description = "出参")
3032
private DataType output;
@@ -36,6 +38,7 @@ public class AiModelPortrait implements Externalizable {
3638
public void writeExternal(ObjectOutput out) throws IOException {
3739
out.writeByte(1);
3840
SerializeUtils.writeObject(input, out);
41+
SerializeUtils.writeObject(testInput, out);
3942
SerializeUtils.writeObject(output, out);
4043
SerializeUtils.writeKeyValue(others, out);
4144
}
@@ -45,6 +48,7 @@ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundExcept
4548
byte version = in.readByte();
4649
if (version == 1) {
4750
input = (ConfigMetadata) SerializeUtils.readObject(in);
51+
testInput = (ConfigMetadata) SerializeUtils.readObject(in);
4852
output = (DataType) SerializeUtils.readObject(in);
4953
others = SerializeUtils.readMap(in, Maps::newHashMapWithExpectedSize);
5054
}

0 commit comments

Comments
 (0)