peichao.dong commited on
Commit
1d2148a
1 Parent(s): 405c09f

add generate Entity code tool

Browse files
agents/code_generate_agent.py CHANGED
@@ -8,7 +8,7 @@ from langchain.agents import initialize_agent
8
  from langchain.prompts import StringPromptTemplate
9
  from agents.promopts import code_generate_agent_template
10
  from agents.tools.api_layer_code_tool import apiLayerCodeGenerator
11
- from agents.tools.domain_layer_code_tool import domainLayerCodeGenerator
12
  from agents.tools.persistent_layer_code_tool import persistentLayerCodeGenerator
13
 
14
 
@@ -66,7 +66,7 @@ class CustomOutputParser(AgentOutputParser):
66
 
67
  # agent = initialize_agent(
68
  # tools=tools, llm=llm_chain, template=AGENT_PROMPT, stop=["\nObservation:"], agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
69
- code_agent_tools = [domainLayerCodeGenerator, persistentLayerCodeGenerator, apiLayerCodeGenerator]
70
 
71
  def code_agent_executor() -> AgentExecutor:
72
  output_parser = CustomOutputParser()
 
8
  from langchain.prompts import StringPromptTemplate
9
  from agents.promopts import code_generate_agent_template
10
  from agents.tools.api_layer_code_tool import apiLayerCodeGenerator
11
+ from agents.tools.domain_layer_code_tool import domainLayerCodeGenerator, entityCodeGenerator
12
  from agents.tools.persistent_layer_code_tool import persistentLayerCodeGenerator
13
 
14
 
 
66
 
67
  # agent = initialize_agent(
68
  # tools=tools, llm=llm_chain, template=AGENT_PROMPT, stop=["\nObservation:"], agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
69
+ code_agent_tools = [domainLayerCodeGenerator, entityCodeGenerator, persistentLayerCodeGenerator, apiLayerCodeGenerator]
70
 
71
  def code_agent_executor() -> AgentExecutor:
72
  output_parser = CustomOutputParser()
agents/tools/domain_layer_code_tool.py CHANGED
@@ -22,7 +22,9 @@ the domain layer inclue 2 componets:
22
  }}
23
 
24
  @Builder
25
- public record FeatureDescription(String name, String description, Boolean isEnable))) {{
 
 
26
 
27
  }}
28
  }}
@@ -82,4 +84,115 @@ domainLayerChain = LLMChain(llm = ChatOpenAI(temperature=0.1), prompt=DOMAIN_LAY
82
  def domainLayerCodeGenerator(input: str) -> str:
83
  '''useful for when you need to generate domain layer code'''
84
  response = domainLayerChain.run(input)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  return response
 
22
  }}
23
 
24
  @Builder
25
+ public record FeatureDescription(String name,
26
+ String description,
27
+ Boolean isEnable))) {{
28
 
29
  }}
30
  }}
 
84
  def domainLayerCodeGenerator(input: str) -> str:
85
  '''useful for when you need to generate domain layer code'''
86
  response = domainLayerChain.run(input)
