peichao.dong
commited on
Commit
•
2459b19
1
Parent(s):
fc06616
optimate ui
Browse files- app.py +78 -37
- code_generate.py +2 -2
- documents/bussiness_context/business_context.md +9 -1
- promopts.py +45 -3
app.py
CHANGED
@@ -7,7 +7,7 @@ from embedding import CustomEmbedding
|
|
7 |
from memories import HumenFeedbackBufferMemory
|
8 |
from langchain.memory import ConversationBufferMemory
|
9 |
from promopts import FEEDBACK, FEEDBACK_PROMPT
|
10 |
-
from code_generate import code_agent_executor
|
11 |
|
12 |
# llm = ChatOpenAI(temperature=0.1)
|
13 |
|
@@ -17,8 +17,6 @@ baChain = HumanFeedBackChain(verbose=True, memory=baMemory)
|
|
17 |
|
18 |
"""读取document/business_context.py文件内容作为context"""
|
19 |
context_path = "./documents/bussiness_context/business_context.md"
|
20 |
-
textloader = TextLoader(context_path)
|
21 |
-
CONTEXT = textloader.load()[0].page_content
|
22 |
|
23 |
|
24 |
def sendMessage(chatbot, input):
|
@@ -33,12 +31,18 @@ def clearMemory(chatbot):
|
|
33 |
baMemory.clear()
|
34 |
return chatbot, ""
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
def feedBack(context, story, chatbot=[], input=""):
|
38 |
if len(input) > 0:
|
39 |
context += (f"\n\n {input}")
|
40 |
-
|
41 |
-
f.write(context)
|
42 |
response = baChain.run(
|
43 |
input=(input if len(input) == 0 else input), context=context, story=story, stop="\nAnswer:")
|
44 |
chatbot[-1][1] = response
|
@@ -61,7 +65,7 @@ def generateEmbeddings():
|
|
61 |
customerEmbedding.calculateNotionEmbedding()
|
62 |
|
63 |
|
64 |
-
def generateCode(input: str, chatbot=[]):
|
65 |
if len(input) <=0:
|
66 |
chatbot[-1][1] = None
|
67 |
return chatbot, ""
|
@@ -70,46 +74,83 @@ def generateCode(input: str, chatbot=[]):
|
|
70 |
chatbot[-1][1] = response
|
71 |
return chatbot, ""
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
|
|
|
|
|
|
74 |
with gr.Blocks() as demo:
|
75 |
with gr.Row():
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
with gr.
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
with gr.Row():
|
102 |
-
|
|
|
103 |
|
104 |
-
|
|
|
105 |
feedBack, [context, story, chatbot], [chatbot, txt])
|
|
|
106 |
txt.submit(sendMessage, [chatbot, txt], [chatbot]).then(
|
107 |
feedBack, [context, story, chatbot, txt], [chatbot, txt, context])
|
108 |
|
109 |
-
code.submit(sendMessage, [
|
110 |
-
generateCode, [code,
|
|
|
|
|
|
|
111 |
|
112 |
-
faq.submit(faqFromLocal, [faq, chatbot], [chatbot, faq])
|
113 |
-
generateEmbedding.click(generateEmbeddings)
|
114 |
|
115 |
demo.launch()
|
|
|
7 |
from memories import HumenFeedbackBufferMemory
|
8 |
from langchain.memory import ConversationBufferMemory
|
9 |
from promopts import FEEDBACK, FEEDBACK_PROMPT
|
10 |
+
from code_generate import code_agent_executor, tools
|
11 |
|
12 |
# llm = ChatOpenAI(temperature=0.1)
|
13 |
|
|
|
17 |
|
18 |
"""读取document/business_context.py文件内容作为context"""
|
19 |
context_path = "./documents/bussiness_context/business_context.md"
|
|
|
|
|
20 |
|
21 |
|
22 |
def sendMessage(chatbot, input):
|
|
|
31 |
baMemory.clear()
|
32 |
return chatbot, ""
|
33 |
|
34 |
+
def loadContext():
|
35 |
+
textloader = TextLoader(context_path)
|
36 |
+
return textloader.load()[0].page_content
|
37 |
+
|
38 |
+
def saveContext(context):
|
39 |
+
with open(context_path, 'w') as f:
|
40 |
+
f.write(context)
|
41 |
|
42 |
def feedBack(context, story, chatbot=[], input=""):
|
43 |
if len(input) > 0:
|
44 |
context += (f"\n\n {input}")
|
45 |
+
saveContext(context)
|
|
|
46 |
response = baChain.run(
|
47 |
input=(input if len(input) == 0 else input), context=context, story=story, stop="\nAnswer:")
|
48 |
chatbot[-1][1] = response
|
|
|
65 |
customerEmbedding.calculateNotionEmbedding()
|
66 |
|
67 |
|
68 |
+
def generateCode(input: str, chatbot=[], returnCode=False):
|
69 |
if len(input) <=0:
|
70 |
chatbot[-1][1] = None
|
71 |
return chatbot, ""
|
|
|
74 |
chatbot[-1][1] = response
|
75 |
return chatbot, ""
|
76 |
|
77 |
+
def generateCodeByMultiPart(context: str, relateCode: str, toolName: str, chatbot=[]):
|
78 |
+
input = f"请根据如下信息{toolName}:\n{context}\n\n{relateCode}"
|
79 |
+
return generateCode(input, chatbot)
|
80 |
+
|
81 |
+
def sendMessageByMultiPart(chatbot, context: str, relateCode: str, toolName: str):
|
82 |
+
input = f"请根据如下信息{toolName}:\n{context}\n\n{relateCode}"
|
83 |
+
chatbot.append((input, None))
|
84 |
+
return chatbot
|
85 |
+
|
86 |
+
|
87 |
+
|
88 |
|
89 |
+
|
90 |
+
index = 0
|
91 |
+
toolTextBox = []
|
92 |
with gr.Blocks() as demo:
|
93 |
with gr.Row():
|
94 |
+
|
95 |
+
with gr.Tab("Business"):
|
96 |
+
with gr.Row():
|
97 |
+
with gr.Column():
|
98 |
+
chatbot = gr.Chatbot(elem_id="chatbot").style()
|
99 |
+
with gr.Row():
|
100 |
+
txt = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(
|
101 |
+
container=False)
|
102 |
+
with gr.Column():
|
103 |
+
with gr.Row():
|
104 |
+
context = gr.Textbox(show_label=True, value=loadContext(), label="Context", placeholder="Enter Context").style(
|
105 |
+
container=False)
|
106 |
+
with gr.Row():
|
107 |
+
story = gr.Textbox(show_label=True, label="User Story", placeholder="Enter User Story").style(
|
108 |
+
container=False)
|
109 |
+
with gr.Row():
|
110 |
+
buisinessButton = gr.Button("Generate Scenarios")
|
111 |
+
with gr.Row():
|
112 |
+
gr.Button("Save Context").click(saveContext, [context], [])
|
113 |
+
# with gr.Row():
|
114 |
+
# generateEmbedding = gr.Button("Generate embedding")
|
115 |
+
with gr.Tab("Tech"):
|
116 |
+
with gr.Row():
|
117 |
+
with gr.Column():
|
118 |
+
code_chatbot = gr.Chatbot(elem_id="chatbot").style()
|
119 |
+
with gr.Row():
|
120 |
+
code = gr.Textbox(show_label=False, label="Code Generate", placeholder="Enter text and press enter").style(
|
121 |
+
container=False)
|
122 |
+
with gr.Column():
|
123 |
+
with gr.Row():
|
124 |
+
code_context = gr.Textbox(show_label=True, label="Context", placeholder="Enter Context").style(
|
125 |
+
container=False)
|
126 |
+
with gr.Row():
|
127 |
+
relateCode = gr.Textbox(show_label=True, label="Relate Code", placeholder="Enter Relate Code").style(
|
128 |
+
container=False)
|
129 |
+
for tool in tools:
|
130 |
+
with gr.Row():
|
131 |
+
toolTextBox.append(gr.Textbox(show_label=False, visible=False, label=tool.name, value=tool.name).style())
|
132 |
+
gr.Button(tool.name).click(
|
133 |
+
sendMessageByMultiPart, [code_chatbot, code_context, relateCode, toolTextBox[index]], [code_chatbot]).then(
|
134 |
+
generateCodeByMultiPart, [code_context, relateCode, toolTextBox[index], code_chatbot], [code_chatbot, code])
|
135 |
+
index += 1
|
136 |
+
with gr.Tab("FAQ"):
|
137 |
+
faq_chatbot = gr.Chatbot(elem_id="chatbot").style()
|
138 |
with gr.Row():
|
139 |
+
faq = gr.Textbox(show_label=False, placeholder="Enter text and press enter").style(
|
140 |
+
container=False)
|
141 |
|
142 |
+
|
143 |
+
buisinessButton.click(clearMemory, [chatbot], [chatbot, txt]).then(sendMessage, [chatbot, txt], [chatbot]).then(
|
144 |
feedBack, [context, story, chatbot], [chatbot, txt])
|
145 |
+
|
146 |
txt.submit(sendMessage, [chatbot, txt], [chatbot]).then(
|
147 |
feedBack, [context, story, chatbot, txt], [chatbot, txt, context])
|
148 |
|
149 |
+
code.submit(sendMessage, [code_chatbot, code], [code_chatbot]).then(
|
150 |
+
generateCode, [code, code_chatbot], [code_chatbot, code])
|
151 |
+
|
152 |
+
faq.submit(faqFromLocal, [faq, faq_chatbot], [faq_chatbot, faq])
|
153 |
+
# generateEmbedding.click(generateEmbeddings)
|
154 |
|
|
|
|
|
155 |
|
156 |
demo.launch()
|
code_generate.py
CHANGED
@@ -94,13 +94,13 @@ class CustomOutputParser(AgentOutputParser):
|
|
94 |
|
95 |
# agent = initialize_agent(
|
96 |
# tools=tools, llm=llm_chain, template=AGENT_PROMPT, stop=["\nObservation:"], agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
|
|
97 |
|
98 |
|
99 |
def code_agent_executor() -> AgentExecutor:
|
100 |
|
101 |
|
102 |
-
|
103 |
-
|
104 |
output_parser = CustomOutputParser()
|
105 |
|
106 |
|
|
|
94 |
|
95 |
# agent = initialize_agent(
|
96 |
# tools=tools, llm=llm_chain, template=AGENT_PROMPT, stop=["\nObservation:"], agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
|
97 |
+
tools = [domainLayerCodeGenerator, persistentLayerCodeGenerator, apiLayerCodeGenerator]
|
98 |
|
99 |
|
100 |
def code_agent_executor() -> AgentExecutor:
|
101 |
|
102 |
|
103 |
+
|
|
|
104 |
output_parser = CustomOutputParser()
|
105 |
|
106 |
|
documents/bussiness_context/business_context.md
CHANGED
@@ -19,4 +19,12 @@ FeatureConfig新增后status为DRAFT、执行发布操作后变为PUBLISHED、
|
|
19 |
|
20 |
新创建的FeatureConfig状态为DRAFT
|
21 |
|
22 |
-
一个FeatureFlag中可以包含多个FeatureConfig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
新创建的FeatureConfig状态为DRAFT
|
21 |
|
22 |
+
一个FeatureFlag中可以包含多个FeatureConfig
|
23 |
+
|
24 |
+
客户端用户需要查到FeatureConfig中data、saData、更新时间、id
|
25 |
+
|
26 |
+
FeatureConfig 可以关联圈人条件,符合圈人条件的配置,可展示给客户端用户
|
27 |
+
|
28 |
+
客户端用户仅能查看符合圈人条件的PUBLISHED状态的数据
|
29 |
+
|
30 |
+
圈人条件包括上传用户白名单,按照比例灰度发布,地理位置,人群标签等
|
promopts.py
CHANGED
@@ -102,8 +102,20 @@ For the Association,do not write tests because it is has no impletation.
|
|
102 |
Use the following format:
|
103 |
request: the request that you need to fulfill
|
104 |
|
105 |
-
|
|
|
|
|
|
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
request: {input}"""
|
109 |
|
@@ -246,8 +258,25 @@ For Association Impletation,we writ unit test, and stub repository method with
|
|
246 |
Use the following format:
|
247 |
request: the request that you need to fulfill include Entity and Association of domain layer
|
248 |
|
249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
250 |
|
|
|
|
|
|
|
|
|
251 |
|
252 |
request: {input}"""
|
253 |
|
@@ -317,7 +346,20 @@ For the Controller and DTO, we can write component test to test the actual imple
|
|
317 |
Use the following format:
|
318 |
request: the request that you need to fulfill include Entity and Association of domain layer
|
319 |
|
320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
request: {input}"""
|
323 |
|
|
|
102 |
Use the following format:
|
103 |
request: the request that you need to fulfill
|
104 |
|
105 |
+
Entity:
|
106 |
+
```
|
107 |
+
the Entity code that you write to fulfill the request, follow TechStack and Architecture
|
108 |
+
```
|
109 |
|
110 |
+
Association:
|
111 |
+
```
|
112 |
+
the Association code that you write to fulfill the request, follow TechStack and Architecture
|
113 |
+
```
|
114 |
+
|
115 |
+
Test:
|
116 |
+
```
|
117 |
+
the test code that you write to fulfill the request, follow TechStack Architecture and TestStrategy
|
118 |
+
```
|
119 |
|
120 |
request: {input}"""
|
121 |
|
|
|
258 |
Use the following format:
|
259 |
request: the request that you need to fulfill include Entity and Association of domain layer
|
260 |
|
261 |
+
DBEntity:
|
262 |
+
```
|
263 |
+
the DBEntity code that you write to fulfill the request, follow TechStack and Architecture
|
264 |
+
```
|
265 |
+
|
266 |
+
Repository:
|
267 |
+
```
|
268 |
+
the Repository code that you write to fulfill the request, follow TechStack and Architecture
|
269 |
+
```
|
270 |
+
|
271 |
+
Association Impletation:
|
272 |
+
```
|
273 |
+
the Association Impletation code that you write to fulfill the request, follow TechStack and Architecture
|
274 |
+
```
|
275 |
|
276 |
+
Test:
|
277 |
+
```
|
278 |
+
the test code that you write to fulfill the request, follow TechStack Architecture and TestStrategy
|
279 |
+
```
|
280 |
|
281 |
request: {input}"""
|
282 |
|
|
|
346 |
Use the following format:
|
347 |
request: the request that you need to fulfill include Entity and Association of domain layer
|
348 |
|
349 |
+
DTO:
|
350 |
+
```
|
351 |
+
the DTO code that you write to fulfill the request, follow TechStack and Architecture
|
352 |
+
```
|
353 |
+
|
354 |
+
Controller:
|
355 |
+
```
|
356 |
+
the Controller code that you write to fulfill the request, follow TechStack and Architecture
|
357 |
+
```
|
358 |
+
|
359 |
+
Test:
|
360 |
+
```
|
361 |
+
the test code that you write to fulfill the request, follow TechStack Architecture and TestStrategy
|
362 |
+
```
|
363 |
|
364 |
request: {input}"""
|
365 |
|