Wendyy commited on
Commit
baa1f8d
·
1 Parent(s): bb940c0
Files changed (1) hide show
  1. modules/chat_func.py +70 -70
modules/chat_func.py CHANGED
@@ -119,7 +119,6 @@ def stream_predict(
119
  logging.info(f"输入token计数: {user_token_count}")
120
  yield get_return_value()
121
  try:
122
- # 如果能传入index,则此处里获得初筛后的店铺和菜名
123
  response = get_response(
124
  openai_api_key,
125
  system_prompt,
@@ -129,75 +128,6 @@ def stream_predict(
129
  True,
130
  selected_model,
131
  )
132
- # 将response中的店铺和菜名提取出来
133
- import re
134
-
135
- text = """
136
- 好的,针对您想吃韩式烤肉的需求,我向您推荐以下店铺和菜品:
137
-
138
- 店铺名称:“青年烤肉店” 推荐菜品:烤牛肉、烤猪肉、烤羊肉
139
-
140
- 店铺名称:“西西里烤肉店” 推荐菜品:烤牛肉串、烤排骨、烤鸡肉
141
-
142
- 店铺名称:“韩式烤肉店” 推荐菜品:石锅拌饭、铁板烧、烤牛舌"""
143
-
144
- pattern = r'店铺名称:(.+?) 推荐菜品:(.+)'
145
-
146
- results = re.findall(pattern, response)
147
-
148
- dicts = {}
149
- import string
150
- for result in results:
151
- dicts[result[0]] = result[1].split('、')
152
-
153
- logging.info(f"初筛后的店铺和菜品:{dicts}")
154
- dishes = []
155
- for restaurant, dish in dicts.items():
156
- dishes.extend(dish)
157
-
158
- dishes = '、'.join(dishes)
159
-
160
- # 将初筛后的店铺和菜品送入构建好的CoT
161
- prompt_with_ingredient = f"""
162
- 我需要你推测一些菜可能的原料以及其营养成分,输出格式如下:
163
-
164
- 菜品名称:[]
165
- 菜品原料:[原料1,原料2...]
166
- 营养成分:[成分(含量)]
167
-
168
- 注意,其中营养成分包括蛋白质、脂肪、碳水化合物、纤维素、维生素等,你可以根据你的知识添加其他成分。营养成分的含量分为无、低、中、高四个等级,需要填在成分后的括号内。
169
-
170
- 以下是需要你推测的菜品名称,不同菜品用顿号隔开:{dishes}
171
- """
172
-
173
- logging.info(f"分析食物中营养成分的prompt构建完成:{prompt_with_ingredient}")
174
-
175
- response_ingredient = get_response(
176
- openai_api_key,
177
- "",
178
- prompt_with_ingredient,
179
- temperature,
180
- top_p,
181
- True,
182
- selected_model,
183
- )
184
-
185
- logging.info(f"得到食物中的营养成分:{response_ingredient}")
186
-
187
- prompt_rec = f"""
188
- 以下是一些菜品名称和所属的店铺,我需要你根据我的需求从其中推荐一家店铺的一种或多种菜品,并给出推荐的理由。我的需求为:我有糖尿病,而且今天不想吃太油腻的食物。
189
-
190
- {response_ingredient}
191
- """
192
- response = get_response(
193
- openai_api_key,
194
- "",
195
- prompt_rec,
196
- temperature,
197
- top_p,
198
- True,
199
- selected_model,
200
- )
201
 
202
 
203
  except requests.exceptions.ConnectTimeout:
@@ -283,6 +213,7 @@ def predict_all(
283
  else:
284
  all_token_counts.append(count_token(construct_user(inputs)))
285
  try:
 
286
  response = get_response(
287
  openai_api_key,
288
  system_prompt,
@@ -292,6 +223,75 @@ def predict_all(
292
  False,
293
  selected_model,
294
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  except requests.exceptions.ConnectTimeout:
296
  status_text = (
297
  standard_error_msg + connection_timeout_prompt + error_retrieve_prompt
 
119
  logging.info(f"输入token计数: {user_token_count}")
120
  yield get_return_value()
121
  try:
 
122
  response = get_response(
123
  openai_api_key,
124
  system_prompt,
 
128
  True,
129
  selected_model,
130
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
 
132
 
133
  except requests.exceptions.ConnectTimeout:
 
213
  else:
214
  all_token_counts.append(count_token(construct_user(inputs)))
215
  try:
216
+ # 如果能传入index,则此处里获得初筛后的店铺和菜名
217
  response = get_response(
218
  openai_api_key,
219
  system_prompt,
 
223
  False,
224
  selected_model,
225
  )
226
+ # 将response中的店铺和菜名提取出来
227
+ import re
228
+
229
+ text = """
230
+ 好的,针对您想吃韩式烤肉的需求,我向您推荐以下店铺和菜品:
231
+
232
+ 店铺名称:“青年烤肉店” 推荐菜品:烤牛肉、烤猪肉、烤羊肉
233
+
234
+ 店铺名称:“西西里烤肉店” 推荐菜品:烤牛肉串、烤排骨、烤鸡肉
235
+
236
+ 店铺名称:“韩式烤肉店” 推荐菜品:石锅拌饭、铁板烧、烤牛舌"""
237
+
238
+ pattern = r'店铺名称:(.+?) 推荐菜品:(.+)'
239
+
240
+ results = re.findall(pattern, response)
241
+
242
+ dicts = {}
243
+ import string
244
+ for result in results:
245
+ dicts[result[0]] = result[1].split('、')
246
+
247
+ logging.info(f"初筛后的店铺和菜品:{dicts}")
248
+ dishes = []
249
+ for restaurant, dish in dicts.items():
250
+ dishes.extend(dish)
251
+
252
+ dishes = '、'.join(dishes)
253
+
254
+ # 将初筛后的店铺和菜品送入构建好的CoT
255
+ prompt_with_ingredient = f"""
256
+ 我需要你推测一些菜可能的原料以及其营养成分,输出格式如下:
257
+
258
+ 菜品名称:[]
259
+ 菜品原料:[原料1,原料2...]
260
+ 营养成分:[成分(含量)]
261
+
262
+ 注意,其中营养成分包括蛋白质、脂肪、碳水化合物、纤维素、维生素等,你可以根据你的知识添加其他成分。营养成分的含量分为无、低、中、高四个等级,需要填在成分后的括号内。
263
+
264
+ 以下是需要你推测��菜品名称,不同菜品用顿号隔开:{dishes}
265
+ """
266
+
267
+ logging.info(f"分析食物中营养成分的prompt构建完成:{prompt_with_ingredient}")
268
+
269
+ response_ingredient = get_response(
270
+ openai_api_key,
271
+ "",
272
+ prompt_with_ingredient,
273
+ temperature,
274
+ top_p,
275
+ True,
276
+ selected_model,
277
+ )
278
+
279
+ logging.info(f"得到食物中的营养成分:{response_ingredient}")
280
+
281
+ prompt_rec = f"""
282
+ 以下是一些菜品名称和所属的店铺,我需要你根据我的需求从其中推荐一家店铺的一种或多种菜品,并给出推荐的理由。我的需求为:我有糖尿病,而且今天不想吃太油腻的食物。
283
+
284
+ {response_ingredient}
285
+ """
286
+ response = get_response(
287
+ openai_api_key,
288
+ "",
289
+ prompt_rec,
290
+ temperature,
291
+ top_p,
292
+ True,
293
+ selected_model,
294
+ )
295
  except requests.exceptions.ConnectTimeout:
296
  status_text = (
297
  standard_error_msg + connection_timeout_prompt + error_retrieve_prompt