File size: 3,869 Bytes
fbae247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
from langchain.agents import tool
from agents.tools.smart_domain.common import getPrefix
from models import llm

entity_architecture = """
Entity: This component is use to represents business concepts and encapsulates business rules.
It may include 3 parts: 
- id(identity of entity)
- description (properties package of entity represent the value of entity), 
- associations (collection of associated entiy)
---example code:
    @Getter
    @AllArgsConstructor 
    public class Feature {{
        // id
        private FeatureId id;
        
        // description
        private FeatureDescription description;

        // associations
        private FeatureConfigs configs;

        public record FeatureId(String featureKey) {{
        
        }}

        @Builder
        public record FeatureDescription(String name, 
                            String description, 
                            Boolean isEnable,
                            LocalDateTime updatedAt,
                            LocalDateTime createdAt))) {{
        
        }}

        public Feature update(Feature newFeature) {{
            this.description = FeatureDescription.builder()
                .name(newFeature.description.name())
                .description(newFeature.description.description())
                .isEnable(this.description.isEnable())
                .updatedAt(LocalDateTime.now())
                .createdAt(this.description.createdAt());

            return this;
        }}

        public interface FeatureConfigs() {{
            Flux<FeatureConfig> findAll();
            Flux<FeatureConfig> subCollection(long from, long to);
            Mono<FeatureConfig> findById(FeatureConfigId id);
        }}
    }}
---end of example code
"""

entity_test_strategy = """
For the Entity, we can write unit test to ensure that the business rules related to Merchandise are correctly encapsulated.
---example code
    class FeatureTest {{
        @Test
        void should_update_feature_description() {{
            // given
            Feature feature = Feature.builder()
                .id(new FeatureId("featureKey"))
                .description(new FeatureDescription("name", "description", true, LocalDateTime.now(), LocalDateTime.now()))
                .build();
            Feature newFeature = Feature.builder()
                .id(new FeatureId("featureKey"))
                .description(new FeatureDescription("newName", "newDescription", true, LocalDateTime.now(), LocalDateTime.now()))
                .build();
            // when
            feature.update(newFeature);
            // then
            assertThat(feature.description().name()).isEqualTo("newName");
            assertThat(feature.description().description()).isEqualTo("newDescription");
        }}
    }}
---end of example code
"""

entity_tech_stack = """
Java17、reactor、lombok、Junit5、reactor test、Mockito
"""

entity_task = """Your task is to generate the Enity of domain layer tests and product code."""
ENTITY = getPrefix(entity_task, entity_tech_stack, entity_architecture, entity_test_strategy) + """

Use the following format:
request: the request that you need to fulfill

Entity:
```
the Entity code that you write to fulfill the request, follow TechStack and Architecture
```

Test:
```
the test code that you write to fulfill the request, follow TechStack Architecture and TestStrategy
```

request: {input}"""

ENTITY_PROMPT = PromptTemplate(input_variables=["input"], template=ENTITY,)

entityChain = LLMChain(llm = llm(temperature=0.1), prompt=ENTITY_PROMPT)


@tool("Generate Entity Code", return_direct=True)
def entityCodeGenerator(input: str) -> str:
    '''useful for when you need to generate entity code'''
    response = entityChain.run(input)
    return response