87
+ return response
88
+
89
+
90
+
91
+
92
+ ENTITY = """You are a software developer. Your task is to generate the Enity of domain layer tests and product code.
93
+
94
+ ===TechStack
95
+ Java17、reactor、lombok、Junit5、reactor test、Mockito
96
+ ===END OF TechStack
97
+
98
+ ===Architecture
99
+ Entity is a kine of component of the domain layer, which is use to represents business concepts and encapsulates business rules.
100
+ Entity may include 3 parts:
101
+ - id(identity of entity)
102
+ - description (properties package of entity represent the value of entity),
103
+ - associations (collection of associated entiy)
104
+
105
+ ---example code:
106
+ public class Feature {{
107
+ // id
108
+ private FeatureId id;
109
+
110
+ // description
111
+ private FeatureDescription description;
112
+
113
+ // associations
114
+ private FeatureConfigs configs;
115
+
116
+ public record FeatureId(String featureKey) {{
117
+
118
+ }}
119
+
120
+ @Builder
121
+ public record FeatureDescription(String name,
122
+ String description,
123
+ Boolean isEnable,
124
+ LocalDateTime updatedAt,
125
+ LocalDateTime createdAt))) {{
126
+
127
+ }}
128
+
129
+ public Feature update(Feature newFeature) {{
130
+ this.description = FeatureDescription.builder()
131
+ .name(newFeature.description.name())
132
+ .description(newFeature.description.description())
133
+ .isEnable(this.description.isEnable())
134
+ .updatedAt(LocalDateTime.now())
135
+ .createdAt(this.description.createdAt());
136
+
137
+ return this;
138
+ }}
139
+
140
+ public interface FeatureConfigs() {{
141
+ Flux<FeatureConfig> findAll();
142
+ Flux<FeatureConfig> subCollection(long from, long to);
143
+ Mono<FeatureConfig> findById(FeatureConfigId id);
144
+ }}
145
+ }}
146
+ ---end of example code
147
+ ===END OF Architecture
148
+
149
+ ===TestStrategy
150
+ For the Entity, we can write unit test to ensure that the business rules related to Merchandise are correctly encapsulated.
151
+ ---example code
152
+ class FeatureTest {{
153
+ @Test
154
+ void should_update_feature_description() {{
155
+ // given
156
+ Feature feature = Feature.builder()
157
+ .id(new FeatureId("featureKey"))
158
+ .description(new FeatureDescription("name", "description", true, LocalDateTime.now(), LocalDateTime.now()))
159
+ .build();
160
+ Feature newFeature = Feature.builder()
161
+ .id(new FeatureId("featureKey"))
162
+ .description(new FeatureDescription("newName", "newDescription", true, LocalDateTime.now(), LocalDateTime.now()))
163
+ .build();
164
+ // when
165
+ feature.update(newFeature);
166
+ // then
167
+ assertThat(feature.description().name()).isEqualTo("newName");
168
+ assertThat(feature.description().description()).isEqualTo("newDescription");
169
+ }}
170
+ }}
171
+ ---end of example code
172
+ ===END OF TestStrategy
173
+
174
+ Use the following format:
175
+ request: the request that you need to fulfill
176
+
177
+ Entity:
178
+ ```
179
+ the Entity code that you write to fulfill the request, follow TechStack and Architecture
180
+ ```
181
+
182
+ Test:
183
+ ```
184
+ the test code that you write to fulfill the request, follow TechStack Architecture and TestStrategy
185
+ ```
186
+
187
+ request: {input}"""
188
+
189
+ ENTITY_PROMPT = PromptTemplate(input_variables=["input"], template=ENTITY,)
190
+
191
+ entityChain = LLMChain(llm = ChatOpenAI(temperature=0.1), prompt=ENTITY_PROMPT)
192
+
193
+
194
+ @tool("Generate Entity Code", return_direct=True)
195
+ def entityCodeGenerator(input: str) -> str:
196
+ '''useful for when you need to generate entity code'''
197
+ response = entityChain.run(input)
198
  return response
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from langchain.chains import LLMChain
3
  from langchain.chat_models import ChatOpenAI
4
  from langchain.document_loaders import TextLoader
5
- from agents.tools.python_util_tool import generate_and_excute_python_code
6
  from chains import HumanFeedBackChain, contextRewriteChain
7
  from embedding import CustomEmbedding
8
  from memories import HumenFeedbackBufferMemory
@@ -146,7 +146,7 @@ with gr.Blocks() as demo:
146
  sendMessageByMultiPart, [code_chatbot, code_context, relateCode, toolTextBox[index]], [code_chatbot]).then(
147
  generateCodeByMultiPart, [code_context, relateCode, toolTextBox[index], code_chatbot], [code_chatbot, code])
148
  with gr.Tab("FAQ"):
149
- faq_chatbot = gr.Chatbot().style(max_width="50%")
150
  with gr.Row():
151
  faq = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(
152
  container=False)
 
2
  from langchain.chains import LLMChain
3
  from langchain.chat_models import ChatOpenAI
4
  from langchain.document_loaders import TextLoader
5
+ from agents.tools.python_code_tool import generate_and_excute_python_code
6
  from chains import HumanFeedBackChain, contextRewriteChain
7
  from embedding import CustomEmbedding
8
  from memories import HumenFeedbackBufferMemory
 
146
  sendMessageByMultiPart, [code_chatbot, code_context, relateCode, toolTextBox[index]], [code_chatbot]).then(
147
  generateCodeByMultiPart, [code_context, relateCode, toolTextBox[index], code_chatbot], [code_chatbot, code])
148
  with gr.Tab("FAQ"):
149
+ faq_chatbot = gr.Chatbot().style()
150
  with gr.Row():
151
  faq = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(
152
  container=False)