peichao.dong commited on
Commit
a72034e
1 Parent(s): 2459b19

add rewrite context

Browse files
app.py CHANGED
@@ -2,14 +2,14 @@ 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 chains import HumanFeedBackChain
6
  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, tools
11
 
12
- # llm = ChatOpenAI(temperature=0.1)
13
 
14
  baMemory = HumenFeedbackBufferMemory(
15
  input_key="input", human_prefix="Answer", ai_prefix="AI")
@@ -35,6 +35,7 @@ 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)
@@ -84,14 +85,16 @@ def sendMessageByMultiPart(chatbot, context: str, relateCode: str, toolName: str
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():
@@ -101,38 +104,44 @@ with gr.Blocks() as demo:
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():
@@ -152,5 +161,5 @@ with gr.Blocks() as demo:
152
  faq.submit(faqFromLocal, [faq, faq_chatbot], [faq_chatbot, faq])
153
  # generateEmbedding.click(generateEmbeddings)
154
 
155
-
156
  demo.launch()
 
2
  from langchain.chains import LLMChain
3
  from langchain.chat_models import ChatOpenAI
4
  from langchain.document_loaders import TextLoader
5
+ from chains import HumanFeedBackChain, contextRewriteChain
6
  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, tools
11
 
12
+ # llm = ChatOpenAI(temperature=0.7)
13
 
14
  baMemory = HumenFeedbackBufferMemory(
15
  input_key="input", human_prefix="Answer", ai_prefix="AI")
 
35
  textloader = TextLoader(context_path)
36
  return textloader.load()[0].page_content
37
 
38
+
39
  def saveContext(context):
40
  with open(context_path, 'w') as f:
41
  f.write(context)
 
85
  return chatbot
86
 
87
 
88
+ def rewriteContext(input, chatbot):
89
+ response = contextRewriteChain.run(input=input, verbose=True)
90
+ chatbot.append((input, response))
91
+ return chatbot, response
92
 
93
 
94
 
 
95
  toolTextBox = []
96
  with gr.Blocks() as demo:
97
  with gr.Row():
 
98
  with gr.Tab("Business"):
99
  with gr.Row():
100
  with gr.Column():
 
104
  container=False)
105
  with gr.Column():
106
  with gr.Row():
107
+ context = gr.Textbox(show_label=True, label="Context", placeholder="Enter Context").style(
108
  container=False)
109
  with gr.Row():
110
  story = gr.Textbox(show_label=True, label="User Story", placeholder="Enter User Story").style(
111
  container=False)
112
  with gr.Row():
113
  buisinessButton = gr.Button("Generate Scenarios")
114
+ with gr.Row():
115
+ with gr.Column(scale=5):
116
+ gr.Button("Rewrite Context").click(rewriteContext, [context, chatbot], [chatbot, context])
117
+ with gr.Column(scale=1):
118
+ gr.Button("Revert").click(loadContext, [], [context])
119
  with gr.Row():
120
  gr.Button("Save Context").click(saveContext, [context], [])
121
+
122
+
123
  # with gr.Row():
124
  # generateEmbedding = gr.Button("Generate embedding")
125
  with gr.Tab("Tech"):
126
  with gr.Row():
127
+ with gr.Column(min_width="50%"):
128
  code_chatbot = gr.Chatbot(elem_id="chatbot").style()
129
  with gr.Row():
130
  code = gr.Textbox(show_label=False, label="Code Generate", placeholder="Enter text and press enter").style(
131
  container=False)
132
+ with gr.Column(min_width="50%"):
133
  with gr.Row():
134
  code_context = gr.Textbox(show_label=True, label="Context", placeholder="Enter Context").style(
135
  container=False)
136
  with gr.Row():
137
  relateCode = gr.Textbox(show_label=True, label="Relate Code", placeholder="Enter Relate Code").style(
138
  container=False)
139
+ for index, tool in enumerate(tools):
140
  with gr.Row():
141
  toolTextBox.append(gr.Textbox(show_label=False, visible=False, label=tool.name, value=tool.name).style())
142
  gr.Button(tool.name).click(
143
  sendMessageByMultiPart, [code_chatbot, code_context, relateCode, toolTextBox[index]], [code_chatbot]).then(
144
  generateCodeByMultiPart, [code_context, relateCode, toolTextBox[index], code_chatbot], [code_chatbot, code])
 
145
  with gr.Tab("FAQ"):
146
  faq_chatbot = gr.Chatbot(elem_id="chatbot").style()
147
  with gr.Row():
 
161
  faq.submit(faqFromLocal, [faq, faq_chatbot], [faq_chatbot, faq])
162
  # generateEmbedding.click(generateEmbeddings)
163
 
164
+ demo.load(loadContext, [], [context])
165
  demo.launch()
chains.py CHANGED
@@ -6,7 +6,7 @@ from langchain.prompts import PromptTemplate
6
  from langchain.memory.chat_memory import BaseMemory
7
  from langchain.chat_models import ChatOpenAI
8
 
9
- from promopts import FEEDBACK_PROMPT
10
 
11
 
12
  class HumanFeedBackChain(LLMChain):
@@ -40,3 +40,4 @@ class HumanFeedBackChain(LLMChain):
40
  )
41
 
42
 
 
 
6
  from langchain.memory.chat_memory import BaseMemory
7
  from langchain.chat_models import ChatOpenAI
8
 
9
+ from promopts import CONTENT_RE_WRIGHT_PROMPT, FEEDBACK_PROMPT
10
 
