#
Junjie
3 天以前 0c1110daa59bf77ddcff2704641280f417158c10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.zy.ai.service.impl;
 
import com.zy.ai.entity.AiPromptTemplate;
import com.zy.ai.enums.AiPromptBlockType;
import com.zy.ai.service.AiPromptComposerService;
import org.springframework.stereotype.Service;
 
import java.util.ArrayList;
import java.util.List;
 
@Service("aiPromptComposerService")
public class AiPromptComposerServiceImpl implements AiPromptComposerService {
 
    @Override
    public String compose(AiPromptTemplate template) {
        if (template == null) {
            return "";
        }
        List<String> sections = new ArrayList<>();
        appendSection(sections, AiPromptBlockType.BASE_POLICY, template.getBasePolicy());
        appendSection(sections, AiPromptBlockType.TOOL_POLICY, template.getToolPolicy());
        appendSection(sections, AiPromptBlockType.OUTPUT_CONTRACT, template.getOutputContract());
        appendSection(sections, AiPromptBlockType.SCENE_PLAYBOOK, template.getScenePlaybook());
        return String.join("\n\n", sections).trim();
    }
 
    private void appendSection(List<String> sections, AiPromptBlockType type, String content) {
        String value = trim(content);
        if (value == null) {
            return;
        }
        sections.add("【" + type.getLabel() + "】\n" + value);
    }
 
    private String trim(String value) {
        if (value == null) {
            return null;
        }
        String trimmed = value.trim();
        return trimmed.isEmpty() ? null : trimmed;
    }
}