refactor: update code and unit test cases (#3)
* refact: update unit test case * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update * update --------- Co-authored-by: Junhui Huang <hjh604@outlook.com>
This commit is contained in:
parent
285baa7082
commit
4745bbdead
144 changed files with 4919 additions and 8551 deletions
|
|
@ -348,6 +348,7 @@ public class ZaiClient extends AbstractClientBaseService {
|
|||
* @return the wrapped response containing either success data or error information
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <Data, Param, TReq extends ClientRequest<Param>, TResp extends ClientResponse<Data>> TResp executeRequest(
|
||||
TReq request, RequestSupplier<Param, Data> requestSupplier, Class<TResp> tRespClass) {
|
||||
Single<Data> apiCall = requestSupplier.get((Param) request);
|
||||
|
|
@ -357,14 +358,14 @@ public class ZaiClient extends AbstractClientBaseService {
|
|||
// Execute the API call synchronously
|
||||
Data response = execute(apiCall);
|
||||
tResp.setCode(200);
|
||||
tResp.setMsg("Call successful");
|
||||
tResp.setMsg("Call Successful");
|
||||
tResp.setData(response);
|
||||
tResp.setSuccess(true);
|
||||
}
|
||||
catch (ZAiHttpException e) {
|
||||
logger.error("API request failed with business error", e);
|
||||
logger.error("API request failed with call error", e);
|
||||
tResp.setCode(e.statusCode);
|
||||
tResp.setMsg("Business error");
|
||||
tResp.setMsg("Call Failed");
|
||||
tResp.setSuccess(false);
|
||||
ChatError chatError = new ChatError();
|
||||
chatError.setCode(Integer.parseInt(e.code));
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ package ai.z.openapi.core;
|
|||
* This class provides centralized access to: - API base URLs - Model identifiers for
|
||||
* different AI capabilities - Invocation method constants
|
||||
*
|
||||
* @author Z.AI SDK Team
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public final class Constants {
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,12 @@ import ai.z.openapi.service.model.ZAiError;
|
|||
import ai.z.openapi.service.model.ZAiHttpException;
|
||||
import ai.z.openapi.utils.FlowableRequestSupplier;
|
||||
import ai.z.openapi.utils.RequestSupplier;
|
||||
import ai.z.openapi.utils.StringUtils;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.reactivex.BackpressureStrategy;
|
||||
import io.reactivex.Flowable;
|
||||
import io.reactivex.Single;
|
||||
import java.util.Objects;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
@ -85,14 +87,18 @@ public abstract class AbstractClientBaseService {
|
|||
}
|
||||
catch (HttpException e) {
|
||||
logger.error("HTTP exception: {}", e.getMessage());
|
||||
try {
|
||||
if (e.response() == null || e.response().errorBody() == null) {
|
||||
throw e;
|
||||
}
|
||||
String errorBody = e.response().errorBody().string();
|
||||
|
||||
try (ResponseBody responseBody = Objects.requireNonNull(e.response()).errorBody()) {
|
||||
if (responseBody == null) {
|
||||
throw e;
|
||||
}
|
||||
String errorBody = responseBody.string();
|
||||
if (StringUtils.isEmpty(errorBody)) {
|
||||
throw e;
|
||||
}
|
||||
ZAiError error = mapper.readValue(errorBody, ZAiError.class);
|
||||
|
||||
throw new ZAiHttpException(error, e, e.code());
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import lombok.EqualsAndHashCode;
|
|||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public class AgentServiceImpl implements AgentService {
|
|||
|
||||
@Override
|
||||
public ChatCompletionResponse createAgentCompletion(AgentsCompletionRequest request) {
|
||||
validateParams(request);
|
||||
if (request.getStream()) {
|
||||
return streamAgentCompletion(request);
|
||||
}
|
||||
|
|
@ -49,4 +50,16 @@ public class AgentServiceImpl implements AgentService {
|
|||
return this.zAiClient.executeRequest(request, supplier, ChatCompletionResponse.class);
|
||||
}
|
||||
|
||||
private void validateParams(AgentsCompletionRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
if (request.getMessages() == null || request.getMessages().isEmpty()) {
|
||||
throw new IllegalArgumentException("request messages cannot be null or empty");
|
||||
}
|
||||
if (request.getAgentId() == null) {
|
||||
throw new IllegalArgumentException("request agent_id cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,9 +12,7 @@ import lombok.EqualsAndHashCode;
|
|||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Request parameters for agent completion API calls. This class contains all the
|
||||
|
|
@ -32,7 +30,7 @@ public class AgentsCompletionRequest extends CommonRequest implements ClientRequ
|
|||
* Agent ID
|
||||
*/
|
||||
@JsonProperty("agent_id")
|
||||
private String agent_id;
|
||||
private String agentId;
|
||||
|
||||
/**
|
||||
* Message body
|
||||
|
|
@ -55,6 +53,6 @@ public class AgentsCompletionRequest extends CommonRequest implements ClientRequ
|
|||
* @return
|
||||
*/
|
||||
@JsonProperty("custom_variables")
|
||||
private ObjectNode custom_variables;
|
||||
private ObjectNode customVariables;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
package ai.z.openapi.service.assistant;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.assistant.AssistantCompletionDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the completion data returned by an assistant.
|
||||
*/
|
||||
@JsonDeserialize(using = AssistantCompletionDeserializer.class)
|
||||
public class AssistantCompletion extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AssistantCompletion {
|
||||
|
||||
/**
|
||||
* Request ID
|
||||
|
|
@ -42,7 +40,7 @@ public class AssistantCompletion extends ObjectNode {
|
|||
* Request creation time, Unix timestamp
|
||||
*/
|
||||
@JsonProperty("created")
|
||||
private int created;
|
||||
private Long created;
|
||||
|
||||
/**
|
||||
* Return status, including: `completed` indicates generation finished, `in_progress`
|
||||
|
|
@ -75,180 +73,4 @@ public class AssistantCompletion extends ObjectNode {
|
|||
@JsonProperty("usage")
|
||||
private CompletionUsage usage;
|
||||
|
||||
public AssistantCompletion() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public AssistantCompletion(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.has("id")) {
|
||||
this.setId(objectNode.get("id").asText());
|
||||
}
|
||||
else {
|
||||
this.setId(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("conversation_id")) {
|
||||
this.setConversationId(objectNode.get("conversation_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setConversationId(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("assistant_id")) {
|
||||
this.setAssistantId(objectNode.get("assistant_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setAssistantId(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("created")) {
|
||||
this.setCreated(objectNode.get("created").asInt());
|
||||
}
|
||||
else {
|
||||
this.setCreated(0);
|
||||
}
|
||||
|
||||
if (objectNode.has("status")) {
|
||||
this.setStatus(objectNode.get("status").asText());
|
||||
|
||||
}
|
||||
else {
|
||||
this.setStatus(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("last_error")) {
|
||||
this.setLastError(objectMapper.convertValue(objectNode.get("last_error"), ErrorInfo.class));
|
||||
}
|
||||
else {
|
||||
this.setLastError(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("choices")) {
|
||||
List<AssistantChoice> choices1 = objectMapper.convertValue(objectNode.get("choices"),
|
||||
new com.fasterxml.jackson.core.type.TypeReference<List<AssistantChoice>>() {
|
||||
});
|
||||
|
||||
this.setChoices(choices1);
|
||||
|
||||
}
|
||||
else {
|
||||
this.setChoices(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("metadata")) {
|
||||
this.setMetadata(objectMapper.convertValue(objectNode.get("metadata"), Map.class));
|
||||
}
|
||||
else {
|
||||
this.setMetadata(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("usage")) {
|
||||
this.setUsage(objectMapper.convertValue(objectNode.get("usage"), CompletionUsage.class));
|
||||
}
|
||||
else {
|
||||
this.setUsage(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
// Getters and Setters
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
this.put("id", id);
|
||||
}
|
||||
|
||||
public String getConversationId() {
|
||||
return conversationId;
|
||||
}
|
||||
|
||||
public void setConversationId(String conversationId) {
|
||||
this.conversationId = conversationId;
|
||||
this.put("conversation_id", conversationId);
|
||||
}
|
||||
|
||||
public String getAssistantId() {
|
||||
return assistantId;
|
||||
}
|
||||
|
||||
public void setAssistantId(String assistantId) {
|
||||
this.assistantId = assistantId;
|
||||
this.put("assistant_id", assistantId);
|
||||
}
|
||||
|
||||
public int getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(int created) {
|
||||
this.created = created;
|
||||
this.put("created", created);
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
this.put("status", status);
|
||||
}
|
||||
|
||||
public ErrorInfo getLastError() {
|
||||
return lastError;
|
||||
}
|
||||
|
||||
public void setLastError(ErrorInfo lastError) {
|
||||
this.lastError = lastError;
|
||||
this.putPOJO("last_error", lastError);
|
||||
}
|
||||
|
||||
public List<AssistantChoice> getChoices() {
|
||||
return choices;
|
||||
}
|
||||
|
||||
public void setChoices(List<AssistantChoice> choices) {
|
||||
this.choices = choices;
|
||||
ArrayNode jsonNodes = this.putArray("choices");
|
||||
if (choices == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (AssistantChoice choice : choices) {
|
||||
jsonNodes.add(choice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public void setMetadata(Map<String, Object> metadata) {
|
||||
this.metadata = metadata;
|
||||
this.putPOJO("metadata", metadata);
|
||||
}
|
||||
|
||||
public CompletionUsage getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public void setUsage(CompletionUsage usage) {
|
||||
this.usage = usage;
|
||||
this.putPOJO("usage", usage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
package ai.z.openapi.service.assistant;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.assistant.CompletionUsageDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the usage statistics for a completion.
|
||||
*/
|
||||
@JsonDeserialize(using = CompletionUsageDeserializer.class)
|
||||
public class CompletionUsage extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CompletionUsage {
|
||||
|
||||
/**
|
||||
* Number of tokens in the input (prompt).
|
||||
|
|
@ -35,67 +34,4 @@ public class CompletionUsage extends ObjectNode {
|
|||
@JsonProperty("total_tokens")
|
||||
private int totalTokens;
|
||||
|
||||
public CompletionUsage() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public CompletionUsage(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("prompt_tokens") != null) {
|
||||
this.setPromptTokens(objectNode.get("prompt_tokens").asInt());
|
||||
}
|
||||
else {
|
||||
this.setPromptTokens(0);
|
||||
}
|
||||
if (objectNode.get("completion_tokens") != null) {
|
||||
this.setCompletionTokens(objectNode.get("completion_tokens").asInt());
|
||||
}
|
||||
else {
|
||||
this.setCompletionTokens(0);
|
||||
}
|
||||
if (objectNode.get("total_tokens") != null) {
|
||||
this.setTotalTokens(objectNode.get("total_tokens").asInt());
|
||||
}
|
||||
else {
|
||||
this.setTotalTokens(0);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
// Getters and Setters
|
||||
|
||||
public int getPromptTokens() {
|
||||
return promptTokens;
|
||||
}
|
||||
|
||||
public void setPromptTokens(int promptTokens) {
|
||||
this.promptTokens = promptTokens;
|
||||
this.put("prompt_tokens", promptTokens);
|
||||
}
|
||||
|
||||
public int getCompletionTokens() {
|
||||
return completionTokens;
|
||||
}
|
||||
|
||||
public void setCompletionTokens(int completionTokens) {
|
||||
this.completionTokens = completionTokens;
|
||||
this.put("completion_tokens", completionTokens);
|
||||
}
|
||||
|
||||
public int getTotalTokens() {
|
||||
return totalTokens;
|
||||
}
|
||||
|
||||
public void setTotalTokens(int totalTokens) {
|
||||
this.totalTokens = totalTokens;
|
||||
this.put("total_tokens", totalTokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
package ai.z.openapi.service.assistant;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.assistant.ErrorInfoDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents error information.
|
||||
*/
|
||||
@JsonDeserialize(using = ErrorInfoDeserializer.class)
|
||||
public class ErrorInfo extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ErrorInfo {
|
||||
|
||||
/**
|
||||
* Error code.
|
||||
|
|
@ -29,52 +28,4 @@ public class ErrorInfo extends ObjectNode {
|
|||
@JsonProperty("message")
|
||||
private String message;
|
||||
|
||||
public ErrorInfo() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ErrorInfo(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
|
||||
if (objectNode.get("code") != null) {
|
||||
this.setCode(objectNode.get("code").asText());
|
||||
}
|
||||
else {
|
||||
this.setCode(null);
|
||||
}
|
||||
if (objectNode.get("message") != null) {
|
||||
this.setMessage(objectNode.get("message").asText());
|
||||
}
|
||||
else {
|
||||
this.setMessage(null);
|
||||
}
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
this.put("code", code);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
this.put("message", message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public class AudioServiceImpl implements AudioService {
|
|||
|
||||
@Override
|
||||
public AudioSpeechApiResponse createSpeech(AudioSpeechRequest request) {
|
||||
validateSpeechParams(request);
|
||||
RequestSupplier<AudioSpeechRequest, java.io.File> supplier = (params) -> {
|
||||
try {
|
||||
Single<ResponseBody> responseBody = audioApi.audioSpeech(params);
|
||||
|
|
@ -61,6 +62,7 @@ public class AudioServiceImpl implements AudioService {
|
|||
|
||||
@Override
|
||||
public AudioCustomizationApiResponse createCustomSpeech(AudioCustomizationRequest request) {
|
||||
validateCustomSpeechParams(request);
|
||||
RequestSupplier<AudioCustomizationRequest, java.io.File> supplier = (params) -> {
|
||||
try {
|
||||
java.io.File voiceFile = params.getVoiceData();
|
||||
|
|
@ -117,6 +119,7 @@ public class AudioServiceImpl implements AudioService {
|
|||
|
||||
@Override
|
||||
public ChatCompletionResponse createTranscription(AudioTranscriptionsRequest request) {
|
||||
validateTranscriptionParams(request);
|
||||
if (request.getStream()) {
|
||||
return createTranscriptionStream(request);
|
||||
}
|
||||
|
|
@ -195,6 +198,48 @@ public class AudioServiceImpl implements AudioService {
|
|||
return this.zAiClient.executeRequest(request, supplier, ChatCompletionResponse.class);
|
||||
}
|
||||
|
||||
private void validateSpeechParams(AudioSpeechRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
if (request.getModel() == null) {
|
||||
throw new IllegalArgumentException("request model cannot be null");
|
||||
}
|
||||
if (request.getInput() == null || request.getInput().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("request input cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCustomSpeechParams(AudioCustomizationRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
if (request.getModel() == null) {
|
||||
throw new IllegalArgumentException("request model cannot be null");
|
||||
}
|
||||
if (request.getInput() == null || request.getInput().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("request input cannot be null or empty");
|
||||
}
|
||||
if (request.getVoiceData() == null) {
|
||||
throw new IllegalArgumentException("request voice data cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateTranscriptionParams(AudioTranscriptionsRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
if (request.getModel() == null) {
|
||||
throw new IllegalArgumentException("request model cannot be null");
|
||||
}
|
||||
if (request.getFile() == null) {
|
||||
throw new IllegalArgumentException("request file cannot be null");
|
||||
}
|
||||
if (!request.getFile().exists()) {
|
||||
throw new IllegalArgumentException("request file does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
private void writeResponseBodyToFile(ResponseBody body, java.io.File file) {
|
||||
try (InputStream inputStream = body.byteStream();
|
||||
OutputStream outputStream = Files.newOutputStream(file.toPath())) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
package ai.z.openapi.service.batches;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Batch {
|
||||
|
||||
@JsonProperty("id")
|
||||
|
|
@ -15,7 +21,7 @@ public class Batch {
|
|||
private String completionWindow;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private long createdAt;
|
||||
private Long createdAt;
|
||||
|
||||
@JsonProperty("endpoint")
|
||||
private String endpoint;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ import java.util.Map;
|
|||
@EqualsAndHashCode(callSuper = false)
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class BatchCreateParams implements ClientRequest<BatchCreateParams> {
|
||||
|
||||
/**
|
||||
|
|
@ -42,15 +45,4 @@ public class BatchCreateParams implements ClientRequest<BatchCreateParams> {
|
|||
@JsonProperty("metadata")
|
||||
private Map<String, String> metadata;
|
||||
|
||||
public BatchCreateParams() {
|
||||
}
|
||||
|
||||
public BatchCreateParams(String completionWindow, String endpoint, String inputFileId,
|
||||
Map<String, String> metadata) {
|
||||
this.completionWindow = completionWindow;
|
||||
this.endpoint = endpoint;
|
||||
this.inputFileId = inputFileId;
|
||||
this.metadata = metadata;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,15 @@ package ai.z.openapi.service.batches;
|
|||
|
||||
import ai.z.openapi.core.model.ClientResponse;
|
||||
import ai.z.openapi.service.model.ChatError;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class BatchResponse implements ClientResponse<Batch> {
|
||||
|
||||
private int code;
|
||||
|
|
|
|||
|
|
@ -21,24 +21,28 @@ public class BatchServiceImpl implements BatchService {
|
|||
|
||||
@Override
|
||||
public BatchResponse createBatch(BatchCreateParams batchCreateParams) {
|
||||
validateCreateBatchParams(batchCreateParams);
|
||||
RequestSupplier<BatchCreateParams, Batch> supplier = batchesApi::batchesCreate;
|
||||
return this.zAiClient.executeRequest(batchCreateParams, supplier, BatchResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchResponse retrieveBatch(BatchRequest request) {
|
||||
validateBatchRequest(request);
|
||||
RequestSupplier<BatchRequest, Batch> supplier = (params) -> batchesApi.batchesRetrieve(params.getBatchId());
|
||||
return this.zAiClient.executeRequest(request, supplier, BatchResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchResponse retrieveBatch(String batchId) {
|
||||
validateBatchId(batchId);
|
||||
BatchRequest request = BatchRequest.builder().batchId(batchId).build();
|
||||
return retrieveBatch(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
public QueryBatchResponse listBatches(QueryBatchRequest queryBatchRequest) {
|
||||
validateQueryBatchRequest(queryBatchRequest);
|
||||
RequestSupplier<QueryBatchRequest, BatchPage> supplier = (params) -> batchesApi.batchesList(params.getAfter(),
|
||||
params.getLimit());
|
||||
return this.zAiClient.executeRequest(queryBatchRequest, supplier, QueryBatchResponse.class);
|
||||
|
|
@ -46,14 +50,73 @@ public class BatchServiceImpl implements BatchService {
|
|||
|
||||
@Override
|
||||
public BatchResponse cancelBatch(BatchRequest request) {
|
||||
validateBatchRequest(request);
|
||||
RequestSupplier<BatchRequest, Batch> supplier = (params) -> batchesApi.batchesCancel(params.getBatchId());
|
||||
return this.zAiClient.executeRequest(request, supplier, BatchResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BatchResponse cancelBatch(String batchId) {
|
||||
validateBatchId(batchId);
|
||||
BatchRequest request = BatchRequest.builder().batchId(batchId).build();
|
||||
return cancelBatch(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates BatchCreateParams parameters
|
||||
* @param batchCreateParams the batch creation parameters to validate
|
||||
* @throws IllegalArgumentException if validation fails
|
||||
*/
|
||||
private void validateCreateBatchParams(BatchCreateParams batchCreateParams) {
|
||||
if (batchCreateParams == null) {
|
||||
throw new IllegalArgumentException("BatchCreateParams cannot be null");
|
||||
}
|
||||
if (batchCreateParams.getEndpoint() == null || batchCreateParams.getEndpoint().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Endpoint cannot be null or empty");
|
||||
}
|
||||
if (batchCreateParams.getInputFileId() == null || batchCreateParams.getInputFileId().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Input file ID cannot be null or empty");
|
||||
}
|
||||
if (batchCreateParams.getCompletionWindow() == null
|
||||
|| batchCreateParams.getCompletionWindow().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Completion window cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates BatchRequest parameters
|
||||
* @param request the batch request to validate
|
||||
* @throws IllegalArgumentException if validation fails
|
||||
*/
|
||||
private void validateBatchRequest(BatchRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("BatchRequest cannot be null");
|
||||
}
|
||||
if (request.getBatchId() == null || request.getBatchId().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Batch ID cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates batch ID parameter
|
||||
* @param batchId the batch ID to validate
|
||||
* @throws IllegalArgumentException if validation fails
|
||||
*/
|
||||
private void validateBatchId(String batchId) {
|
||||
if (batchId == null || batchId.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Batch ID cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates QueryBatchRequest parameters
|
||||
* @param queryBatchRequest the query batch request to validate
|
||||
* @throws IllegalArgumentException if validation fails
|
||||
*/
|
||||
private void validateQueryBatchRequest(QueryBatchRequest queryBatchRequest) {
|
||||
if (queryBatchRequest == null) {
|
||||
throw new IllegalArgumentException("QueryBatchRequest cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,9 +2,15 @@ package ai.z.openapi.service.batches;
|
|||
|
||||
import ai.z.openapi.core.model.ClientResponse;
|
||||
import ai.z.openapi.service.model.ChatError;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class QueryBatchResponse implements ClientResponse<BatchPage> {
|
||||
|
||||
private int code;
|
||||
|
|
|
|||
|
|
@ -28,10 +28,7 @@ public class ChatServiceImpl implements ChatService {
|
|||
|
||||
@Override
|
||||
public ChatCompletionResponse createChatCompletion(ChatCompletionCreateParams request) {
|
||||
String paramMsg = validateParams(request);
|
||||
if (StringUtils.isNotEmpty(paramMsg)) {
|
||||
return new ChatCompletionResponse(-100, String.format("invalid param: %s", paramMsg));
|
||||
}
|
||||
validateParams(request);
|
||||
if (request.getStream()) {
|
||||
return streamChatCompletion(request);
|
||||
}
|
||||
|
|
@ -65,17 +62,16 @@ public class ChatServiceImpl implements ChatService {
|
|||
return this.zAiClient.executeRequest(request, supplier, ChatCompletionResponse.class);
|
||||
}
|
||||
|
||||
private String validateParams(ChatCompletionCreateParams request) {
|
||||
private void validateParams(ChatCompletionCreateParams request) {
|
||||
if (request == null) {
|
||||
return "request can not be null";
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
if (request.getMessages() == null || request.getMessages().isEmpty()) {
|
||||
return "message can not be empty";
|
||||
throw new IllegalArgumentException("request messages cannot be null or empty");
|
||||
}
|
||||
if (request.getModel() == null) {
|
||||
return "model can not be empty";
|
||||
throw new IllegalArgumentException("request model cannot be null");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.model.ChatFunctionCall;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ChatFunctionCall} from any JSON
|
||||
* content, using appropriate {@link ChatFunctionCall} type.
|
||||
*/
|
||||
public class ChatFunctionCallDeserializer extends BaseNodeDeserializer<ChatFunctionCall> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Singleton instance of generic deserializer for
|
||||
* {@link ChatFunctionCallDeserializer}. Only used for types other than JSON Object
|
||||
* and Array.
|
||||
*/
|
||||
private final static ChatFunctionCallDeserializer instance = new ChatFunctionCallDeserializer();
|
||||
|
||||
public ChatFunctionCallDeserializer() {
|
||||
// `null` means that explicit "merge" is honored and may or may not work, but
|
||||
// that per-type and global defaults do not enable merging. This because
|
||||
// some node types (Object, Array) do support, others don't.
|
||||
super(ChatFunctionCall.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for accessing deserializer for specific node type
|
||||
*/
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
// For others, generic one works fine
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*
|
||||
* /********************************************************** /* Actual deserializer
|
||||
* implementations /**********************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ChatFunctionCall getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation that will produce types of any JSON nodes; not just one deserializer
|
||||
* is registered to handle (in case of more specialized handler). Overridden by typed
|
||||
* sub-classes for more thorough checking
|
||||
*/
|
||||
@Override
|
||||
public ChatFunctionCall deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ChatFunctionCall(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.model.ChatMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ChatMessage} from any JSON content,
|
||||
* using appropriate {@link ChatMessage} type.
|
||||
*/
|
||||
public class ChatMessageDeserializer extends BaseNodeDeserializer<ChatMessage> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Singleton instance of generic deserializer for {@link ChatMessageDeserializer}.
|
||||
* Only used for types other than JSON Object and Array.
|
||||
*/
|
||||
private final static ChatMessageDeserializer instance = new ChatMessageDeserializer();
|
||||
|
||||
public ChatMessageDeserializer() {
|
||||
// `null` means that explicit "merge" is honored and may or may not work, but
|
||||
// that per-type and global defaults do not enable merging. This because
|
||||
// some node types (Object, Array) do support, others don't.
|
||||
super(ChatMessage.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for accessing deserializer for specific node type
|
||||
*/
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
// For others, generic one works fine
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*
|
||||
* /********************************************************** /* Actual deserializer
|
||||
* implementations /**********************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ChatMessage getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation that will produce types of any JSON nodes; not just one deserializer
|
||||
* is registered to handle (in case of more specialized handler). Overridden by typed
|
||||
* sub-classes for more thorough checking
|
||||
*/
|
||||
@Override
|
||||
public ChatMessage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ChatMessage(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.model.Choice;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link Choice} from any JSON content, using
|
||||
* appropriate {@link Choice} type.
|
||||
*/
|
||||
public class ChoiceDeserializer extends BaseNodeDeserializer<Choice> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Singleton instance of generic deserializer for {@link ChoiceDeserializer}. Only
|
||||
* used for types other than JSON Object and Array.
|
||||
*/
|
||||
private final static ChoiceDeserializer instance = new ChoiceDeserializer();
|
||||
|
||||
public ChoiceDeserializer() {
|
||||
// `null` means that explicit "merge" is honored and may or may not work, but
|
||||
// that per-type and global defaults do not enable merging. This because
|
||||
// some node types (Object, Array) do support, others don't.
|
||||
super(Choice.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for accessing deserializer for specific node type
|
||||
*/
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
// For others, generic one works fine
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*
|
||||
* /********************************************************** /* Actual deserializer
|
||||
* implementations /**********************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Choice getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation that will produce types of any JSON nodes; not just one deserializer
|
||||
* is registered to handle (in case of more specialized handler). Overridden by typed
|
||||
* sub-classes for more thorough checking
|
||||
*/
|
||||
@Override
|
||||
public Choice deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new Choice(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.model.params.CodeGeexContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CodeGeexContextDeserializer extends BaseNodeDeserializer<CodeGeexContext> {
|
||||
|
||||
private static final CodeGeexContextDeserializer instance = new CodeGeexContextDeserializer();
|
||||
|
||||
public CodeGeexContextDeserializer() {
|
||||
super(CodeGeexContext.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeGeexContext getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodeGeexContext deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new CodeGeexContext(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.model.Delta;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link Delta} from any JSON content, using
|
||||
* appropriate {@link Delta} type.
|
||||
*/
|
||||
public class DeltaDeserializer extends BaseNodeDeserializer<Delta> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Singleton instance of generic deserializer for {@link DeltaDeserializer}. Only used
|
||||
* for types other than JSON Object and Array.
|
||||
*/
|
||||
private final static DeltaDeserializer instance = new DeltaDeserializer();
|
||||
|
||||
public DeltaDeserializer() {
|
||||
// `null` means that explicit "merge" is honored and may or may not work, but
|
||||
// that per-type and global defaults do not enable merging. This because
|
||||
// some node types (Object, Array) do support, others don't.
|
||||
super(Delta.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for accessing deserializer for specific node type
|
||||
*/
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
// For others, generic one works fine
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*
|
||||
* /********************************************************** /* Actual deserializer
|
||||
* implementations /**********************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Delta getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation that will produce types of any JSON nodes; not just one deserializer
|
||||
* is registered to handle (in case of more specialized handler). Overridden by typed
|
||||
* sub-classes for more thorough checking
|
||||
*/
|
||||
@Override
|
||||
public Delta deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new Delta(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,123 +1,23 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentDataDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentDataFailInfoDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentFailedInfoDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentObjectDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentPageDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentSuccessInfoDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.ChoiceDeltaDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.ChoiceDeltaToolCallDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.SearchChatMessageDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.SearchIntentDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.SearchRecommendDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.SearchResultDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.WebSearchChoiceDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.WebSearchMessageDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.WebSearchMessageToolCallDeserializer;
|
||||
import ai.z.openapi.service.deserialize.tools.WebSearchProDeserializer;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentData;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentDataFailInfo;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentFailedInfo;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentObject;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentPage;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentSuccessInfo;
|
||||
import ai.z.openapi.service.model.ChatFunctionCall;
|
||||
import ai.z.openapi.service.model.ChatMessage;
|
||||
import ai.z.openapi.service.model.Choice;
|
||||
import ai.z.openapi.service.model.Delta;
|
||||
import ai.z.openapi.service.model.ModelData;
|
||||
import ai.z.openapi.service.model.ToolCalls;
|
||||
import ai.z.openapi.service.tools.ChoiceDelta;
|
||||
import ai.z.openapi.service.tools.ChoiceDeltaToolCall;
|
||||
import ai.z.openapi.service.tools.SearchChatMessage;
|
||||
import ai.z.openapi.service.tools.SearchIntent;
|
||||
import ai.z.openapi.service.tools.SearchRecommend;
|
||||
import ai.z.openapi.service.tools.SearchResult;
|
||||
import ai.z.openapi.service.tools.WebSearchChoice;
|
||||
import ai.z.openapi.service.tools.WebSearchMessage;
|
||||
import ai.z.openapi.service.tools.WebSearchMessageToolCall;
|
||||
import ai.z.openapi.service.tools.WebSearchPro;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import ai.z.openapi.service.assistant.AssistantChoice;
|
||||
import ai.z.openapi.service.assistant.AssistantCompletion;
|
||||
import ai.z.openapi.service.assistant.CompletionUsage;
|
||||
import ai.z.openapi.service.assistant.ErrorInfo;
|
||||
import ai.z.openapi.service.deserialize.assistant.AssistantChoiceDeserializer;
|
||||
import ai.z.openapi.service.deserialize.assistant.AssistantCompletionDeserializer;
|
||||
import ai.z.openapi.service.deserialize.assistant.CompletionUsageDeserializer;
|
||||
import ai.z.openapi.service.deserialize.assistant.ErrorInfoDeserializer;
|
||||
import ai.z.openapi.service.deserialize.embedding.EmbeddingDeserializer;
|
||||
import ai.z.openapi.service.deserialize.embedding.EmbeddingResultDeserializer;
|
||||
import ai.z.openapi.service.deserialize.image.ImageDeserializer;
|
||||
import ai.z.openapi.service.deserialize.image.ImageResultDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgeInfoDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgePageDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgeStatisticsDeserializer;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgeUsedDeserializer;
|
||||
import ai.z.openapi.service.deserialize.videos.VideoObjectDeserializer;
|
||||
import ai.z.openapi.service.deserialize.videos.VideoResultDeserializer;
|
||||
import ai.z.openapi.service.embedding.Embedding;
|
||||
import ai.z.openapi.service.embedding.EmbeddingResult;
|
||||
import ai.z.openapi.service.image.Image;
|
||||
import ai.z.openapi.service.image.ImageResult;
|
||||
import ai.z.openapi.service.knowledge.KnowledgeInfo;
|
||||
import ai.z.openapi.service.knowledge.KnowledgePage;
|
||||
import ai.z.openapi.service.knowledge.KnowledgeStatistics;
|
||||
import ai.z.openapi.service.knowledge.KnowledgeUsed;
|
||||
import ai.z.openapi.service.model.params.CodeGeexContext;
|
||||
import ai.z.openapi.service.videos.VideoObject;
|
||||
import ai.z.openapi.service.videos.VideoResult;
|
||||
|
||||
public class MessageDeserializeFactory {
|
||||
|
||||
public static ObjectMapper defaultObjectMapper() {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
|
||||
SimpleModule module = new SimpleModule();
|
||||
|
||||
module.addDeserializer(ModelData.class, new ModelDataDeserializer());
|
||||
module.addDeserializer(Choice.class, new ChoiceDeserializer());
|
||||
module.addDeserializer(ChatMessage.class, new ChatMessageDeserializer());
|
||||
module.addDeserializer(Delta.class, new DeltaDeserializer());
|
||||
module.addDeserializer(ToolCalls.class, new ToolCallsDeserializer());
|
||||
module.addDeserializer(ChatFunctionCall.class, new ChatFunctionCallDeserializer());
|
||||
module.addDeserializer(CodeGeexContext.class, new CodeGeexContextDeserializer());
|
||||
module.addDeserializer(ChoiceDelta.class, new ChoiceDeltaDeserializer());
|
||||
module.addDeserializer(ChoiceDeltaToolCall.class, new ChoiceDeltaToolCallDeserializer());
|
||||
module.addDeserializer(SearchChatMessage.class, new SearchChatMessageDeserializer());
|
||||
module.addDeserializer(SearchIntent.class, new SearchIntentDeserializer());
|
||||
module.addDeserializer(SearchRecommend.class, new SearchRecommendDeserializer());
|
||||
module.addDeserializer(SearchResult.class, new SearchResultDeserializer());
|
||||
module.addDeserializer(WebSearchChoice.class, new WebSearchChoiceDeserializer());
|
||||
module.addDeserializer(WebSearchMessage.class, new WebSearchMessageDeserializer());
|
||||
module.addDeserializer(WebSearchMessageToolCall.class, new WebSearchMessageToolCallDeserializer());
|
||||
module.addDeserializer(WebSearchPro.class, new WebSearchProDeserializer());
|
||||
module.addDeserializer(VideoResult.class, new VideoResultDeserializer());
|
||||
module.addDeserializer(VideoObject.class, new VideoObjectDeserializer());
|
||||
module.addDeserializer(Image.class, new ImageDeserializer());
|
||||
module.addDeserializer(ImageResult.class, new ImageResultDeserializer());
|
||||
module.addDeserializer(KnowledgeInfo.class, new KnowledgeInfoDeserializer());
|
||||
module.addDeserializer(KnowledgeUsed.class, new KnowledgeUsedDeserializer());
|
||||
module.addDeserializer(KnowledgeStatistics.class, new KnowledgeStatisticsDeserializer());
|
||||
module.addDeserializer(KnowledgePage.class, new KnowledgePageDeserializer());
|
||||
module.addDeserializer(DocumentFailedInfo.class, new DocumentFailedInfoDeserializer());
|
||||
module.addDeserializer(DocumentObject.class, new DocumentObjectDeserializer());
|
||||
module.addDeserializer(DocumentSuccessInfo.class, new DocumentSuccessInfoDeserializer());
|
||||
module.addDeserializer(DocumentData.class, new DocumentDataDeserializer());
|
||||
module.addDeserializer(DocumentDataFailInfo.class, new DocumentDataFailInfoDeserializer());
|
||||
module.addDeserializer(DocumentPage.class, new DocumentPageDeserializer());
|
||||
module.addDeserializer(EmbeddingResult.class, new EmbeddingResultDeserializer());
|
||||
module.addDeserializer(Embedding.class, new EmbeddingDeserializer());
|
||||
module.addDeserializer(KnowledgeInfo.class, new KnowledgeInfoDeserializer());
|
||||
module.addDeserializer(AssistantChoice.class, new AssistantChoiceDeserializer());
|
||||
module.addDeserializer(AssistantCompletion.class, new AssistantCompletionDeserializer());
|
||||
module.addDeserializer(CompletionUsage.class, new CompletionUsageDeserializer());
|
||||
module.addDeserializer(ErrorInfo.class, new ErrorInfoDeserializer());
|
||||
mapper.registerModule(module);
|
||||
|
||||
return mapper;
|
||||
|
|
|
|||
|
|
@ -1,70 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.model.ModelData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ModelData} from any JSON content, using
|
||||
* appropriate {@link ModelData} type.
|
||||
*/
|
||||
public class ModelDataDeserializer extends BaseNodeDeserializer<ModelData> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Singleton instance of generic deserializer for {@link ModelDataDeserializer}. Only
|
||||
* used for types other than JSON Object and Array.
|
||||
*/
|
||||
private final static ModelDataDeserializer instance = new ModelDataDeserializer();
|
||||
|
||||
public ModelDataDeserializer() {
|
||||
// `null` means that explicit "merge" is honored and may or may not work, but
|
||||
// that per-type and global defaults do not enable merging. This because
|
||||
// some node types (Object, Array) do support, others don't.
|
||||
super(ModelData.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for accessing deserializer for specific node type
|
||||
*/
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
// For others, generic one works fine
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*
|
||||
* /********************************************************** /* Actual deserializer
|
||||
* implementations /**********************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ModelData getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation that will produce types of any JSON nodes; not just one deserializer
|
||||
* is registered to handle (in case of more specialized handler). Overridden by typed
|
||||
* sub-classes for more thorough checking
|
||||
*/
|
||||
@Override
|
||||
public ModelData deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ModelData(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.model.ToolCalls;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ToolCalls} from any JSON content, using
|
||||
* appropriate {@link ToolCalls} type.
|
||||
*/
|
||||
public class ToolCallsDeserializer extends BaseNodeDeserializer<ToolCalls> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* Singleton instance of generic deserializer for {@link ToolCallsDeserializer}. Only
|
||||
* used for types other than JSON Object and Array.
|
||||
*/
|
||||
private final static ToolCallsDeserializer instance = new ToolCallsDeserializer();
|
||||
|
||||
public ToolCallsDeserializer() {
|
||||
// `null` means that explicit "merge" is honored and may or may not work, but
|
||||
// that per-type and global defaults do not enable merging. This because
|
||||
// some node types (Object, Array) do support, others don't.
|
||||
super(ToolCalls.class, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for accessing deserializer for specific node type
|
||||
*/
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
// For others, generic one works fine
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*
|
||||
* /********************************************************** /* Actual deserializer
|
||||
* implementations /**********************************************************
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ToolCalls getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation that will produce types of any JSON nodes; not just one deserializer
|
||||
* is registered to handle (in case of more specialized handler). Overridden by typed
|
||||
* sub-classes for more thorough checking
|
||||
*/
|
||||
@Override
|
||||
public ToolCalls deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ToolCalls(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.assistant;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.assistant.AssistantCompletion;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link AssistantCompletion} from any JSON
|
||||
* content, using appropriate {@link AssistantCompletion} type.
|
||||
*/
|
||||
public class AssistantCompletionDeserializer extends BaseNodeDeserializer<AssistantCompletion> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static AssistantCompletionDeserializer instance = new AssistantCompletionDeserializer();
|
||||
|
||||
public AssistantCompletionDeserializer() {
|
||||
super(AssistantCompletion.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssistantCompletion getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssistantCompletion deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new AssistantCompletion(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.assistant;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.assistant.CompletionUsage;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link CompletionUsage} from any JSON content,
|
||||
* using appropriate {@link CompletionUsage} type.
|
||||
*/
|
||||
public class CompletionUsageDeserializer extends BaseNodeDeserializer<CompletionUsage> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static CompletionUsageDeserializer instance = new CompletionUsageDeserializer();
|
||||
|
||||
public CompletionUsageDeserializer() {
|
||||
super(CompletionUsage.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionUsage getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletionUsage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new CompletionUsage(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.assistant;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.assistant.ErrorInfo;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ErrorInfo} from any JSON content, using
|
||||
* appropriate {@link ErrorInfo} type.
|
||||
*/
|
||||
public class ErrorInfoDeserializer extends BaseNodeDeserializer<ErrorInfo> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static ErrorInfoDeserializer instance = new ErrorInfoDeserializer();
|
||||
|
||||
public ErrorInfoDeserializer() {
|
||||
super(ErrorInfo.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorInfo getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErrorInfo deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ErrorInfo(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
|
||||
package ai.z.openapi.service.deserialize.embedding;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.embedding.Embedding;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link Embedding} from any JSON content, using
|
||||
* appropriate {@link Embedding} type.
|
||||
*/
|
||||
public class EmbeddingDeserializer extends BaseNodeDeserializer<Embedding> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static EmbeddingDeserializer instance = new EmbeddingDeserializer();
|
||||
|
||||
public EmbeddingDeserializer() {
|
||||
super(Embedding.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Embedding getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Embedding deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new Embedding(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.embedding;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.embedding.EmbeddingResult;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link EmbeddingResult} from any JSON content,
|
||||
* using appropriate {@link EmbeddingResult} type.
|
||||
*/
|
||||
public class EmbeddingResultDeserializer extends BaseNodeDeserializer<EmbeddingResult> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static EmbeddingResultDeserializer instance = new EmbeddingResultDeserializer();
|
||||
|
||||
public EmbeddingResultDeserializer() {
|
||||
super(EmbeddingResult.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddingResult getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmbeddingResult deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new EmbeddingResult(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.image;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.image.Image;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link Image} from any JSON content, using
|
||||
* appropriate {@link Image} type.
|
||||
*/
|
||||
public class ImageDeserializer extends BaseNodeDeserializer<Image> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static ImageDeserializer instance = new ImageDeserializer();
|
||||
|
||||
public ImageDeserializer() {
|
||||
super(Image.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new Image(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.image;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.image.ImageResult;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ImageResult} from any JSON content,
|
||||
* using appropriate {@link ImageResult} type.
|
||||
*/
|
||||
public class ImageResultDeserializer extends BaseNodeDeserializer<ImageResult> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static ImageResultDeserializer instance = new ImageResultDeserializer();
|
||||
|
||||
public ImageResultDeserializer() {
|
||||
super(ImageResult.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageResult getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageResult deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ImageResult(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.KnowledgeInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link KnowledgeInfo} from any JSON content,
|
||||
* using appropriate {@link KnowledgeInfo} type.
|
||||
*/
|
||||
public class KnowledgeInfoDeserializer extends BaseNodeDeserializer<KnowledgeInfo> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static KnowledgeInfoDeserializer instance = new KnowledgeInfoDeserializer();
|
||||
|
||||
public KnowledgeInfoDeserializer() {
|
||||
super(KnowledgeInfo.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeInfo getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeInfo deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new KnowledgeInfo(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.KnowledgePage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link KnowledgePage} from any JSON content,
|
||||
* using appropriate {@link KnowledgePage} type.
|
||||
*/
|
||||
public class KnowledgePageDeserializer extends BaseNodeDeserializer<KnowledgePage> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static KnowledgePageDeserializer instance = new KnowledgePageDeserializer();
|
||||
|
||||
public KnowledgePageDeserializer() {
|
||||
super(KnowledgePage.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgePage getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgePage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new KnowledgePage(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.KnowledgeStatistics;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link KnowledgeStatistics} from any JSON
|
||||
* content, using appropriate {@link KnowledgeStatistics} type.
|
||||
*/
|
||||
public class KnowledgeStatisticsDeserializer extends BaseNodeDeserializer<KnowledgeStatistics> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static KnowledgeStatisticsDeserializer instance = new KnowledgeStatisticsDeserializer();
|
||||
|
||||
public KnowledgeStatisticsDeserializer() {
|
||||
super(KnowledgeStatistics.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeStatistics getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeStatistics deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new KnowledgeStatistics(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.KnowledgeUsed;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link KnowledgeUsed} from any JSON content,
|
||||
* using appropriate {@link KnowledgeUsed} type.
|
||||
*/
|
||||
public class KnowledgeUsedDeserializer extends BaseNodeDeserializer<KnowledgeUsed> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static KnowledgeUsedDeserializer instance = new KnowledgeUsedDeserializer();
|
||||
|
||||
public KnowledgeUsedDeserializer() {
|
||||
super(KnowledgeUsed.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeUsed getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeUsed deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new KnowledgeUsed(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentData;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link DocumentData} from any JSON content,
|
||||
* using appropriate {@link DocumentData} type.
|
||||
*/
|
||||
public class DocumentDataDeserializer extends BaseNodeDeserializer<DocumentData> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static DocumentDataDeserializer instance = new DocumentDataDeserializer();
|
||||
|
||||
public DocumentDataDeserializer() {
|
||||
super(DocumentData.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentData getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentData deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new DocumentData(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentDataFailInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link DocumentDataFailInfo} from any JSON
|
||||
* content, using appropriate {@link DocumentDataFailInfo} type.
|
||||
*/
|
||||
public class DocumentDataFailInfoDeserializer extends BaseNodeDeserializer<DocumentDataFailInfo> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static DocumentDataFailInfoDeserializer instance = new DocumentDataFailInfoDeserializer();
|
||||
|
||||
public DocumentDataFailInfoDeserializer() {
|
||||
super(DocumentDataFailInfo.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentDataFailInfo getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentDataFailInfo deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new DocumentDataFailInfo(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentFailedInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link DocumentFailedInfo} from any JSON
|
||||
* content, using appropriate {@link DocumentFailedInfo} type.
|
||||
*/
|
||||
public class DocumentFailedInfoDeserializer extends BaseNodeDeserializer<DocumentFailedInfo> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static DocumentFailedInfoDeserializer instance = new DocumentFailedInfoDeserializer();
|
||||
|
||||
public DocumentFailedInfoDeserializer() {
|
||||
super(DocumentFailedInfo.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentFailedInfo getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentFailedInfo deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new DocumentFailedInfo(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link DocumentObject} from any JSON content,
|
||||
* using appropriate {@link DocumentObject} type.
|
||||
*/
|
||||
|
||||
public class DocumentObjectDeserializer extends BaseNodeDeserializer<DocumentObject> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static DocumentObjectDeserializer instance = new DocumentObjectDeserializer();
|
||||
|
||||
public DocumentObjectDeserializer() {
|
||||
super(DocumentObject.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentObject getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentObject deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new DocumentObject(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentPage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link DocumentPage} from any JSON content,
|
||||
* using appropriate {@link DocumentPage} type.
|
||||
*/
|
||||
public class DocumentPageDeserializer extends BaseNodeDeserializer<DocumentPage> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static DocumentPageDeserializer instance = new DocumentPageDeserializer();
|
||||
|
||||
public DocumentPageDeserializer() {
|
||||
super(DocumentPage.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentPage getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentPage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new DocumentPage(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.knowledge.document.DocumentSuccessInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link DocumentSuccessInfo} from any JSON
|
||||
* content, using appropriate {@link DocumentSuccessInfo} type.
|
||||
*/
|
||||
public class DocumentSuccessInfoDeserializer extends BaseNodeDeserializer<DocumentSuccessInfo> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static DocumentSuccessInfoDeserializer instance = new DocumentSuccessInfoDeserializer();
|
||||
|
||||
public DocumentSuccessInfoDeserializer() {
|
||||
super(DocumentSuccessInfo.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentSuccessInfo getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentSuccessInfo deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new DocumentSuccessInfo(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.ChoiceDelta;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ChoiceDelta} from any JSON content,
|
||||
* using appropriate {@link ChoiceDelta} type.
|
||||
*/
|
||||
public class ChoiceDeltaDeserializer extends BaseNodeDeserializer<ChoiceDelta> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static ChoiceDeltaDeserializer instance = new ChoiceDeltaDeserializer();
|
||||
|
||||
public ChoiceDeltaDeserializer() {
|
||||
super(ChoiceDelta.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoiceDelta getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoiceDelta deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ChoiceDelta(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.ChoiceDeltaToolCall;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link ChoiceDeltaToolCall} from any JSON
|
||||
* content, using appropriate {@link ChoiceDeltaToolCall} type.
|
||||
*/
|
||||
public class ChoiceDeltaToolCallDeserializer extends BaseNodeDeserializer<ChoiceDeltaToolCall> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static ChoiceDeltaToolCallDeserializer instance = new ChoiceDeltaToolCallDeserializer();
|
||||
|
||||
public ChoiceDeltaToolCallDeserializer() {
|
||||
super(ChoiceDeltaToolCall.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoiceDeltaToolCall getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChoiceDeltaToolCall deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new ChoiceDeltaToolCall(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.SearchChatMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link SearchChatMessage} from any JSON
|
||||
* content, using appropriate {@link SearchChatMessage} type.
|
||||
*/
|
||||
public class SearchChatMessageDeserializer extends BaseNodeDeserializer<SearchChatMessage> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static SearchChatMessageDeserializer instance = new SearchChatMessageDeserializer();
|
||||
|
||||
public SearchChatMessageDeserializer() {
|
||||
super(SearchChatMessage.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchChatMessage getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchChatMessage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new SearchChatMessage(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.SearchIntent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link SearchIntent} from any JSON content,
|
||||
* using appropriate {@link SearchIntent} type.
|
||||
*/
|
||||
public class SearchIntentDeserializer extends BaseNodeDeserializer<SearchIntent> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static SearchIntentDeserializer instance = new SearchIntentDeserializer();
|
||||
|
||||
public SearchIntentDeserializer() {
|
||||
super(SearchIntent.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchIntent getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchIntent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new SearchIntent(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.SearchRecommend;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link SearchRecommend} from any JSON content,
|
||||
* using appropriate {@link SearchRecommend} type.
|
||||
*/
|
||||
public class SearchRecommendDeserializer extends BaseNodeDeserializer<SearchRecommend> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static SearchRecommendDeserializer instance = new SearchRecommendDeserializer();
|
||||
|
||||
public SearchRecommendDeserializer() {
|
||||
super(SearchRecommend.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchRecommend getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchRecommend deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new SearchRecommend(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.SearchResult;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link SearchResult} from any JSON content,
|
||||
* using appropriate {@link SearchResult} type.
|
||||
*/
|
||||
public class SearchResultDeserializer extends BaseNodeDeserializer<SearchResult> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static SearchResultDeserializer instance = new SearchResultDeserializer();
|
||||
|
||||
public SearchResultDeserializer() {
|
||||
super(SearchResult.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchResult getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchResult deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new SearchResult(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.WebSearchChoice;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link WebSearchChoice} from any JSON content,
|
||||
* using appropriate {@link WebSearchChoice} type.
|
||||
*/
|
||||
public class WebSearchChoiceDeserializer extends BaseNodeDeserializer<WebSearchChoice> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static WebSearchChoiceDeserializer instance = new WebSearchChoiceDeserializer();
|
||||
|
||||
public WebSearchChoiceDeserializer() {
|
||||
super(WebSearchChoice.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchChoice getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchChoice deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new WebSearchChoice(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.WebSearchMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link WebSearchMessage} from any JSON
|
||||
* content, using appropriate {@link WebSearchMessage} type.
|
||||
*/
|
||||
public class WebSearchMessageDeserializer extends BaseNodeDeserializer<WebSearchMessage> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static WebSearchMessageDeserializer instance = new WebSearchMessageDeserializer();
|
||||
|
||||
public WebSearchMessageDeserializer() {
|
||||
super(WebSearchMessage.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchMessage getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchMessage deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new WebSearchMessage(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.WebSearchMessageToolCall;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link WebSearchMessageToolCall} from any JSON
|
||||
* content, using appropriate {@link WebSearchMessageToolCall} type.
|
||||
*/
|
||||
public class WebSearchMessageToolCallDeserializer extends BaseNodeDeserializer<WebSearchMessageToolCall> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static WebSearchMessageToolCallDeserializer instance = new WebSearchMessageToolCallDeserializer();
|
||||
|
||||
public WebSearchMessageToolCallDeserializer() {
|
||||
super(WebSearchMessageToolCall.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchMessageToolCall getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchMessageToolCall deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new WebSearchMessageToolCall(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.tools;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.tools.WebSearchPro;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link WebSearchPro} from any JSON content,
|
||||
* using appropriate {@link WebSearchPro} type.
|
||||
*/
|
||||
public class WebSearchProDeserializer extends BaseNodeDeserializer<WebSearchPro> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static WebSearchProDeserializer instance = new WebSearchProDeserializer();
|
||||
|
||||
public WebSearchProDeserializer() {
|
||||
super(WebSearchPro.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchPro getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSearchPro deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new WebSearchPro(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.videos;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.videos.VideoObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link VideoObject} from any JSON content,
|
||||
* using appropriate {@link VideoObject} type.
|
||||
*/
|
||||
public class VideoObjectDeserializer extends BaseNodeDeserializer<VideoObject> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static VideoObjectDeserializer instance = new VideoObjectDeserializer();
|
||||
|
||||
public VideoObjectDeserializer() {
|
||||
super(VideoObject.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoObject getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoObject deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new VideoObject(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
package ai.z.openapi.service.deserialize.videos;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonTokenId;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.BaseNodeDeserializer;
|
||||
import ai.z.openapi.service.deserialize.ObjectDeserializer;
|
||||
import ai.z.openapi.service.videos.VideoResult;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Deserializer that can build instances of {@link VideoResult} from any JSON content,
|
||||
* using appropriate {@link VideoResult} type.
|
||||
*/
|
||||
public class VideoResultDeserializer extends BaseNodeDeserializer<VideoResult> {
|
||||
|
||||
private final static ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private final static VideoResultDeserializer instance = new VideoResultDeserializer();
|
||||
|
||||
public VideoResultDeserializer() {
|
||||
super(VideoResult.class, null);
|
||||
}
|
||||
|
||||
public static JsonDeserializer<? extends JsonNode> getDeserializer(Class<?> nodeClass) {
|
||||
if (nodeClass == ObjectNode.class) {
|
||||
return ObjectDeserializer.getInstance();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoResult getNullValue(DeserializationContext ctxt) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VideoResult deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
if (p.currentTokenId() == JsonTokenId.ID_START_OBJECT) {
|
||||
ObjectNode jsonNodes = deserializeObject(p, ctxt, ctxt.getNodeFactory());
|
||||
return new VideoResult(jsonNodes);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,97 +1,35 @@
|
|||
package ai.z.openapi.service.embedding;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.embedding.EmbeddingDeserializer;
|
||||
import lombok.Getter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents an embedding returned by the embedding api
|
||||
*/
|
||||
|
||||
@JsonDeserialize(using = EmbeddingDeserializer.class)
|
||||
public class Embedding extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Embedding {
|
||||
|
||||
/**
|
||||
* The type of object returned, should be "embedding"
|
||||
*/
|
||||
@Getter
|
||||
String object;
|
||||
|
||||
/**
|
||||
* The embedding vector
|
||||
*/
|
||||
@Getter
|
||||
List<Double> embedding;
|
||||
|
||||
/**
|
||||
* The position of this embedding in the list
|
||||
*/
|
||||
@Getter
|
||||
Integer index;
|
||||
|
||||
public Embedding() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public Embedding(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("object") != null) {
|
||||
this.setObject(objectNode.get("object").asText());
|
||||
}
|
||||
else {
|
||||
this.setObject(null);
|
||||
}
|
||||
if (objectNode.get("index") != null) {
|
||||
this.setIndex(objectNode.get("index").asInt());
|
||||
}
|
||||
else {
|
||||
this.setIndex(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("embedding") != null) {
|
||||
List<Double> embedding = objectMapper.convertValue(objectNode.get("embedding"),
|
||||
new TypeReference<List<Double>>() {
|
||||
});
|
||||
this.setEmbedding(embedding);
|
||||
}
|
||||
else {
|
||||
this.setEmbedding(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
public void setIndex(Integer index) {
|
||||
this.index = index;
|
||||
this.put("index", index);
|
||||
}
|
||||
|
||||
public void setObject(String object) {
|
||||
this.object = object;
|
||||
this.put("object", object);
|
||||
}
|
||||
|
||||
public void setEmbedding(List<Double> embedding) throws IllegalArgumentException {
|
||||
if (embedding == null || embedding.isEmpty()) {
|
||||
throw new IllegalArgumentException("Embedding cannot be null or empty");
|
||||
}
|
||||
this.embedding = embedding;
|
||||
this.putPOJO("embedding", embedding);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ import ai.z.openapi.service.CommonRequest;
|
|||
import lombok.*;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Creates an embedding vector representing the input text.
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
package ai.z.openapi.service.embedding;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.embedding.EmbeddingResultDeserializer;
|
||||
import ai.z.openapi.service.model.Usage;
|
||||
import lombok.Getter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* An object containing a response from the answer api
|
||||
*/
|
||||
@Getter
|
||||
@JsonDeserialize(using = EmbeddingResultDeserializer.class)
|
||||
public class EmbeddingResult extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EmbeddingResult {
|
||||
|
||||
/**
|
||||
* The GLMmodel used for generating embeddings
|
||||
|
|
@ -40,67 +37,4 @@ public class EmbeddingResult extends ObjectNode {
|
|||
*/
|
||||
Usage usage;
|
||||
|
||||
public EmbeddingResult() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public EmbeddingResult(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("model") != null) {
|
||||
this.setModel(objectNode.get("model").asText());
|
||||
}
|
||||
else {
|
||||
this.setModel(null);
|
||||
}
|
||||
if (objectNode.get("object") != null) {
|
||||
this.setObject(objectNode.get("object").asText());
|
||||
}
|
||||
else {
|
||||
this.setObject(null);
|
||||
}
|
||||
if (objectNode.get("data") != null) {
|
||||
List<Embedding> data1 = objectMapper.convertValue(objectNode.get("data"),
|
||||
new com.fasterxml.jackson.core.type.TypeReference<List<Embedding>>() {
|
||||
});
|
||||
this.setData(data1);
|
||||
}
|
||||
else {
|
||||
this.setData(null);
|
||||
}
|
||||
if (objectNode.get("usage") != null) {
|
||||
this.setUsage(objectMapper.convertValue(objectNode.get("usage"), Usage.class));
|
||||
}
|
||||
else {
|
||||
this.setUsage(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
this.put("model", model);
|
||||
}
|
||||
|
||||
public void setObject(String object) {
|
||||
this.object = object;
|
||||
this.put("object", object);
|
||||
}
|
||||
|
||||
public void setData(List<Embedding> data) {
|
||||
this.data = data;
|
||||
this.putPOJO("data", data);
|
||||
}
|
||||
|
||||
public void setUsage(Usage usage) {
|
||||
this.usage = usage;
|
||||
this.putPOJO("usage", usage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import ai.z.openapi.ZaiClient;
|
|||
import ai.z.openapi.api.embedding.EmbeddingApi;
|
||||
import ai.z.openapi.utils.RequestSupplier;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Embedding service implementation
|
||||
*/
|
||||
|
|
@ -20,8 +22,37 @@ public class EmbeddingServiceImpl implements EmbeddingService {
|
|||
|
||||
@Override
|
||||
public EmbeddingResponse createEmbeddings(EmbeddingCreateParams request) {
|
||||
validateCreateEmbeddingsParams(request);
|
||||
RequestSupplier<EmbeddingCreateParams, EmbeddingResult> supplier = embeddingApi::createEmbeddings;
|
||||
return this.zAiClient.executeRequest(request, supplier, EmbeddingResponse.class);
|
||||
}
|
||||
|
||||
private void validateCreateEmbeddingsParams(EmbeddingCreateParams request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("Request cannot be null");
|
||||
}
|
||||
if (request.getModel() == null || request.getModel().trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Model cannot be null or empty");
|
||||
}
|
||||
if (request.getInput() == null) {
|
||||
throw new IllegalArgumentException("Input cannot be null");
|
||||
}
|
||||
if (request.getInput() instanceof String) {
|
||||
String input = (String) request.getInput();
|
||||
if (input.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("Input string cannot be empty");
|
||||
}
|
||||
}
|
||||
else if (request.getInput() instanceof List) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> inputList = (List<String>) request.getInput();
|
||||
if (inputList.isEmpty()) {
|
||||
throw new IllegalArgumentException("Input list cannot be empty");
|
||||
}
|
||||
}
|
||||
if (request.getDimensions() != null && request.getDimensions() <= 0) {
|
||||
throw new IllegalArgumentException("Dimensions must be positive");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -28,6 +28,13 @@ public class FileServiceImpl implements FileService {
|
|||
|
||||
@Override
|
||||
public FileApiResponse uploadFile(FileUploadParams request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
if (request.getFilePath() == null) {
|
||||
throw new IllegalArgumentException("request path cannot be null");
|
||||
}
|
||||
|
||||
RequestSupplier<FileUploadParams, File> supplier = (params) -> {
|
||||
try {
|
||||
java.io.File file = new java.io.File(params.getFilePath());
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.List;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIgnoreProperties(ignoreUnknown = true) // Ignore unknown properties
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class FineTuningEvent {
|
||||
|
||||
private String object;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
|
|||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonIgnoreProperties(ignoreUnknown = true) // Ignore unknown properties
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class FineTuningEventData {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public class FineTuningServiceImpl implements FineTuningService {
|
|||
|
||||
@Override
|
||||
public CreateFineTuningJobApiResponse createFineTuningJob(FineTuningJobRequest request) {
|
||||
validateRequest(request, "FineTuningJobRequest");
|
||||
RequestSupplier<FineTuningJobRequest, FineTuningJob> supplier = fineTuningApi::createFineTuningJob;
|
||||
return this.zAiClient.executeRequest(request, supplier, CreateFineTuningJobApiResponse.class);
|
||||
}
|
||||
|
|
@ -27,6 +28,7 @@ public class FineTuningServiceImpl implements FineTuningService {
|
|||
@Override
|
||||
public QueryFineTuningEventApiResponse listFineTuningJobEvents(
|
||||
QueryFineTuningJobRequest queryFineTuningJobRequest) {
|
||||
validateRequest(queryFineTuningJobRequest, "QueryFineTuningJobRequest");
|
||||
RequestSupplier<QueryFineTuningJobRequest, FineTuningEvent> supplier = (params) -> fineTuningApi
|
||||
.listFineTuningJobEvents(params.getJobId(), params.getLimit(), params.getAfter());
|
||||
return this.zAiClient.executeRequest(queryFineTuningJobRequest, supplier,
|
||||
|
|
@ -35,6 +37,7 @@ public class FineTuningServiceImpl implements FineTuningService {
|
|||
|
||||
@Override
|
||||
public QueryFineTuningJobApiResponse retrieveFineTuningJob(QueryFineTuningJobRequest queryFineTuningJobRequest) {
|
||||
validateRequest(queryFineTuningJobRequest, "QueryFineTuningJobRequest");
|
||||
RequestSupplier<QueryFineTuningJobRequest, FineTuningJob> supplier = (params) -> fineTuningApi
|
||||
.retrieveFineTuningJob(params.getJobId(), params.getLimit(), params.getAfter());
|
||||
return this.zAiClient.executeRequest(queryFineTuningJobRequest, supplier, QueryFineTuningJobApiResponse.class);
|
||||
|
|
@ -43,6 +46,7 @@ public class FineTuningServiceImpl implements FineTuningService {
|
|||
@Override
|
||||
public QueryPersonalFineTuningJobApiResponse listPersonalFineTuningJobs(
|
||||
QueryPersonalFineTuningJobRequest queryPersonalFineTuningJobRequest) {
|
||||
validateRequest(queryPersonalFineTuningJobRequest, "QueryPersonalFineTuningJobRequest");
|
||||
RequestSupplier<QueryPersonalFineTuningJobRequest, PersonalFineTuningJob> supplier = (params) -> fineTuningApi
|
||||
.queryPersonalFineTuningJobs(params.getLimit(), params.getAfter());
|
||||
return this.zAiClient.executeRequest(queryPersonalFineTuningJobRequest, supplier,
|
||||
|
|
@ -51,6 +55,7 @@ public class FineTuningServiceImpl implements FineTuningService {
|
|||
|
||||
@Override
|
||||
public QueryFineTuningJobApiResponse cancelFineTuningJob(FineTuningJobIdRequest fineTuningJobIdRequest) {
|
||||
validateRequest(fineTuningJobIdRequest, "FineTuningJobIdRequest");
|
||||
RequestSupplier<FineTuningJobIdRequest, FineTuningJob> supplier = (params) -> fineTuningApi
|
||||
.cancelFineTuningJob(params.getJobId());
|
||||
return this.zAiClient.executeRequest(fineTuningJobIdRequest, supplier, QueryFineTuningJobApiResponse.class);
|
||||
|
|
@ -58,6 +63,7 @@ public class FineTuningServiceImpl implements FineTuningService {
|
|||
|
||||
@Override
|
||||
public QueryFineTuningJobApiResponse deleteFineTuningJob(FineTuningJobIdRequest fineTuningJobIdRequest) {
|
||||
validateRequest(fineTuningJobIdRequest, "FineTuningJobIdRequest");
|
||||
RequestSupplier<FineTuningJobIdRequest, FineTuningJob> supplier = (params) -> fineTuningApi
|
||||
.deleteFineTuningJob(params.getJobId());
|
||||
return this.zAiClient.executeRequest(fineTuningJobIdRequest, supplier, QueryFineTuningJobApiResponse.class);
|
||||
|
|
@ -65,9 +71,16 @@ public class FineTuningServiceImpl implements FineTuningService {
|
|||
|
||||
@Override
|
||||
public FineTunedModelsStatusResponse deleteFineTunedModel(FineTuningJobModelRequest fineTuningJobModelRequest) {
|
||||
validateRequest(fineTuningJobModelRequest, "FineTuningJobModelRequest");
|
||||
RequestSupplier<FineTuningJobModelRequest, FineTunedModelsStatus> supplier = (params) -> fineTuningApi
|
||||
.deleteFineTuningModel(params.getFineTunedModel());
|
||||
return this.zAiClient.executeRequest(fineTuningJobModelRequest, supplier, FineTunedModelsStatusResponse.class);
|
||||
}
|
||||
|
||||
private void validateRequest(Object request, String requestType) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException(requestType + " cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -4,7 +4,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
import ai.z.openapi.core.model.ClientRequest;
|
||||
import ai.z.openapi.service.CommonRequest;
|
||||
import ai.z.openapi.service.model.SensitiveWordCheckRequest;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.NonNull;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
|
|
@ -22,7 +26,6 @@ public class CreateImageRequest extends CommonRequest implements ClientRequest<C
|
|||
* A text description of the desired image(s). The maximum length is 1000 characters
|
||||
* for dall-e-2 and 4000 characters for dall-e-3.
|
||||
*/
|
||||
@NonNull
|
||||
private String prompt;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
package ai.z.openapi.service.image;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.image.ImageDeserializer;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* An object containing either a URL or a base 64 encoded image.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@JsonDeserialize(using = ImageDeserializer.class)
|
||||
public class Image extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Image {
|
||||
|
||||
/**
|
||||
* The URL where the image can be accessed.
|
||||
|
|
@ -39,53 +36,4 @@ public class Image extends ObjectNode {
|
|||
@JsonProperty("revised_prompt")
|
||||
String revisedPrompt;
|
||||
|
||||
public Image() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public Image(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("url") != null) {
|
||||
this.setUrl(objectNode.get("url").asText());
|
||||
}
|
||||
else {
|
||||
this.setUrl(null);
|
||||
}
|
||||
if (objectNode.get("b64_json") != null) {
|
||||
this.setB64Json(objectNode.get("b64_json").asText());
|
||||
}
|
||||
else {
|
||||
this.setB64Json(null);
|
||||
}
|
||||
if (objectNode.get("revised_prompt") != null) {
|
||||
this.setRevisedPrompt(objectNode.get("revised_prompt").asText());
|
||||
}
|
||||
else {
|
||||
this.setRevisedPrompt(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
this.put("url", url);
|
||||
}
|
||||
|
||||
public void setB64Json(String b64Json) {
|
||||
this.b64Json = b64Json;
|
||||
this.put("b64_json", b64Json);
|
||||
}
|
||||
|
||||
public void setRevisedPrompt(String revisedPrompt) {
|
||||
this.revisedPrompt = revisedPrompt;
|
||||
this.put("revised_prompt", revisedPrompt);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,23 @@
|
|||
package ai.z.openapi.service.image;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.image.ImageResultDeserializer;
|
||||
import lombok.Getter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* An object with a list of image results.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@JsonDeserialize(using = ImageResultDeserializer.class)
|
||||
public class ImageResult extends ObjectNode {
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ImageResult {
|
||||
|
||||
/**
|
||||
* The creation time in epoch seconds.
|
||||
|
|
@ -32,6 +28,8 @@ public class ImageResult extends ObjectNode {
|
|||
/**
|
||||
* List of image results.
|
||||
*/
|
||||
@JsonProperty("data")
|
||||
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
||||
List<Image> data;
|
||||
|
||||
/**
|
||||
|
|
@ -41,66 +39,4 @@ public class ImageResult extends ObjectNode {
|
|||
@JsonProperty("request_id")
|
||||
private String requestId;
|
||||
|
||||
public ImageResult() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ImageResult(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("created") != null) {
|
||||
this.setCreated(objectNode.get("created").asLong());
|
||||
}
|
||||
else {
|
||||
this.setCreated(null);
|
||||
}
|
||||
if (objectNode.get("data") != null) {
|
||||
List<Image> data = objectMapper.convertValue(objectNode.get("data"), new TypeReference<List<Image>>() {
|
||||
});
|
||||
|
||||
this.setData(data);
|
||||
}
|
||||
else {
|
||||
this.setData(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("request_id") != null) {
|
||||
this.setRequestId(objectNode.get("request_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setRequestId(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
public void setCreated(Long created) {
|
||||
this.created = created;
|
||||
this.put("created", created);
|
||||
}
|
||||
|
||||
public void setData(List<Image> data) {
|
||||
this.data = data;
|
||||
ArrayNode jsonNodes = this.putArray("data");
|
||||
if (data == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (Image image : data) {
|
||||
jsonNodes.add(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRequestId(String requestId) {
|
||||
this.requestId = requestId;
|
||||
this.put("request_id", requestId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
package ai.z.openapi.service.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgeInfoDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the knowledge base information.
|
||||
*/
|
||||
@JsonDeserialize(using = KnowledgeInfoDeserializer.class)
|
||||
public class KnowledgeInfo extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class KnowledgeInfo {
|
||||
|
||||
/**
|
||||
* Knowledge base unique ID
|
||||
|
|
@ -64,142 +64,4 @@ public class KnowledgeInfo extends ObjectNode {
|
|||
@JsonProperty("bucket_id")
|
||||
private String bucketId;
|
||||
|
||||
public KnowledgeInfo() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public KnowledgeInfo(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
if (objectNode.has("id")) {
|
||||
this.setId(objectNode.get("id").asText());
|
||||
}
|
||||
else {
|
||||
this.setId(null);
|
||||
}
|
||||
if (objectNode.has("embedding_id")) {
|
||||
this.setEmbeddingId(objectNode.get("embedding_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setEmbeddingId(null);
|
||||
}
|
||||
if (objectNode.has("name")) {
|
||||
this.setName(objectNode.get("name").asText());
|
||||
}
|
||||
else {
|
||||
this.setName(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("customer_identifier")) {
|
||||
this.setCustomerIdentifier(objectNode.get("customer_identifier").asText());
|
||||
}
|
||||
else {
|
||||
this.setCustomerIdentifier(null);
|
||||
}
|
||||
if (objectNode.has("description")) {
|
||||
this.setDescription(objectNode.get("description").asText());
|
||||
}
|
||||
else {
|
||||
this.setDescription(null);
|
||||
}
|
||||
if (objectNode.has("background")) {
|
||||
this.setBackground(objectNode.get("background").asText());
|
||||
}
|
||||
else {
|
||||
this.setBackground(null);
|
||||
}
|
||||
if (objectNode.has("icon")) {
|
||||
this.setIcon(objectNode.get("icon").asText());
|
||||
}
|
||||
else {
|
||||
this.setIcon(null);
|
||||
}
|
||||
if (objectNode.has("bucket_id")) {
|
||||
this.setBucketId(objectNode.get("bucket_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setBucketId(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
this.put("id", id);
|
||||
}
|
||||
|
||||
public String getEmbeddingId() {
|
||||
return embeddingId;
|
||||
}
|
||||
|
||||
public void setEmbeddingId(String embeddingId) {
|
||||
this.embeddingId = embeddingId;
|
||||
this.put("embedding_id", embeddingId);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.put("name", name);
|
||||
}
|
||||
|
||||
public String getCustomerIdentifier() {
|
||||
return customerIdentifier;
|
||||
}
|
||||
|
||||
public void setCustomerIdentifier(String customerIdentifier) {
|
||||
this.customerIdentifier = customerIdentifier;
|
||||
this.put("customer_identifier", customerIdentifier);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
this.put("description", description);
|
||||
}
|
||||
|
||||
public String getBackground() {
|
||||
return background;
|
||||
}
|
||||
|
||||
public void setBackground(String background) {
|
||||
this.background = background;
|
||||
this.put("background", background);
|
||||
}
|
||||
|
||||
public String getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(String icon) {
|
||||
this.icon = icon;
|
||||
this.put("icon", icon);
|
||||
}
|
||||
|
||||
public String getBucketId() {
|
||||
return bucketId;
|
||||
}
|
||||
|
||||
public void setBucketId(String bucketId) {
|
||||
this.bucketId = bucketId;
|
||||
this.put("bucket_id", bucketId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,21 @@
|
|||
package ai.z.openapi.service.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgePageDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents a page of knowledge base information.
|
||||
*/
|
||||
@JsonDeserialize(using = KnowledgePageDeserializer.class)
|
||||
public class KnowledgePage extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class KnowledgePage {
|
||||
|
||||
/**
|
||||
* Knowledge base information list
|
||||
|
|
@ -32,66 +29,4 @@ public class KnowledgePage extends ObjectNode {
|
|||
@JsonProperty("total")
|
||||
private Integer total;
|
||||
|
||||
public KnowledgePage() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public KnowledgePage(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("list") != null) {
|
||||
List<KnowledgeInfo> list = objectMapper.convertValue(objectNode.get("list"),
|
||||
new TypeReference<List<KnowledgeInfo>>() {
|
||||
});
|
||||
|
||||
this.setList(list);
|
||||
}
|
||||
else {
|
||||
this.setList(null);
|
||||
}
|
||||
if (objectNode.get("total") != null) {
|
||||
this.setTotal(objectNode.get("total").asInt());
|
||||
}
|
||||
else {
|
||||
this.setTotal(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public List<KnowledgeInfo> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<KnowledgeInfo> list) {
|
||||
this.list = list;
|
||||
ArrayNode jsonNodes = this.putArray("list");
|
||||
if (list == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (KnowledgeInfo item : list) {
|
||||
jsonNodes.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Integer total) {
|
||||
this.total = total;
|
||||
this.put("total", total);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import ai.z.openapi.ZaiClient;
|
|||
import ai.z.openapi.api.knowledge.KnowledgeApi;
|
||||
import ai.z.openapi.service.model.AsyncResultRetrieveParams;
|
||||
import ai.z.openapi.utils.RequestSupplier;
|
||||
import ai.z.openapi.utils.StringUtils;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
|
|
@ -22,12 +23,14 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
|||
|
||||
@Override
|
||||
public KnowledgeResponse createKnowledge(KnowledgeBaseParams request) {
|
||||
validateCreateKnowledgeParams(request);
|
||||
RequestSupplier<KnowledgeBaseParams, KnowledgeInfo> supplier = knowledgeApi::knowledgeCreate;
|
||||
return this.zAiClient.executeRequest(request, supplier, KnowledgeResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KnowledgeEditResponse modifyKnowledge(KnowledgeBaseParams request) {
|
||||
validateModifyKnowledgeParams(request);
|
||||
RequestSupplier<KnowledgeBaseParams, Response<Void>> supplier = (params) -> knowledgeApi
|
||||
.knowledgeModify(params.getKnowledgeId(), params);
|
||||
return zAiClient.executeRequest(request, supplier, KnowledgeEditResponse.class);
|
||||
|
|
@ -35,6 +38,7 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
|||
|
||||
@Override
|
||||
public QueryKnowledgeApiResponse queryKnowledge(QueryKnowledgeRequest request) {
|
||||
validateQueryKnowledgeParams(request);
|
||||
RequestSupplier<QueryKnowledgeRequest, KnowledgePage> supplier = (params) -> knowledgeApi
|
||||
.knowledgeQuery(params.getPage(), params.getSize());
|
||||
return zAiClient.executeRequest(request, supplier, QueryKnowledgeApiResponse.class);
|
||||
|
|
@ -42,7 +46,8 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
|||
|
||||
@Override
|
||||
public KnowledgeEditResponse deleteKnowledge(String knowledgeId) {
|
||||
AsyncResultRetrieveParams params = new AsyncResultRetrieveParams(knowledgeId);
|
||||
validateDeleteKnowledgeParams(knowledgeId);
|
||||
AsyncResultRetrieveParams params = AsyncResultRetrieveParams.builder().taskId(knowledgeId).build();
|
||||
RequestSupplier<AsyncResultRetrieveParams, Response<Void>> supplier = (params1) -> knowledgeApi
|
||||
.knowledgeDelete(params1.getTaskId());
|
||||
return zAiClient.executeRequest(params, supplier, KnowledgeEditResponse.class);
|
||||
|
|
@ -54,4 +59,31 @@ public class KnowledgeServiceImpl implements KnowledgeService {
|
|||
return zAiClient.executeRequest(null, supplier, KnowledgeUsedResponse.class);
|
||||
}
|
||||
|
||||
private void validateCreateKnowledgeParams(KnowledgeBaseParams request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateModifyKnowledgeParams(KnowledgeBaseParams request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
if (StringUtils.isEmpty(request.getKnowledgeId())) {
|
||||
throw new IllegalArgumentException("knowledge ID cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateQueryKnowledgeParams(QueryKnowledgeRequest request) {
|
||||
if (request == null) {
|
||||
throw new IllegalArgumentException("request cannot be null");
|
||||
}
|
||||
}
|
||||
|
||||
private void validateDeleteKnowledgeParams(String knowledgeId) {
|
||||
if (StringUtils.isEmpty(knowledgeId)) {
|
||||
throw new IllegalArgumentException("knowledge ID cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,19 +1,20 @@
|
|||
package ai.z.openapi.service.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgeStatisticsDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the usage statistics of the knowledge base.
|
||||
*/
|
||||
@JsonDeserialize(using = KnowledgeStatisticsDeserializer.class)
|
||||
public class KnowledgeStatistics extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class KnowledgeStatistics {
|
||||
|
||||
/**
|
||||
* Statistical word count
|
||||
|
|
@ -27,50 +28,4 @@ public class KnowledgeStatistics extends ObjectNode {
|
|||
@JsonProperty("length")
|
||||
private Integer length;
|
||||
|
||||
public KnowledgeStatistics() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public KnowledgeStatistics(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
if (objectNode.has("word_num")) {
|
||||
this.setWordNum(objectNode.get("word_num").asInt());
|
||||
}
|
||||
else {
|
||||
this.setWordNum(null);
|
||||
}
|
||||
if (objectNode.has("length")) {
|
||||
this.setLength(objectNode.get("length").asInt());
|
||||
}
|
||||
else {
|
||||
this.setLength(null);
|
||||
}
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public Integer getWordNum() {
|
||||
return wordNum;
|
||||
}
|
||||
|
||||
public void setWordNum(Integer wordNum) {
|
||||
this.wordNum = wordNum;
|
||||
this.put("word_num", wordNum);
|
||||
}
|
||||
|
||||
public Integer getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(Integer length) {
|
||||
this.length = length;
|
||||
this.put("length", length);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,20 @@
|
|||
package ai.z.openapi.service.knowledge;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.knowledge.KnowledgeUsedDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the usage information of the knowledge base.
|
||||
*/
|
||||
@JsonDeserialize(using = KnowledgeUsedDeserializer.class)
|
||||
public class KnowledgeUsed extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class KnowledgeUsed {
|
||||
|
||||
/**
|
||||
* Used amount
|
||||
|
|
@ -29,52 +28,4 @@ public class KnowledgeUsed extends ObjectNode {
|
|||
@JsonProperty("total")
|
||||
private KnowledgeStatistics total;
|
||||
|
||||
public KnowledgeUsed() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public KnowledgeUsed(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.has("used")) {
|
||||
this.setUsed(objectMapper.convertValue(objectNode.get("used"), KnowledgeStatistics.class));
|
||||
}
|
||||
else {
|
||||
this.setUsed(null);
|
||||
}
|
||||
if (objectNode.has("total")) {
|
||||
this.setTotal(objectMapper.convertValue(objectNode.get("total"), KnowledgeStatistics.class));
|
||||
}
|
||||
else {
|
||||
this.setTotal(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public KnowledgeStatistics getUsed() {
|
||||
return used;
|
||||
}
|
||||
|
||||
public void setUsed(KnowledgeStatistics used) {
|
||||
this.used = used;
|
||||
this.set("used", used);
|
||||
}
|
||||
|
||||
public KnowledgeStatistics getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(KnowledgeStatistics total) {
|
||||
this.total = total;
|
||||
this.set("total", total);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,21 @@
|
|||
package ai.z.openapi.service.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentDataDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the document data, including metadata and processing status.
|
||||
*/
|
||||
@JsonDeserialize(using = DocumentDataDeserializer.class)
|
||||
public class DocumentData extends ObjectNode {
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DocumentData {
|
||||
|
||||
/**
|
||||
* Knowledge unique ID
|
||||
|
|
@ -74,172 +72,4 @@ public class DocumentData extends ObjectNode {
|
|||
@JsonProperty("failInfo")
|
||||
private DocumentDataFailInfo failInfo;
|
||||
|
||||
public DocumentData() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public DocumentData(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode == null) {
|
||||
return;
|
||||
}
|
||||
if (objectNode.get("id") != null) {
|
||||
this.setId(objectNode.get("id").asText());
|
||||
}
|
||||
else {
|
||||
this.setId(null);
|
||||
}
|
||||
if (objectNode.get("custom_separator") != null) {
|
||||
List<String> customSeparator = objectNode.findValuesAsText("custom_separator");
|
||||
this.setCustomSeparator(customSeparator);
|
||||
}
|
||||
else {
|
||||
this.setCustomSeparator(null);
|
||||
}
|
||||
if (objectNode.get("sentence_size") != null) {
|
||||
this.setSentenceSize(objectNode.get("sentence_size").asText());
|
||||
}
|
||||
else {
|
||||
this.setSentenceSize(null);
|
||||
}
|
||||
if (objectNode.get("length") != null) {
|
||||
this.setLength(objectNode.get("length").asInt());
|
||||
}
|
||||
else {
|
||||
this.setLength(null);
|
||||
}
|
||||
if (objectNode.get("word_num") != null) {
|
||||
this.setWordNum(objectNode.get("word_num").asInt());
|
||||
}
|
||||
else {
|
||||
this.setWordNum(null);
|
||||
}
|
||||
if (objectNode.get("name") != null) {
|
||||
this.setName(objectNode.get("name").asText());
|
||||
}
|
||||
else {
|
||||
this.setName(null);
|
||||
}
|
||||
if (objectNode.get("url") != null) {
|
||||
this.setUrl(objectNode.get("url").asText());
|
||||
}
|
||||
else {
|
||||
this.setUrl(null);
|
||||
}
|
||||
if (objectNode.get("embedding_stat") != null) {
|
||||
this.setEmbeddingStat(objectNode.get("embedding_stat").asInt());
|
||||
}
|
||||
else {
|
||||
this.setEmbeddingStat(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("failInfo") != null) {
|
||||
DocumentDataFailInfo failInfo = objectMapper.convertValue(objectNode.get("failInfo"),
|
||||
DocumentDataFailInfo.class);
|
||||
this.setFailInfo(failInfo);
|
||||
}
|
||||
else {
|
||||
this.setFailInfo(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
// Getters and Setters
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
this.put("id", id);
|
||||
}
|
||||
|
||||
public List<String> getCustomSeparator() {
|
||||
return customSeparator;
|
||||
}
|
||||
|
||||
public void setCustomSeparator(List<String> customSeparator) {
|
||||
this.customSeparator = customSeparator;
|
||||
ArrayNode jsonNodes = this.putArray("customSeparator");
|
||||
if (customSeparator == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
for (String item : customSeparator) {
|
||||
jsonNodes.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getSentenceSize() {
|
||||
return sentenceSize;
|
||||
}
|
||||
|
||||
public void setSentenceSize(String sentenceSize) {
|
||||
this.sentenceSize = sentenceSize;
|
||||
this.put("sentenceSize", sentenceSize);
|
||||
}
|
||||
|
||||
public Integer getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(Integer length) {
|
||||
this.length = length;
|
||||
this.put("length", length);
|
||||
}
|
||||
|
||||
public Integer getWordNum() {
|
||||
return wordNum;
|
||||
}
|
||||
|
||||
public void setWordNum(Integer wordNum) {
|
||||
this.wordNum = wordNum;
|
||||
this.put("wordNum", wordNum);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.put("name", name);
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
this.put("url", url);
|
||||
}
|
||||
|
||||
public Integer getEmbeddingStat() {
|
||||
return embeddingStat;
|
||||
}
|
||||
|
||||
public void setEmbeddingStat(Integer embeddingStat) {
|
||||
this.embeddingStat = embeddingStat;
|
||||
this.put("embeddingStat", embeddingStat);
|
||||
}
|
||||
|
||||
public DocumentDataFailInfo getFailInfo() {
|
||||
return failInfo;
|
||||
}
|
||||
|
||||
public void setFailInfo(DocumentDataFailInfo failInfo) {
|
||||
this.failInfo = failInfo;
|
||||
this.putPOJO("failInfo", failInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
package ai.z.openapi.service.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentDataFailInfoDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the failure information of document data processing.
|
||||
*/
|
||||
@JsonDeserialize(using = DocumentDataFailInfoDeserializer.class)
|
||||
public class DocumentDataFailInfo extends ObjectNode {
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class DocumentDataFailInfo {
|
||||
|
||||
/**
|
||||
* Failure code 10001: Knowledge unavailable, knowledge base space has reached the
|
||||
|
|
@ -29,52 +30,4 @@ public class DocumentDataFailInfo extends ObjectNode {
|
|||
@JsonProperty("embedding_msg")
|
||||
private String embeddingMsg;
|
||||
|
||||
public DocumentDataFailInfo() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public DocumentDataFailInfo(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
|
||||
if (objectNode.get("embedding_code") != null) {
|
||||
this.setEmbeddingCode(objectNode.get("embedding_code").asInt());
|
||||
}
|
||||
else {
|
||||
this.setEmbeddingCode(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("embedding_msg") != null) {
|
||||
this.setEmbeddingMsg(objectNode.get("embedding_msg").asText());
|
||||
|
||||
}
|
||||
else {
|
||||
this.setEmbeddingMsg(null);
|
||||
}
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
// Getters and Setters
|
||||
|
||||
public Integer getEmbeddingCode() {
|
||||
return embeddingCode;
|
||||
}
|
||||
|
||||
public void setEmbeddingCode(Integer embeddingCode) {
|
||||
this.embeddingCode = embeddingCode;
|
||||
this.put("embedding_code", embeddingCode);
|
||||
}
|
||||
|
||||
public String getEmbeddingMsg() {
|
||||
return embeddingMsg;
|
||||
}
|
||||
|
||||
public void setEmbeddingMsg(String embeddingMsg) {
|
||||
this.embeddingMsg = embeddingMsg;
|
||||
this.put("embedding_msg", embeddingMsg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,54 +65,4 @@ public class DocumentEditParams implements ClientRequest<DocumentEditParams> {
|
|||
@JsonProperty("callback_header")
|
||||
private Map<String, String> callbackHeader;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getKnowledgeType() {
|
||||
return knowledgeType;
|
||||
}
|
||||
|
||||
public void setKnowledgeType(Integer knowledgeType) {
|
||||
this.knowledgeType = knowledgeType;
|
||||
}
|
||||
|
||||
public List<String> getCustomSeparator() {
|
||||
return customSeparator;
|
||||
}
|
||||
|
||||
public void setCustomSeparator(List<String> customSeparator) {
|
||||
this.customSeparator = customSeparator;
|
||||
}
|
||||
|
||||
public Integer getSentenceSize() {
|
||||
return sentenceSize;
|
||||
}
|
||||
|
||||
public void setSentenceSize(Integer sentenceSize) {
|
||||
this.sentenceSize = sentenceSize;
|
||||
}
|
||||
|
||||
public String getCallbackUrl() {
|
||||
return callbackUrl;
|
||||
}
|
||||
|
||||
public void setCallbackUrl(String callbackUrl) {
|
||||
this.callbackUrl = callbackUrl;
|
||||
}
|
||||
|
||||
public Map<String, String> getCallbackHeader() {
|
||||
return callbackHeader;
|
||||
}
|
||||
|
||||
public void setCallbackHeader(Map<String, String> callbackHeader) {
|
||||
this.callbackHeader = callbackHeader;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
package ai.z.openapi.service.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentFailedInfoDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the information of a failed document upload.
|
||||
*/
|
||||
@JsonDeserialize(using = DocumentFailedInfoDeserializer.class)
|
||||
public class DocumentFailedInfo extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DocumentFailedInfo {
|
||||
|
||||
/**
|
||||
* Reason for upload failure, including: unsupported file format, file size exceeds
|
||||
|
|
@ -34,71 +35,4 @@ public class DocumentFailedInfo extends ObjectNode {
|
|||
@JsonProperty("documentId")
|
||||
private String documentId;
|
||||
|
||||
public DocumentFailedInfo() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public DocumentFailedInfo(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
if (objectNode == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (objectNode.has("failReason")) {
|
||||
this.setFailReason(objectNode.get("failReason").asText());
|
||||
}
|
||||
else {
|
||||
this.setFailReason(null);
|
||||
}
|
||||
if (objectNode.has("filename")) {
|
||||
this.setFilename(objectNode.get("filename").asText());
|
||||
}
|
||||
else {
|
||||
this.setFilename(null);
|
||||
}
|
||||
|
||||
if (objectNode.has("documentId")) {
|
||||
this.setDocumentId(objectNode.get("documentId").asText());
|
||||
}
|
||||
else {
|
||||
this.setDocumentId(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
|
||||
}
|
||||
// Getters and Setters
|
||||
|
||||
public String getFailReason() {
|
||||
return failReason;
|
||||
}
|
||||
|
||||
public void setFailReason(String failReason) {
|
||||
this.failReason = failReason;
|
||||
this.put("failReason", failReason);
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
this.put("filename", filename);
|
||||
}
|
||||
|
||||
public String getDocumentId() {
|
||||
return documentId;
|
||||
}
|
||||
|
||||
public void setDocumentId(String documentId) {
|
||||
this.documentId = documentId;
|
||||
this.put("documentId", documentId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,21 @@
|
|||
package ai.z.openapi.service.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentObjectDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the document information including success and failure details.
|
||||
*/
|
||||
@JsonDeserialize(using = DocumentObjectDeserializer.class)
|
||||
public class DocumentObject extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DocumentObject {
|
||||
|
||||
/**
|
||||
* Information of successfully uploaded files
|
||||
|
|
@ -31,78 +29,4 @@ public class DocumentObject extends ObjectNode {
|
|||
@JsonProperty("failedInfos")
|
||||
private List<DocumentFailedInfo> failedInfos;
|
||||
|
||||
public DocumentObject() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public DocumentObject(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("successInfos") != null) {
|
||||
List<DocumentSuccessInfo> successInfos = objectMapper.convertValue(objectNode.get("successInfos"),
|
||||
new com.fasterxml.jackson.core.type.TypeReference<List<DocumentSuccessInfo>>() {
|
||||
});
|
||||
|
||||
this.setSuccessInfos(successInfos);
|
||||
}
|
||||
else {
|
||||
this.setSuccessInfos(null);
|
||||
}
|
||||
if (objectNode.get("failedInfos") != null) {
|
||||
List<DocumentFailedInfo> failedInfos = objectMapper.convertValue(objectNode.get("failedInfos"),
|
||||
new com.fasterxml.jackson.core.type.TypeReference<List<DocumentFailedInfo>>() {
|
||||
});
|
||||
|
||||
this.setFailedInfos(failedInfos);
|
||||
}
|
||||
else {
|
||||
this.setFailedInfos(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
// Getters and Setters
|
||||
|
||||
public List<DocumentSuccessInfo> getSuccessInfos() {
|
||||
return successInfos;
|
||||
}
|
||||
|
||||
public void setSuccessInfos(List<DocumentSuccessInfo> successInfos) {
|
||||
this.successInfos = successInfos;
|
||||
ArrayNode jsonNodes = this.putArray("successInfos");
|
||||
if (successInfos == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (DocumentSuccessInfo successInfo : successInfos) {
|
||||
jsonNodes.add(successInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<DocumentFailedInfo> getFailedInfos() {
|
||||
return failedInfos;
|
||||
}
|
||||
|
||||
public void setFailedInfos(List<DocumentFailedInfo> failedInfos) {
|
||||
this.failedInfos = failedInfos;
|
||||
ArrayNode jsonNodes = this.putArray("failedInfos");
|
||||
if (successInfos == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (DocumentFailedInfo failedInfo : failedInfos) {
|
||||
jsonNodes.add(failedInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
package ai.z.openapi.service.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentPageDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents a page of document data, including a list of document entries and
|
||||
* the object type.
|
||||
*/
|
||||
@JsonDeserialize(using = DocumentPageDeserializer.class)
|
||||
public class DocumentPage extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class DocumentPage {
|
||||
|
||||
/**
|
||||
* List of document data entries.
|
||||
|
|
@ -32,65 +30,4 @@ public class DocumentPage extends ObjectNode {
|
|||
@JsonProperty("object")
|
||||
private String object;
|
||||
|
||||
public DocumentPage() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public DocumentPage(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("list") != null) {
|
||||
List<DocumentData> list = objectMapper.convertValue(objectNode.get("list"),
|
||||
new com.fasterxml.jackson.core.type.TypeReference<List<DocumentData>>() {
|
||||
});
|
||||
|
||||
this.setList(list);
|
||||
}
|
||||
else {
|
||||
this.setList(null);
|
||||
}
|
||||
if (objectNode.get("object") != null) {
|
||||
this.setObject(objectNode.get("object").asText());
|
||||
}
|
||||
else {
|
||||
this.setObject(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
// Getters and Setters
|
||||
|
||||
public List<DocumentData> getList() {
|
||||
return list;
|
||||
}
|
||||
|
||||
public void setList(List<DocumentData> list) {
|
||||
this.list = list;
|
||||
ArrayNode jsonNodes = this.putArray("list");
|
||||
if (list == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (DocumentData documentData : list) {
|
||||
jsonNodes.add(documentData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public void setObject(String object) {
|
||||
this.object = object;
|
||||
this.put("object", object);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
package ai.z.openapi.service.knowledge.document;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.knowledge.document.DocumentSuccessInfoDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the information of a successfully uploaded document.
|
||||
*/
|
||||
@JsonDeserialize(using = DocumentSuccessInfoDeserializer.class)
|
||||
public class DocumentSuccessInfo extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DocumentSuccessInfo {
|
||||
|
||||
/**
|
||||
* File ID
|
||||
|
|
@ -27,51 +28,4 @@ public class DocumentSuccessInfo extends ObjectNode {
|
|||
@JsonProperty("filename")
|
||||
private String filename;
|
||||
|
||||
public DocumentSuccessInfo() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public DocumentSuccessInfo(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
if (objectNode == null) {
|
||||
return;
|
||||
}
|
||||
if (objectNode.has("documentId")) {
|
||||
this.setDocumentId(objectNode.get("documentId").asText());
|
||||
}
|
||||
else {
|
||||
this.setDocumentId(null);
|
||||
}
|
||||
if (objectNode.has("filename")) {
|
||||
this.setFilename(objectNode.get("filename").asText());
|
||||
}
|
||||
else {
|
||||
this.setFilename(null);
|
||||
}
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
public String getDocumentId() {
|
||||
return documentId;
|
||||
}
|
||||
|
||||
public void setDocumentId(String documentId) {
|
||||
this.documentId = documentId;
|
||||
this.put("documentId", documentId);
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void setFilename(String filename) {
|
||||
this.filename = filename;
|
||||
this.put("filename", filename);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,18 @@ package ai.z.openapi.service.knowledge.document;
|
|||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* This class represents the details required for uploading a file to the knowledge base.
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class UploadDetail {
|
||||
|
||||
/**
|
||||
|
|
@ -51,62 +59,4 @@ public class UploadDetail {
|
|||
@JsonProperty("callback_header")
|
||||
private Map<String, String> callbackHeader;
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public int getKnowledgeType() {
|
||||
return knowledgeType;
|
||||
}
|
||||
|
||||
public void setKnowledgeType(int knowledgeType) {
|
||||
this.knowledgeType = knowledgeType;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public Integer getSentenceSize() {
|
||||
return sentenceSize;
|
||||
}
|
||||
|
||||
public void setSentenceSize(Integer sentenceSize) {
|
||||
this.sentenceSize = sentenceSize;
|
||||
}
|
||||
|
||||
public List<String> getCustomSeparator() {
|
||||
return customSeparator;
|
||||
}
|
||||
|
||||
public void setCustomSeparator(List<String> customSeparator) {
|
||||
this.customSeparator = customSeparator;
|
||||
}
|
||||
|
||||
public String getCallbackUrl() {
|
||||
return callbackUrl;
|
||||
}
|
||||
|
||||
public void setCallbackUrl(String callbackUrl) {
|
||||
this.callbackUrl = callbackUrl;
|
||||
}
|
||||
|
||||
public Map<String, String> getCallbackHeader() {
|
||||
return callbackHeader;
|
||||
}
|
||||
|
||||
public void setCallbackHeader(Map<String, String> callbackHeader) {
|
||||
this.callbackHeader = callbackHeader;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,14 +1,22 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Audio {
|
||||
|
||||
private String id;
|
||||
|
||||
private String data;
|
||||
|
||||
private Long expires_at;
|
||||
@JsonProperty("expires_at")
|
||||
private Long expiresAt;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,15 @@ package ai.z.openapi.service.model;
|
|||
|
||||
import ai.z.openapi.core.model.FlowableClientResponse;
|
||||
import io.reactivex.Flowable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatCompletionResponse implements FlowableClientResponse<ModelData> {
|
||||
|
||||
private int code;
|
||||
|
|
@ -19,12 +25,4 @@ public class ChatCompletionResponse implements FlowableClientResponse<ModelData>
|
|||
|
||||
private ChatError error;
|
||||
|
||||
public ChatCompletionResponse() {
|
||||
}
|
||||
|
||||
public ChatCompletionResponse(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
public class ChatFunction extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatFunction {
|
||||
|
||||
private String name;
|
||||
|
||||
|
|
@ -19,77 +20,4 @@ public class ChatFunction extends ObjectNode {
|
|||
|
||||
private List<String> required;
|
||||
|
||||
public ChatFunction() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ChatFunction(JsonNodeFactory nc, Map<String, JsonNode> kids) {
|
||||
super(nc, kids);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.put("name", name);
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
this.put("description", description);
|
||||
}
|
||||
|
||||
public void setParameters(ChatFunctionParameters parameters) {
|
||||
this.parameters = parameters;
|
||||
this.set("parameters", parameters);
|
||||
}
|
||||
|
||||
public void setRequired(List<String> required) {
|
||||
this.required = required;
|
||||
this.putPOJO("required", required);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private ChatFunctionParameters parameters;
|
||||
|
||||
private List<String> required;
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder parameters(ChatFunctionParameters parameters) {
|
||||
this.parameters = parameters;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder required(List<String> required) {
|
||||
this.required = required;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ChatFunction build() {
|
||||
ChatFunction chatFunction = new ChatFunction();
|
||||
chatFunction.setName(name);
|
||||
chatFunction.setDescription(description);
|
||||
chatFunction.setParameters(parameters);
|
||||
chatFunction.setRequired(required);
|
||||
return chatFunction;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,20 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.ChatFunctionCallDeserializer;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents a function call generated by the chat model. This class contains the
|
||||
* function name and arguments that the model wants to invoke.
|
||||
*/
|
||||
@Getter
|
||||
@JsonDeserialize(using = ChatFunctionCallDeserializer.class)
|
||||
public class ChatFunctionCall extends ObjectNode {
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class ChatFunctionCall {
|
||||
|
||||
/**
|
||||
* Name of the function that the model wants to call.
|
||||
|
|
@ -32,45 +29,4 @@ public class ChatFunctionCall extends ObjectNode {
|
|||
*/
|
||||
JsonNode arguments;
|
||||
|
||||
public ChatFunctionCall() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ChatFunctionCall(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("name") != null) {
|
||||
this.setName(objectNode.get("name").asText());
|
||||
}
|
||||
else {
|
||||
this.setName(null);
|
||||
}
|
||||
if (objectNode.get("arguments") != null) {
|
||||
this.setArguments(objectNode.get("arguments"));
|
||||
}
|
||||
else {
|
||||
this.setArguments(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.put("name", name);
|
||||
}
|
||||
|
||||
public void setArguments(JsonNode arguments) {
|
||||
this.arguments = arguments;
|
||||
this.set("arguments", arguments);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,18 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.ChatMessageDeserializer;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@JsonDeserialize(using = ChatMessageDeserializer.class)
|
||||
public class ChatMessage extends ObjectNode {
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class ChatMessage {
|
||||
|
||||
private String role;
|
||||
|
||||
|
|
@ -27,105 +23,14 @@ public class ChatMessage extends ObjectNode {
|
|||
private String name;
|
||||
|
||||
@JsonProperty("tool_calls")
|
||||
private List<ToolCalls> tool_calls;
|
||||
private List<ToolCalls> toolCalls;
|
||||
|
||||
private String tool_call_id;
|
||||
|
||||
public ChatMessage() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
@JsonProperty("tool_call_id")
|
||||
private String toolCallId;
|
||||
|
||||
public ChatMessage(String role, Object content) {
|
||||
|
||||
super(JsonNodeFactory.instance);
|
||||
this.setRole(role);
|
||||
this.setContent(content);
|
||||
}
|
||||
|
||||
public ChatMessage(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("role") != null) {
|
||||
this.setRole(objectNode.get("role").asText());
|
||||
}
|
||||
else {
|
||||
this.setRole(null);
|
||||
}
|
||||
if (objectNode.get("content") != null) {
|
||||
this.setContent(objectNode.get("content").asText());
|
||||
}
|
||||
else {
|
||||
this.setContent(null);
|
||||
}
|
||||
if (objectNode.get("name") != null) {
|
||||
this.setName(objectNode.get("name").asText());
|
||||
}
|
||||
else {
|
||||
this.setName(null);
|
||||
}
|
||||
if (objectNode.get("tool_calls") != null) {
|
||||
this.setTool_calls(objectMapper.convertValue(objectNode.get("tool_calls"),
|
||||
new com.fasterxml.jackson.core.type.TypeReference<List<ToolCalls>>() {
|
||||
}));
|
||||
}
|
||||
else {
|
||||
this.setTool_calls(null);
|
||||
}
|
||||
if (objectNode.get("tool_call_id") != null) {
|
||||
this.setTool_call_id(objectNode.get("tool_call_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setTool_call_id(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
this.put("role", role);
|
||||
}
|
||||
|
||||
public void setContent(Object content) {
|
||||
this.content = content;
|
||||
this.putPOJO("content", content);
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
this.put("name", name);
|
||||
}
|
||||
|
||||
public void setTool_calls(List<ToolCalls> tool_calls) {
|
||||
this.tool_calls = tool_calls;
|
||||
ArrayNode toolCalls = this.putArray("tool_calls");
|
||||
if (tool_calls == null) {
|
||||
toolCalls.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (ToolCalls toolCall : tool_calls) {
|
||||
toolCalls.add(toolCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTool_call_id(String tool_call_id) {
|
||||
this.tool_call_id = tool_call_id;
|
||||
this.put("tool_call_id", tool_call_id);
|
||||
}
|
||||
|
||||
public void setAudio(Audio audio) {
|
||||
this.audio = audio;
|
||||
this.putPOJO("audio", audio);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,57 +0,0 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
/**
|
||||
* Class that accumulates chat messages and provides utility methods for handling message
|
||||
* chunks and function calls within a chat stream. This class is immutable.
|
||||
*
|
||||
* @author [Your Name]
|
||||
*/
|
||||
public class ChatMessageAccumulator {
|
||||
|
||||
private final ChatMessage accumulatedMessage;
|
||||
|
||||
private final Delta delta;
|
||||
|
||||
private final Choice choice;
|
||||
|
||||
private final Usage usage;
|
||||
|
||||
private final Long created;
|
||||
|
||||
private final String id;
|
||||
|
||||
public ChatMessageAccumulator(Delta delta, ChatMessage accumulatedMessage, Choice choice, Usage usage, Long created,
|
||||
String id) {
|
||||
this.delta = delta;
|
||||
this.accumulatedMessage = accumulatedMessage;
|
||||
this.choice = choice;
|
||||
this.usage = usage;
|
||||
this.created = created;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Delta getDelta() {
|
||||
return delta;
|
||||
}
|
||||
|
||||
public ChatMessage getAccumulatedMessage() {
|
||||
return accumulatedMessage;
|
||||
}
|
||||
|
||||
public Choice getChoice() {
|
||||
return choice;
|
||||
}
|
||||
|
||||
public Usage getUsage() {
|
||||
return usage;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Long getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Meta information for hyper-realistic conversations. Contains role and user information
|
||||
|
|
@ -8,26 +12,33 @@ import lombok.Data;
|
|||
* role/bot name - user_name: user name
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ChatMeta {
|
||||
|
||||
/**
|
||||
* User information.
|
||||
*/
|
||||
private String user_info;
|
||||
@JsonProperty("user_info")
|
||||
private String userInfo;
|
||||
|
||||
/**
|
||||
* Bot/role information.
|
||||
*/
|
||||
private String bot_info;
|
||||
@JsonProperty("bot_info")
|
||||
private String botInfo;
|
||||
|
||||
/**
|
||||
* Bot/role name.
|
||||
*/
|
||||
private String bot_name;
|
||||
@JsonProperty("bot_name")
|
||||
private String botName;
|
||||
|
||||
/**
|
||||
* User name.
|
||||
*/
|
||||
private String user_name;
|
||||
@JsonProperty("user_name")
|
||||
private String userName;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +1,26 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public class ChatTool extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ChatTool {
|
||||
|
||||
private String type;
|
||||
|
||||
@JsonProperty("function")
|
||||
private ChatFunction function;
|
||||
|
||||
@JsonProperty("retrieval")
|
||||
private Retrieval retrieval;
|
||||
|
||||
@JsonProperty("web_search")
|
||||
private WebSearch web_search;
|
||||
|
||||
public ChatTool() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ChatTool(JsonNodeFactory nc, Map<String, JsonNode> kids) {
|
||||
super(nc, kids);
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
this.put("type", type);
|
||||
}
|
||||
|
||||
public void setFunction(ChatFunction function) {
|
||||
this.function = function;
|
||||
this.putPOJO("function", function);
|
||||
}
|
||||
|
||||
public void setRetrieval(Retrieval retrieval) {
|
||||
this.retrieval = retrieval;
|
||||
this.putPOJO("retrieval", retrieval);
|
||||
}
|
||||
|
||||
public void setWeb_search(WebSearch web_search) {
|
||||
this.web_search = web_search;
|
||||
this.putPOJO("web_search", web_search);
|
||||
}
|
||||
private WebSearch webSearch;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.ChoiceDeserializer;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import lombok.Getter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@Getter
|
||||
@JsonDeserialize(using = ChoiceDeserializer.class)
|
||||
public class Choice extends ObjectNode {
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class Choice {
|
||||
|
||||
@JsonProperty("finish_reason")
|
||||
private String finishReason;
|
||||
|
|
@ -28,66 +24,4 @@ public class Choice extends ObjectNode {
|
|||
@JsonProperty("delta")
|
||||
private Delta delta;
|
||||
|
||||
public Choice() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public Choice(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("finish_reason") != null) {
|
||||
this.setFinishReason(objectNode.get("finish_reason").asText());
|
||||
}
|
||||
else {
|
||||
this.setFinishReason(null);
|
||||
}
|
||||
if (objectNode.get("index") != null) {
|
||||
this.setIndex(objectNode.get("index").asLong());
|
||||
}
|
||||
else {
|
||||
this.setIndex(null);
|
||||
}
|
||||
if (objectNode.get("message") != null) {
|
||||
this.setMessage(objectMapper.convertValue(objectNode.get("message"), ChatMessage.class));
|
||||
}
|
||||
else {
|
||||
this.setMessage(null);
|
||||
}
|
||||
if (objectNode.get("delta") != null) {
|
||||
this.setDelta(objectMapper.convertValue(objectNode.get("delta"), Delta.class));
|
||||
}
|
||||
else {
|
||||
this.setDelta(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
public void setFinishReason(String finishReason) {
|
||||
this.finishReason = finishReason;
|
||||
this.put("finish_reason", finishReason);
|
||||
}
|
||||
|
||||
public void setIndex(Long index) {
|
||||
this.index = index;
|
||||
this.put("index", index);
|
||||
}
|
||||
|
||||
public void setMessage(ChatMessage message) {
|
||||
this.message = message;
|
||||
this.putPOJO("message", message);
|
||||
}
|
||||
|
||||
public void setDelta(Delta delta) {
|
||||
this.delta = delta;
|
||||
this.putPOJO("delta", delta);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,102 +1,26 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.DeltaDeserializer;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@JsonDeserialize(using = DeltaDeserializer.class)
|
||||
public class Delta extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Delta {
|
||||
|
||||
private String role;
|
||||
|
||||
private String content;
|
||||
|
||||
@Setter
|
||||
private Audio audio;
|
||||
|
||||
@JsonProperty("tool_calls")
|
||||
private List<ToolCalls> tool_calls;
|
||||
|
||||
public Delta() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public Delta(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("role") != null) {
|
||||
this.setRole(objectNode.get("role").asText());
|
||||
}
|
||||
else {
|
||||
this.setRole(null);
|
||||
}
|
||||
if (objectNode.get("content") != null) {
|
||||
this.setContent(objectNode.get("content").asText());
|
||||
}
|
||||
else {
|
||||
this.setContent(null);
|
||||
}
|
||||
if (objectNode.get("tool_calls") != null) {
|
||||
this.setTool_calls(
|
||||
objectMapper.convertValue(objectNode.get("tool_calls"), new TypeReference<List<ToolCalls>>() {
|
||||
}));
|
||||
}
|
||||
else {
|
||||
this.setTool_calls(null);
|
||||
}
|
||||
if (objectNode.get("audio") != null) {
|
||||
Audio audio = objectMapper.convertValue(objectNode.get("audio"), new TypeReference<Audio>() {
|
||||
});
|
||||
this.setAudio(audio);
|
||||
}
|
||||
else {
|
||||
this.setAudio(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
this.put("role", role);
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
this.put("content", content);
|
||||
}
|
||||
|
||||
public void setTool_calls(List<ToolCalls> tool_calls) {
|
||||
this.tool_calls = tool_calls;
|
||||
|
||||
ArrayNode toolCalls = this.putArray("tool_calls");
|
||||
if (tool_calls == null) {
|
||||
toolCalls.removeAll();
|
||||
}
|
||||
else {
|
||||
for (ToolCalls toolCall : tool_calls) {
|
||||
toolCalls.add(toolCall);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +1,23 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.ModelDataDeserializer;
|
||||
import ai.z.openapi.service.web_search.WebSearchResp;
|
||||
import lombok.Getter;
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@JsonDeserialize(using = ModelDataDeserializer.class)
|
||||
@Getter
|
||||
public final class ModelData extends ObjectNode {
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public final class ModelData {
|
||||
|
||||
@JsonProperty("choices")
|
||||
private List<Choice> choices;
|
||||
|
||||
@JsonProperty("usage")
|
||||
private Usage usage;
|
||||
|
||||
@JsonProperty("request_id")
|
||||
|
|
@ -37,11 +32,14 @@ public final class ModelData extends ObjectNode {
|
|||
|
||||
private String id;
|
||||
|
||||
private String agent_id;
|
||||
@JsonProperty("agent_id")
|
||||
private String agentId;
|
||||
|
||||
private String conversation_id;
|
||||
@JsonProperty("conversation_id")
|
||||
private String conversationId;
|
||||
|
||||
private String async_id;
|
||||
@JsonProperty("async_id")
|
||||
private String asyncId;
|
||||
|
||||
private String status;
|
||||
|
||||
|
|
@ -56,219 +54,4 @@ public final class ModelData extends ObjectNode {
|
|||
|
||||
private String delta;
|
||||
|
||||
public ModelData() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ModelData(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("choices") != null) {
|
||||
List<Choice> choices1 = objectMapper.convertValue(objectNode.get("choices"),
|
||||
new TypeReference<List<Choice>>() {
|
||||
});
|
||||
|
||||
this.setChoices(choices1);
|
||||
}
|
||||
else {
|
||||
this.setChoices(null);
|
||||
}
|
||||
if (objectNode.get("usage") != null) {
|
||||
this.setUsage(objectMapper.convertValue(objectNode.get("usage"), Usage.class));
|
||||
}
|
||||
else {
|
||||
this.setUsage(null);
|
||||
}
|
||||
if (objectNode.get("request_id") != null) {
|
||||
this.setRequestId(objectNode.get("request_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setRequestId(null);
|
||||
}
|
||||
if (objectNode.get("task_status") != null) {
|
||||
this.setTaskStatus(objectMapper.convertValue(objectNode.get("task_status"), TaskStatus.class));
|
||||
}
|
||||
else {
|
||||
this.setTaskStatus(null);
|
||||
}
|
||||
if (objectNode.get("created") != null) {
|
||||
this.setCreated(objectNode.get("created").asLong());
|
||||
}
|
||||
else {
|
||||
this.setCreated(null);
|
||||
}
|
||||
if (objectNode.get("model") != null) {
|
||||
this.setModel(objectNode.get("model").asText());
|
||||
}
|
||||
else {
|
||||
this.setModel(null);
|
||||
}
|
||||
if (objectNode.get("id") != null) {
|
||||
this.setId(objectNode.get("id").asText());
|
||||
}
|
||||
else {
|
||||
this.setId(null);
|
||||
}
|
||||
if (objectNode.get("agent_id") != null) {
|
||||
this.setAgent_id(objectNode.get("agent_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setAgent_id(null);
|
||||
}
|
||||
if (objectNode.get("conversation_id") != null) {
|
||||
this.setConversation_id(objectNode.get("conversation_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setConversation_id(null);
|
||||
}
|
||||
if (objectNode.get("async_id") != null) {
|
||||
this.setAsync_id(objectNode.get("async_id").asText());
|
||||
}
|
||||
else {
|
||||
this.setAsync_id(null);
|
||||
}
|
||||
if (objectNode.get("status") != null) {
|
||||
this.setStatus(objectNode.get("status").asText());
|
||||
}
|
||||
else {
|
||||
this.setStatus(null);
|
||||
}
|
||||
if (objectNode.get("web_search") != null) {
|
||||
this.setWebSearch(objectMapper.convertValue(objectNode.get("web_search"), List.class));
|
||||
}
|
||||
else {
|
||||
this.setWebSearch(null);
|
||||
}
|
||||
if (objectNode.get("text") != null) {
|
||||
this.setText(objectNode.get("text").asText());
|
||||
}
|
||||
else {
|
||||
this.setText(null);
|
||||
}
|
||||
if (objectNode.get("type") != null) {
|
||||
this.setType(objectNode.get("type").asText());
|
||||
}
|
||||
else {
|
||||
this.setType(null);
|
||||
}
|
||||
if (objectNode.get("segments") != null) {
|
||||
List<Segment> segments = objectMapper.convertValue(objectNode.get("segments"),
|
||||
new TypeReference<List<Segment>>() {
|
||||
});
|
||||
this.setSegments(segments);
|
||||
}
|
||||
else {
|
||||
this.setSegments(null);
|
||||
}
|
||||
if (objectNode.get("delta") != null) {
|
||||
this.setDelta(objectMapper.convertValue(objectNode.get("delta"), String.class));
|
||||
}
|
||||
else {
|
||||
this.setDelta(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ModelData(JsonNodeFactory nc, Map<String, JsonNode> kids) {
|
||||
super(nc, kids);
|
||||
}
|
||||
|
||||
public void setChoices(List<Choice> choices) {
|
||||
this.choices = choices;
|
||||
ArrayNode jsonNodes = this.putArray("choices");
|
||||
if (choices == null) {
|
||||
jsonNodes.removeAll();
|
||||
}
|
||||
else {
|
||||
|
||||
for (Choice choice : choices) {
|
||||
jsonNodes.add(choice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setUsage(Usage usage) {
|
||||
this.usage = usage;
|
||||
this.putPOJO("usage", usage);
|
||||
}
|
||||
|
||||
public void setRequestId(String requestId) {
|
||||
this.requestId = requestId;
|
||||
this.put("request_id", requestId);
|
||||
}
|
||||
|
||||
public void setTaskStatus(TaskStatus taskStatus) {
|
||||
this.taskStatus = taskStatus;
|
||||
this.putPOJO("task_status", taskStatus);
|
||||
}
|
||||
|
||||
public void setCreated(Long created) {
|
||||
this.created = created;
|
||||
this.put("created", created);
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
this.put("model", model);
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
this.put("id", id);
|
||||
}
|
||||
|
||||
public void setWebSearch(List<WebSearchResp> webSearch) {
|
||||
this.webSearch = webSearch;
|
||||
this.putPOJO("web_search", webSearch);
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
this.put("text", text);
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
this.put("type", type);
|
||||
}
|
||||
|
||||
public void setSegments(List<Segment> segments) {
|
||||
this.segments = segments;
|
||||
this.putPOJO("segments", segments);
|
||||
}
|
||||
|
||||
public void setDelta(String delta) {
|
||||
this.delta = delta;
|
||||
this.put("delta", delta);
|
||||
}
|
||||
|
||||
public void setAgent_id(String agent_id) {
|
||||
this.agent_id = agent_id;
|
||||
this.put("agent_id", agent_id);
|
||||
}
|
||||
|
||||
public void setConversation_id(String conversation_id) {
|
||||
this.conversation_id = conversation_id;
|
||||
this.put("conversation_id", conversation_id);
|
||||
}
|
||||
|
||||
public void setAsync_id(String async_id) {
|
||||
this.async_id = async_id;
|
||||
this.put("async_id", async_id);
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
this.put("status", status);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,23 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
public class Retrieval extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Retrieval {
|
||||
|
||||
/**
|
||||
* When involving knowledge base ID, please go to the knowledge base module of the
|
||||
* open platform to create or obtain it.
|
||||
*/
|
||||
private String knowledge_id;
|
||||
@JsonProperty("knowledge_id")
|
||||
private String knowledgeId;
|
||||
|
||||
/**
|
||||
* Knowledge base template when requesting the model, default template: Find the
|
||||
|
|
@ -29,24 +31,7 @@ public class Retrieval extends ObjectNode {
|
|||
* user-side question placeholder must be {{ knowledge}} and {{question}}, other
|
||||
* template content can be defined by users according to actual scenarios
|
||||
*/
|
||||
private String prompt_template;
|
||||
|
||||
public Retrieval() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public Retrieval(JsonNodeFactory nc, Map<String, JsonNode> kids) {
|
||||
super(nc, kids);
|
||||
}
|
||||
|
||||
public void setKnowledge_id(String knowledge_id) {
|
||||
this.knowledge_id = knowledge_id;
|
||||
this.put("knowledge_id", knowledge_id);
|
||||
}
|
||||
|
||||
public void setPrompt_template(String prompt_template) {
|
||||
this.prompt_template = prompt_template;
|
||||
this.put("prompt_template", prompt_template);
|
||||
}
|
||||
@JsonProperty("prompt_template")
|
||||
private String promptTemplate;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Segment {
|
||||
|
||||
private Integer id;
|
||||
|
|
|
|||
|
|
@ -1,25 +1,21 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.ToolCallsDeserializer;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents tool calls made by the model during conversation. This class contains
|
||||
* information about function calls including the function details, unique identifier, and
|
||||
* call type.
|
||||
*/
|
||||
@Getter
|
||||
@JsonDeserialize(using = ToolCallsDeserializer.class)
|
||||
public class ToolCalls extends ObjectNode {
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class ToolCalls {
|
||||
|
||||
@JsonProperty("function")
|
||||
private ChatFunctionCall function;
|
||||
|
|
@ -36,56 +32,4 @@ public class ToolCalls extends ObjectNode {
|
|||
@JsonProperty("type")
|
||||
private String type;
|
||||
|
||||
public ToolCalls() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ToolCalls(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("function") != null) {
|
||||
this.setFunction(objectMapper.convertValue(objectNode.get("function"), ChatFunctionCall.class));
|
||||
}
|
||||
else {
|
||||
this.setFunction(null);
|
||||
}
|
||||
if (objectNode.get("id") != null) {
|
||||
this.setId(objectNode.get("id").asText());
|
||||
}
|
||||
else {
|
||||
this.setId(null);
|
||||
}
|
||||
if (objectNode.get("type") != null) {
|
||||
this.setType(objectNode.get("type").asText());
|
||||
}
|
||||
else {
|
||||
this.setType(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setFunction(ChatFunctionCall function) {
|
||||
this.function = function;
|
||||
this.putPOJO("function", function);
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
this.put("id", id);
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
this.put("type", type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -40,28 +40,4 @@ public class Usage {
|
|||
@JsonProperty("total_calls")
|
||||
private int totalCalls;
|
||||
|
||||
public int getPromptTokens() {
|
||||
return promptTokens;
|
||||
}
|
||||
|
||||
public void setPromptTokens(int promptTokens) {
|
||||
this.promptTokens = promptTokens;
|
||||
}
|
||||
|
||||
public int getCompletionTokens() {
|
||||
return completionTokens;
|
||||
}
|
||||
|
||||
public void setCompletionTokens(int completionTokens) {
|
||||
this.completionTokens = completionTokens;
|
||||
}
|
||||
|
||||
public int getTotalTokens() {
|
||||
return totalTokens;
|
||||
}
|
||||
|
||||
public void setTotalTokens(int totalTokens) {
|
||||
this.totalTokens = totalTokens;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,18 +1,20 @@
|
|||
package ai.z.openapi.service.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Configuration class for web search functionality. This class defines various parameters
|
||||
* and settings for web search operations.
|
||||
*/
|
||||
@Getter
|
||||
public class WebSearch extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WebSearch {
|
||||
|
||||
/**
|
||||
* Whether to enable search, defaults to enabled. true: enabled false: disabled
|
||||
|
|
@ -23,115 +25,62 @@ public class WebSearch extends ObjectNode {
|
|||
* Whether to return search results, defaults to returning results. true: return
|
||||
* results false: do not return results
|
||||
*/
|
||||
private Boolean search_result;
|
||||
@JsonProperty("search_result")
|
||||
private Boolean searchResult;
|
||||
|
||||
/**
|
||||
* Force search for custom keyword content. The model will use the results from custom
|
||||
* search keywords as background knowledge to answer user conversations.
|
||||
*/
|
||||
private String search_query;
|
||||
@JsonProperty("search_query")
|
||||
private String searchQuery;
|
||||
|
||||
/**
|
||||
* Prompt for specifying search engine output results.
|
||||
*/
|
||||
private String search_prompt;
|
||||
@JsonProperty("search_prompt")
|
||||
private String searchPrompt;
|
||||
|
||||
/**
|
||||
* Specify the search engine to use.
|
||||
*/
|
||||
private String search_engine;
|
||||
@JsonProperty("search_engine")
|
||||
private String searchEngine;
|
||||
|
||||
/**
|
||||
* Whether search results must be obtained before answering.
|
||||
*/
|
||||
private Boolean require_search;
|
||||
@JsonProperty("require_search")
|
||||
private Boolean requireSearch;
|
||||
|
||||
/**
|
||||
* Output position of search results.
|
||||
*/
|
||||
private String result_sequence;
|
||||
@JsonProperty("result_sequence")
|
||||
private String resultSequence;
|
||||
|
||||
/**
|
||||
* Number of results to return.
|
||||
*/
|
||||
@JsonProperty("count")
|
||||
private Integer count;
|
||||
|
||||
/**
|
||||
* Domain filter to limit search result scope.
|
||||
*/
|
||||
private String search_domain_filter;
|
||||
@JsonProperty("search_domain_filter")
|
||||
private String searchDomainFilter;
|
||||
|
||||
/**
|
||||
* Recency filter to limit search result scope.
|
||||
*/
|
||||
private String search_recency_filter;
|
||||
@JsonProperty("search_recency_filter")
|
||||
private String searchRecencyFilter;
|
||||
|
||||
/**
|
||||
* Control the word count of web page summaries.
|
||||
*/
|
||||
private String content_size;
|
||||
|
||||
public WebSearch() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public WebSearch(JsonNodeFactory nc, Map<String, JsonNode> kids) {
|
||||
super(nc, kids);
|
||||
}
|
||||
|
||||
public void setEnable(Boolean enable) {
|
||||
this.enable = enable;
|
||||
this.put("enable", enable);
|
||||
}
|
||||
|
||||
public void setSearch_result(Boolean search_result) {
|
||||
this.search_result = search_result;
|
||||
this.put("search_result", search_result);
|
||||
}
|
||||
|
||||
public void setSearch_query(String search_query) {
|
||||
this.search_query = search_query;
|
||||
this.put("search_query", search_query);
|
||||
}
|
||||
|
||||
public void setSearch_prompt(String search_prompt) {
|
||||
this.search_prompt = search_prompt;
|
||||
this.put("search_prompt", search_prompt);
|
||||
}
|
||||
|
||||
public void setSearch_engine(String search_engine) {
|
||||
this.search_engine = search_engine;
|
||||
this.put("search_engine", search_engine);
|
||||
}
|
||||
|
||||
public void setRequire_search(Boolean require_search) {
|
||||
this.require_search = require_search;
|
||||
this.put("require_search", require_search);
|
||||
}
|
||||
|
||||
public void setResult_sequence(String result_sequence) {
|
||||
this.result_sequence = result_sequence;
|
||||
this.put("result_sequence", result_sequence);
|
||||
}
|
||||
|
||||
public void setCount(Integer count) {
|
||||
this.count = count;
|
||||
this.put("count", count);
|
||||
}
|
||||
|
||||
public void setSearch_domain_filter(String search_domain_filter) {
|
||||
this.search_domain_filter = search_domain_filter;
|
||||
this.put("search_domain_filter", search_domain_filter);
|
||||
}
|
||||
|
||||
public void setSearch_recency_filter(String search_recency_filter) {
|
||||
this.search_recency_filter = search_recency_filter;
|
||||
this.put("search_recency_filter", search_recency_filter);
|
||||
}
|
||||
|
||||
public void setContent_size(String content_size) {
|
||||
this.content_size = content_size;
|
||||
this.put("content_size", content_size);
|
||||
}
|
||||
@JsonProperty("content_size")
|
||||
private String contentSize;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,16 @@
|
|||
package ai.z.openapi.service.model.params;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.CodeGeexContextDeserializer;
|
||||
import lombok.Getter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter
|
||||
@JsonDeserialize(using = CodeGeexContextDeserializer.class)
|
||||
public class CodeGeexContext extends ObjectNode {
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class CodeGeexContext {
|
||||
|
||||
@JsonProperty("path")
|
||||
private String path;
|
||||
|
|
@ -21,38 +18,4 @@ public class CodeGeexContext extends ObjectNode {
|
|||
@JsonProperty("code")
|
||||
private String code;
|
||||
|
||||
public CodeGeexContext() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public CodeGeexContext(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
this.setPath(objectNode.has("path") ? objectNode.get("path").asText() : null);
|
||||
this.setCode(objectNode.has("code") ? objectNode.get("code").asText() : null);
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public CodeGeexContext(JsonNodeFactory nc, Map<String, JsonNode> kids) {
|
||||
super(nc, kids);
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
this.put("path", path);
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
this.put("code", code);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
package ai.z.openapi.service.model.params;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CodeGeexTarget {
|
||||
|
||||
@JsonProperty("path")
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
package ai.z.openapi.service.tools;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.tools.ChoiceDeltaDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@JsonDeserialize(using = ChoiceDeltaDeserializer.class)
|
||||
public class ChoiceDelta extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ChoiceDelta {
|
||||
|
||||
/**
|
||||
* Role
|
||||
|
|
@ -28,54 +26,4 @@ public class ChoiceDelta extends ObjectNode {
|
|||
@JsonProperty("tool_calls")
|
||||
private List<ChoiceDeltaToolCall> toolCalls;
|
||||
|
||||
public ChoiceDelta() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ChoiceDelta(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.has("role")) {
|
||||
this.setRole(objectNode.get("role").asText());
|
||||
}
|
||||
else {
|
||||
this.setRole(null);
|
||||
}
|
||||
if (objectNode.has("tool_calls")) {
|
||||
this.setToolCalls(objectMapper.convertValue(objectNode.get("tool_calls"),
|
||||
new TypeReference<List<ChoiceDeltaToolCall>>() {
|
||||
}));
|
||||
}
|
||||
else {
|
||||
this.setToolCalls(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
this.put("role", role);
|
||||
}
|
||||
|
||||
public List<ChoiceDeltaToolCall> getToolCalls() {
|
||||
return toolCalls;
|
||||
}
|
||||
|
||||
public void setToolCalls(List<ChoiceDeltaToolCall> toolCalls) {
|
||||
this.toolCalls = toolCalls;
|
||||
this.putPOJO("tool_calls", toolCalls);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
package ai.z.openapi.service.tools;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.tools.ChoiceDeltaToolCallDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@JsonDeserialize(using = ChoiceDeltaToolCallDeserializer.class)
|
||||
public class ChoiceDeltaToolCall extends ObjectNode {
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class ChoiceDeltaToolCall {
|
||||
|
||||
/**
|
||||
* Index
|
||||
|
|
@ -30,13 +31,15 @@ public class ChoiceDeltaToolCall extends ObjectNode {
|
|||
* Search intent
|
||||
*/
|
||||
@JsonProperty("search_intent")
|
||||
private SearchIntent searchIntent;
|
||||
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
||||
private List<SearchIntent> searchIntent;
|
||||
|
||||
/**
|
||||
* Search result
|
||||
*/
|
||||
@JsonProperty("search_result")
|
||||
private SearchResult searchResult;
|
||||
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
|
||||
private List<SearchResult> searchResult;
|
||||
|
||||
/**
|
||||
* Recommended query
|
||||
|
|
@ -50,118 +53,4 @@ public class ChoiceDeltaToolCall extends ObjectNode {
|
|||
@JsonProperty("type")
|
||||
private String type;
|
||||
|
||||
public ChoiceDeltaToolCall() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public ChoiceDeltaToolCall(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("index") != null) {
|
||||
this.setIndex(objectNode.get("index").asInt());
|
||||
}
|
||||
else {
|
||||
this.setIndex(0);
|
||||
}
|
||||
|
||||
if (objectNode.get("id") != null) {
|
||||
this.setId(objectNode.get("id").asText());
|
||||
}
|
||||
else {
|
||||
this.setId(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("search_intent") != null) {
|
||||
this.setSearchIntent(objectMapper.convertValue(objectNode.get("search_intent"), SearchIntent.class));
|
||||
}
|
||||
else {
|
||||
this.setSearchIntent(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("search_result") != null) {
|
||||
this.setSearchResult(objectMapper.convertValue(objectNode.get("search_result"), SearchResult.class));
|
||||
}
|
||||
else {
|
||||
this.setSearchResult(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("search_recommend") != null) {
|
||||
this.setSearchRecommend(
|
||||
objectMapper.convertValue(objectNode.get("search_recommend"), SearchRecommend.class));
|
||||
}
|
||||
else {
|
||||
this.setSearchRecommend(null);
|
||||
}
|
||||
|
||||
if (objectNode.get("type") != null) {
|
||||
this.setType(objectNode.get("type").asText());
|
||||
}
|
||||
else {
|
||||
this.setType(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
this.put("index", index);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
this.put("id", id);
|
||||
}
|
||||
|
||||
public SearchIntent getSearchIntent() {
|
||||
return searchIntent;
|
||||
}
|
||||
|
||||
public void setSearchIntent(SearchIntent searchIntent) {
|
||||
this.searchIntent = searchIntent;
|
||||
this.set("search_intent", searchIntent);
|
||||
}
|
||||
|
||||
public SearchResult getSearchResult() {
|
||||
return searchResult;
|
||||
}
|
||||
|
||||
public void setSearchResult(SearchResult searchResult) {
|
||||
this.searchResult = searchResult;
|
||||
this.set("search_result", searchResult);
|
||||
}
|
||||
|
||||
public SearchRecommend getSearchRecommend() {
|
||||
return searchRecommend;
|
||||
}
|
||||
|
||||
public void setSearchRecommend(SearchRecommend searchRecommend) {
|
||||
this.searchRecommend = searchRecommend;
|
||||
this.set("search_recommend", searchRecommend);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
this.put("type", type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,70 +1,18 @@
|
|||
package ai.z.openapi.service.tools;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.tools.SearchChatMessageDeserializer;
|
||||
import lombok.Getter;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@JsonDeserialize(using = SearchChatMessageDeserializer.class)
|
||||
@Getter
|
||||
public class SearchChatMessage extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SearchChatMessage {
|
||||
|
||||
private String role;
|
||||
|
||||
private Object content;
|
||||
|
||||
public SearchChatMessage() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public SearchChatMessage(String role, Object content) {
|
||||
|
||||
super(JsonNodeFactory.instance);
|
||||
this.setRole(role);
|
||||
this.setContent(content);
|
||||
}
|
||||
|
||||
public SearchChatMessage(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("role") != null) {
|
||||
this.setRole(objectNode.get("role").asText());
|
||||
}
|
||||
else {
|
||||
this.setRole(null);
|
||||
}
|
||||
if (objectNode.get("content") != null) {
|
||||
this.setContent(objectNode.get("content").asText());
|
||||
}
|
||||
else {
|
||||
this.setContent(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
this.put("role", role);
|
||||
}
|
||||
|
||||
public void setContent(Object content) {
|
||||
this.content = content;
|
||||
this.putPOJO("content", content);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
package ai.z.openapi.service.tools;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.tools.SearchIntentDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents search intent information for web search operations. This class contains
|
||||
* details about search queries, intent analysis, and keywords.
|
||||
*/
|
||||
@JsonDeserialize(using = SearchIntentDeserializer.class)
|
||||
public class SearchIntent extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SearchIntent {
|
||||
|
||||
/**
|
||||
* Search round index, defaults to 0.
|
||||
|
|
@ -42,81 +41,4 @@ public class SearchIntent extends ObjectNode {
|
|||
@JsonProperty("keywords")
|
||||
private String keywords;
|
||||
|
||||
public SearchIntent() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public SearchIntent(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("index") != null) {
|
||||
this.setIndex(objectNode.get("index").asInt());
|
||||
}
|
||||
else {
|
||||
this.setIndex(0);
|
||||
}
|
||||
if (objectNode.get("query") != null) {
|
||||
this.setQuery(objectNode.get("query").asText());
|
||||
}
|
||||
else {
|
||||
this.setQuery(null);
|
||||
}
|
||||
if (objectNode.get("intent") != null) {
|
||||
this.setIntent(objectNode.get("intent").asText());
|
||||
}
|
||||
else {
|
||||
this.setIntent(null);
|
||||
}
|
||||
if (objectNode.get("keywords") != null) {
|
||||
this.setKeywords(objectNode.get("keywords").asText());
|
||||
}
|
||||
else {
|
||||
this.setKeywords(null);
|
||||
}
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
this.put("index", index);
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
this.put("query", query);
|
||||
}
|
||||
|
||||
public String getIntent() {
|
||||
return intent;
|
||||
}
|
||||
|
||||
public void setIntent(String intent) {
|
||||
this.intent = intent;
|
||||
this.put("intent", intent);
|
||||
}
|
||||
|
||||
public String getKeywords() {
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public void setKeywords(String keywords) {
|
||||
this.keywords = keywords;
|
||||
this.put("keywords", keywords);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,21 @@
|
|||
package ai.z.openapi.service.tools;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import ai.z.openapi.service.deserialize.MessageDeserializeFactory;
|
||||
import ai.z.openapi.service.deserialize.tools.SearchRecommendDeserializer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Represents search query recommendations. This class contains recommended search queries
|
||||
* based on search context.
|
||||
*/
|
||||
@JsonDeserialize(using = SearchRecommendDeserializer.class)
|
||||
public class SearchRecommend extends ObjectNode {
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SearchRecommend {
|
||||
|
||||
/**
|
||||
* Search round index, defaults to 0.
|
||||
|
|
@ -30,53 +29,4 @@ public class SearchRecommend extends ObjectNode {
|
|||
@JsonProperty("query")
|
||||
private String query;
|
||||
|
||||
public SearchRecommend() {
|
||||
super(JsonNodeFactory.instance);
|
||||
}
|
||||
|
||||
public SearchRecommend(ObjectNode objectNode) {
|
||||
super(JsonNodeFactory.instance);
|
||||
ObjectMapper objectMapper = MessageDeserializeFactory.defaultObjectMapper();
|
||||
if (objectNode.get("index") != null) {
|
||||
this.setIndex(objectNode.get("index").asInt());
|
||||
}
|
||||
else {
|
||||
this.setIndex(0);
|
||||
}
|
||||
if (objectNode.get("query") != null) {
|
||||
this.setQuery(objectNode.get("query").asText());
|
||||
}
|
||||
else {
|
||||
this.setQuery(null);
|
||||
}
|
||||
|
||||
Iterator<String> fieldNames = objectNode.fieldNames();
|
||||
while (fieldNames.hasNext()) {
|
||||
String fieldName = fieldNames.next();
|
||||
JsonNode field = objectNode.get(fieldName);
|
||||
this.set(fieldName, field);
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
this.put("index", index);
|
||||
}
|
||||
|
||||
public String getQuery() {
|
||||
return query;
|
||||
}
|
||||
|
||||
public void setQuery(String query) {
|
||||
this.query = query;
|
||||
|
||||
this.put("query", query);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue