Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
echo "PR Description: $commit_message"

env=""
module="PromptoLab"
module=""
module_type=""
version=""
skip=""
Expand All @@ -48,6 +48,10 @@ jobs:
skip="${BASH_REMATCH[1]}"
fi

if [[ "$commit_message" =~ -m:([^\ ]*) ]]; then
module="${BASH_REMATCH[1]}"
fi

if [[ "$commit_message" =~ -rp:([^\ ]*) ]]; then
run_port="${BASH_REMATCH[1]}"
fi
Expand Down
6 changes: 3 additions & 3 deletions prompto-lab-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM adoptopenjdk:11-jre-hotspot
COPY *.jar /rvc-captcha.jar
COPY *.jar /prompto-lab.jar

ARG SERVER_PORT
ARG ACTIVE
Expand Down Expand Up @@ -28,6 +28,6 @@ ENV UNIQUE_ID=${UNIQUE_ID}
ENV JASYPT_PASSWORD = ${JASYPT_PASSWORD}
EXPOSE ${SERVER_PORT}

ENTRYPOINT ["java","-jar","/.jar"]
ENTRYPOINT ["java","-jar","/prompto-lab.jar"]

#<Auto> -e:test -type:single -m:rvc-captcha -v:1.0.2 -rp:8080 -de:<-e ACTIVE=test -e SERVER_PORT=8080>
#<Auto> -e:test -type:single -m:prompto-lab -v:1.0.2 -rp:8080 -de:<-e ACTIVE=test -e SERVER_PORT=8080>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.timemachinelab.constant;

public class QATypeConstant {
public static final String FORM_QA = "form";
public static final String TEXT_QA = "text";



}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.github.timemachinelab.core.qatree;

import lombok.Data;
import lombok.Getter;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package io.github.timemachinelab.core.serializable;

import io.github.timemachinelab.core.qatree.*;
import io.github.timemachinelab.core.question.*;
import lombok.Builder;
import lombok.Data;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.Getter;

import java.util.*;

@Getter
@Builder
public class JsonNode {
String nodeId;
String parentId;
String question;
String answer;

public static JsonNode Convert2JsonNode(QaTreeNode node, String parentId) {
String question = "";
String answer = "";

BaseQuestion qa = node.getQa();
if (qa != null) {
question = qa.getQuestion() != null ? qa.getQuestion() : "";

// 根据问题类型获取答案
QuestionType type = QuestionType.fromString(qa.getType());
switch (type) {
case INPUT:
InputQuestion inputQA = (InputQuestion) qa;
answer = inputQA.getAnswer() != null ? inputQA.getAnswer() : "";
break;
case SINGLE:
SingleChoiceQuestion singleQA = (SingleChoiceQuestion) qa;
if (singleQA.getAnswer() != null && !singleQA.getAnswer().isEmpty()) {
List<String> answerLabels = new ArrayList<>();
for (String answerId : singleQA.getAnswer()) {
String label = findOptionLabel(singleQA.getOptions(), answerId);
answerLabels.add(label != null ? label : answerId);
}
answer = String.join(",", answerLabels);
}
break;
case MULTI:
MultipleChoiceQuestion multiQA = (MultipleChoiceQuestion) qa;
if (multiQA.getAnswer() != null && !multiQA.getAnswer().isEmpty()) {
List<String> answerLabels = new ArrayList<>();
for (String answerId : multiQA.getAnswer()) {
String label = findOptionLabel(multiQA.getOptions(), answerId);
answerLabels.add(label != null ? label : answerId);
}
answer = String.join(",", answerLabels);
}
break;
case FORM:
FormQuestion formQA = (FormQuestion) qa;
// 将FormField转换为TempFormQuestion的JSON格式拼接到question后面
if (formQA.getFields() != null && !formQA.getFields().isEmpty()) {
List<TempFormQuestion> tempQuestions = formQA.getFields().stream()
.map(field -> {
return TempFormQuestion.builder()
.id(field.getId())
.question(field.getQuestion())
.type(field.getType())
.options(field.getOptions())
.desc(field.getDesc())
.build();
})
.collect(java.util.stream.Collectors.toList());
String fieldsJson = JSONObject.toJSONString(tempQuestions);
question = question + ":" + fieldsJson;
}
// 将AnswerItem转换为JSON格式作为answer
if (formQA.getAnswer() != null && !formQA.getAnswer().isEmpty()) {
answer = JSONObject.toJSONString(formQA.getAnswer());
}
break;
default:
break;
}
}

return JsonNode.builder()
.nodeId(node.getId())
.parentId(parentId)
.question(question)
.answer(answer)
.build();
}

/**
* 根据选项id查找对应的标签
* @param options 选项列表
* @param id 选项id
* @return 选项标签,如果未找到则返回null
*/
private static String findOptionLabel(List<Option> options, String id) {
if (options == null || id == null) {
return null;
}
for (Option option : options) {
if (id.equals(option.getId())) {
return option.getLabel();
}
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.timemachinelab.core.serializable;

import io.github.timemachinelab.core.question.*;
import lombok.Builder;
import lombok.Data;

import java.util.*;

@Data
@Builder
public class TempFormQuestion {
public String id;
public String question;
public String type;
public List<Option> options;
public String desc;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.timemachinelab.util;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.timemachinelab.core.qatree.QaTree;
import io.github.timemachinelab.core.qatree.QaTreeNode;
import io.github.timemachinelab.core.serializable.JsonNode;

import java.util.ArrayList;
import java.util.List;

public class QaTreeSerializeUtil {

public static String serialize(QaTree t) throws JsonProcessingException {
if (t == null || t.getRoot() == null) {
return "[]";
}

List<JsonNode> result = new ArrayList<>();

firstOrderTraversal(t.getRoot(), null, result);

return JSONObject.toJSONString(result);
}

private static void firstOrderTraversal(QaTreeNode node, String parentId, List<JsonNode> result) throws JsonProcessingException {
if (node == null) {
return;
}

// 获取子节点列表
List<QaTreeNode> children = new ArrayList<>();

if (node.getChildren() != null) {
children.addAll(node.getChildren().values());
}

// 访问当前节点
JsonNode jsonNode = JsonNode.Convert2JsonNode(node, parentId);

result.add(jsonNode);

// 先序遍历
for (QaTreeNode child : children) {
firstOrderTraversal(child, node.getId(), result);
}
}
}
2 changes: 1 addition & 1 deletion prompto-lab-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring:
application:
name: poet-agent
datasource:
url: ${SPRING_DATASOURCE_URL:ENC(74AA8WeNmewtlYjGh4jIWPh8E6cxGrZ0M7zg+1wAfBJLR36B6GTw4cvCfA/EhuZiy0oSbrnGRERv5IxzsxfOFA==)}
url: ${SPRING_DATASOURCE_URL:ENC(AdWk4PSD8S3YHvL824vcUWPkYgVIdSRID1Sy7d2xGa+/WoU0PHMTXvVyk+n7LjQAeidxhRDRQSw9ilmYnY5eef5Tb+1lP4LSa+C5up64Sal7lEqgXbTvalO50Yrsn+mgUGoPJ5DfJ8bETsD35HPKNc/AhcxbzeJHFxrHKhYMsI8EJRFhpzho81HAUd6ARO1l2Ugryj+nbXfWMIgD7PZ6Uo32hHOYzxivRN18YiKmSHU=)}
username: ${SPRING_DATASOURCE_USERNAME:ENC(nOfIk0lODnZFZinDkKMeEX5zHzXpOoIj)}
password: ${SPRING_DATASOURCE_PASSWORD:ENC(W52dd0i/Q8pT/yEJIKs6Zc/brOr6KjXBPVcwdjoe4g4=)}
driver-class-name: ${SPRING_DATASOURCE_DRIVER_CLASS_NAME:org.postgresql.Driver}
Expand Down
Loading
Loading