11
 
12
  class HumanFeedBackChain(LLMChain):
 
40
  )
41
 
42
 
43
+ contextRewriteChain = LLMChain(llm=ChatOpenAI(temperature=0.7), prompt=CONTENT_RE_WRIGHT_PROMPT)
documents/bussiness_context/business_context.md CHANGED
@@ -1,30 +1,9 @@
1
- AB测试系统中一个重要功能是用于控制某个feature的配置下发管理,配置管理中有两个主要业务概念FeatureFlag 和 FeatureConfig
2
- FeatureFlag用于标识某个具体Feature
3
- FeatureFlag主要属性包括: featureKey(feature标识)、名称、描述、enabled、创建时间、最后更新时间、template(作为FeatureConfig的模版用于生成后续FeatureConfig的配置界面组件,属性包括key、名称、描述、dataType、items)
4
- template中dataType为枚举值,取值范围为(STRING、NUMBER、BOOLEAN、OBJECT、ARRAY)
5
 
6
- FeatureConfig用于配置某个Feature中控制前端展示效果的配置项
7
- FeatureConfig主要属性包括:featureKey(feature标识)、data(配置数据)、saData(埋点数据)、status(状态)、标题、描述、创建时间、更新时间
8
- FeatureConfig中status为枚举值,取值范围为(DRAFT、PUBLISHED、DISABLED)
9
- FeatureConfig新增后status为DRAFT、执行发布操作后变为PUBLISHED、执行撤销操作后变为DISABLED
10
- 一个FeatureFlag中可以包含多个FeatureConfig, FeatureFlag和FeatureConfig通过featureKey字段进行关联
11
 
12
- FeatureConfig对应feature控制的不同版本配置内容,添加FeatureConfig目的是控制featureConfig消费方的某个行为
13
 
14
- 添加FeatureConfig应该包含featureKey(feature标识)、data(配置数据)、saData(埋点数据)、status(状态)、标题、描述信息
15
 
16
- 新创建的FeatureConfig状态为DRAFT
17
-
18
- 添加FeatureConfig应该包含:featureKey(feature标识)、data(配置数据)、saData(埋点数据)、status(状态)、标题、描述信息
19
-
20
- 新创建的FeatureConfig状态为DRAFT
21
-
22
- 一个FeatureFlag中可以包含多个FeatureConfig
23
-
24
- 客户端用户需要查到FeatureConfig中data、saData、更新时间、id
25
-
26
- FeatureConfig 可以关联圈人条件,符合圈人条件的配置,可展示给客户端用户
27
-
28
- 客户端用户仅能查看符合圈人条件的PUBLISHED状态的数据
29
-
30
- 圈人条件包括上传用户白名单,按照比例灰度发布,地理位置,人群标签等
 
1
+ AB测试系统中的配置管理是该系统的一个重要功能,其中主要涉及两个业务概念:FeatureFlag 和 FeatureConfig
 
 
 
2
 
3
+ FeatureFlag 用于标识某个具体 Feature,其主要属性包括 featureKey(Feature 标识)、名称、描述、enabled、创建时间、最后更新时间和 template。其中,template 作为 FeatureConfig 的模板,用于生成后续 FeatureConfig 的配置界面组件,其属性包括 key、名称、描述、dataType 和 items。其中,dataType 为枚举值,取值范围为 STRING、NUMBER、BOOLEAN、OBJECT 和 ARRAY。
 
 
 
 
4
 
5
+ FeatureConfig 用于配置某个 Feature 中控制前端展示效果的配置项,其主要属性包括 featureKey(Feature 标识)、data(配置数据)、saData(埋点数据)、status、标题、描述、创建时间和更新时间。其中,status 为枚举值,取值范围为 DRAFT、PUBLISHED 和 DISABLED。新增的 FeatureConfig 状态为 DRAFT,执行发布操作后变为 PUBLISHED,执行撤销操作后变为 DISABLED。一个 FeatureFlag 中可以包含多个 FeatureConfig,通过 featureKey 字段进行关联。
6
 
7
+ 添加 FeatureConfig 的主要目的是为了控制 FeatureConfig 消费方的某个行为。在添加 FeatureConfig 时,应该包含 featureKey、datasaDatastatus、标题和描述信息。新增的 FeatureConfig 状态为 DRAFT。
8
 
9
+ 客户端用户需要查看 FeatureConfig 中的 data、saData、更新时间和 id。同时,FeatureConfig 可以关联圈人条件,符合圈人条件的配置可以展示给客户端用户。客户端用户仅能查看符合圈人条件的 PUBLISHED 状态的数据。圈人条件包括上传用户白名单、按照比例灰度发布、地理位置和人群标签等。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
promopts.py CHANGED
@@ -384,4 +384,12 @@ Final Answer: the result of the action
384
  Begin!
385
 
386
  Request: {input}
387
- {agent_scratchpad}"""
 
 
 
 
 
 
 
 
 
384
  Begin!
385
 
386
  Request: {input}
387
+ {agent_scratchpad}"""
388
+
389
+
390
+
391
+ CONTENT_RE_WRIGHT = """你是一个文案助手,请将如下文案整理重写,去除重复的内容,尽量保留原有信息:
392
+ ```
393
+ {input}
394
+ ```"""
395
+ CONTENT_RE_WRIGHT_PROMPT = PromptTemplate(input_variables=["input"], template=CONTENT_RE_WRIGHT,)