Wendyy commited on
Commit
0688f0f
ยท
1 Parent(s): 771a889
Files changed (1) hide show
  1. modules/chat_func.py +42 -40
modules/chat_func.py CHANGED
@@ -213,50 +213,52 @@ def predict_all(
213
  else:
214
  all_token_counts.append(count_token(construct_user(inputs)))
215
  try:
216
- logging.info(f"system_prompt๏ผš{system_prompt}")
217
- logging.info(f"history๏ผš{history}")
218
- # ๅฆ‚ๆžœ่ƒฝไผ ๅ…ฅindex๏ผŒๅˆ™ๆญคๅค„้‡Œ่Žทๅพ—ๅˆ็ญ›ๅŽ็š„ๅบ—้“บๅ’Œ่œๅ
219
- response = get_response(
220
- openai_api_key,
221
- system_prompt,
222
- history,
223
- temperature,
224
- top_p,
225
- False,
226
- selected_model,
227
- )
228
- response = json.loads(response.text)
229
- logging.info(f"ๅˆๆฌกๅ“ๅบ”ๆŽจ่ๅบ—้“บ๏ผš{response}")
230
- response = response["choices"][0]["message"]["content"]
231
-
232
- logging.info(f"ๅˆๆฌกๅ“ๅบ”ๆŽจ่ๅบ—้“บ๏ผš{response}")
233
- # ๅฐ†responseไธญ็š„ๅบ—้“บๅ’Œ่œๅๆๅ–ๅ‡บๆฅ
234
- import re
235
-
236
- # text = """
237
- # ๅฅฝ็š„๏ผŒ้’ˆๅฏนๆ‚จๆƒณๅƒ้Ÿฉๅผ็ƒค่‚‰็š„้œ€ๆฑ‚๏ผŒๆˆ‘ๅ‘ๆ‚จๆŽจ่ไปฅไธ‹ๅบ—้“บๅ’Œ่œๅ“๏ผš
238
  #
239
- # ๅบ—้“บๅ็งฐ๏ผšโ€œ้’ๅนด็ƒค่‚‰ๅบ—โ€ ๆŽจ่่œๅ“๏ผš็ƒค็‰›่‚‰ใ€็ƒค็Œช่‚‰ใ€็ƒค็พŠ่‚‰
 
 
240
  #
241
- # ๅบ—้“บๅ็งฐ๏ผšโ€œ่ฅฟ่ฅฟ้‡Œ็ƒค่‚‰ๅบ—โ€ ๆŽจ่่œๅ“๏ผš็ƒค็‰›่‚‰ไธฒใ€็ƒคๆŽ’้ชจใ€็ƒค้ธก่‚‰
 
 
 
 
 
 
 
242
  #
243
- # ๅบ—้“บๅ็งฐ๏ผšโ€œ้Ÿฉๅผ็ƒค่‚‰ๅบ—โ€ ๆŽจ่่œๅ“๏ผš็Ÿณ้”…ๆ‹Œ้ฅญใ€้“ๆฟ็ƒงใ€็ƒค็‰›่ˆŒ"""
244
-
245
- pattern = r'ๅบ—้“บๅ็งฐ๏ผš(.+?) ๆŽจ่่œๅ“๏ผš(.+)ใ€‚'
246
-
247
- results = re.findall(pattern, response)
248
-
249
- dicts = {}
250
- import string
251
- for result in results:
252
- dicts[result[0]] = result[1].split('ใ€')
253
-
254
- logging.info(f"ๅˆ็ญ›ๅŽ็š„ๅบ—้“บๅ’Œ่œๅ“๏ผš{dicts}")
255
- dishes = []
256
- for restaurant, dish in dicts.items():
257
- dishes.extend(dish)
258
 
259
- dishes = 'ใ€'.join(dishes)
260
 
261
  # ๅฐ†ๅˆ็ญ›ๅŽ็š„ๅบ—้“บๅ’Œ่œๅ“้€ๅ…ฅๆž„ๅปบๅฅฝ็š„CoT
262
  prompt_with_ingredient = f"""
 
213
  else:
214
  all_token_counts.append(count_token(construct_user(inputs)))
215
  try:
216
+ # logging.info(f"system_prompt๏ผš{system_prompt}")
217
+ # logging.info(f"history๏ผš{history}")
218
+ # # ๅฆ‚ๆžœ่ƒฝไผ ๅ…ฅindex๏ผŒๅˆ™ๆญคๅค„้‡Œ่Žทๅพ—ๅˆ็ญ›ๅŽ็š„ๅบ—้“บๅ’Œ่œๅ
219
+ # response = get_response(
220
+ # openai_api_key,
221
+ # system_prompt,
222
+ # history,
223
+ # temperature,
224
+ # top_p,
225
+ # False,
226
+ # selected_model,
227
+ # )
228
+ # response = json.loads(response.text)
229
+ # logging.info(f"ๅˆๆฌกๅ“ๅบ”ๆŽจ่ๅบ—้“บ๏ผš{response}")
230
+ # response = response["choices"][0]["message"]["content"]
 
 
 
 
 
 
 
231
  #
232
+ # logging.info(f"ๅˆๆฌกๅ“ๅบ”ๆŽจ่ๅบ—้“บ๏ผš{response}")
233
+ # # ๅฐ†responseไธญ็š„ๅบ—้“บๅ’Œ่œๅๆๅ–ๅ‡บๆฅ
234
+ # import re
235
  #
236
+ # # text = """
237
+ # # ๅฅฝ็š„๏ผŒ้’ˆๅฏนๆ‚จๆƒณๅƒ้Ÿฉๅผ็ƒค่‚‰็š„้œ€ๆฑ‚๏ผŒๆˆ‘ๅ‘ๆ‚จๆŽจ่ไปฅไธ‹ๅบ—้“บๅ’Œ่œๅ“๏ผš
238
+ # #
239
+ # # ๅบ—้“บๅ็งฐ๏ผšโ€œ้’ๅนด็ƒค่‚‰ๅบ—โ€ ๆŽจ่่œๅ“๏ผš็ƒค็‰›่‚‰ใ€็ƒค็Œช่‚‰ใ€็ƒค็พŠ่‚‰
240
+ # #
241
+ # # ๅบ—้“บๅ็งฐ๏ผšโ€œ่ฅฟ่ฅฟ้‡Œ็ƒค่‚‰ๅบ—โ€ ๆŽจ่่œๅ“๏ผš็ƒค็‰›่‚‰ไธฒใ€็ƒคๆŽ’้ชจใ€็ƒค้ธก่‚‰
242
+ # #
243
+ # # ๅบ—้“บๅ็งฐ๏ผšโ€œ้Ÿฉๅผ็ƒค่‚‰ๅบ—โ€ ๆŽจ่่œๅ“๏ผš็Ÿณ้”…ๆ‹Œ้ฅญใ€้“ๆฟ็ƒงใ€็ƒค็‰›่ˆŒ"""
244
  #
245
+ # pattern = r'ๅบ—้“บๅ็งฐ๏ผš(.+?) ๆŽจ่่œๅ“๏ผš(.+)ใ€‚'
246
+ #
247
+ # results = re.findall(pattern, response)
248
+ #
249
+ # dicts = {}
250
+ # import string
251
+ # for result in results:
252
+ # dicts[result[0]] = result[1].split('ใ€')
253
+ #
254
+ # logging.info(f"ๅˆ็ญ›ๅŽ็š„ๅบ—้“บๅ’Œ่œๅ“๏ผš{dicts}")
255
+ # dishes = []
256
+ # for restaurant, dish in dicts.items():
257
+ # dishes.extend(dish)
258
+ #
259
+ # dishes = 'ใ€'.join(dishes)
260
 
261
+ dishes = "ๅŠ็†Ÿ่Šๅฃซๆ‹ฟ้“ใ€็™ฝๆกƒๅŠ็†Ÿ่Šๅฃซๆ‹ฟ้“ใ€ๆ‹›็‰Œ็ƒคๅ…จ็พŠใ€็พŠ่‚‰ไธฒ"
262
 
263
  # ๅฐ†ๅˆ็ญ›ๅŽ็š„ๅบ—้“บๅ’Œ่œๅ“้€ๅ…ฅๆž„ๅปบๅฅฝ็š„CoT
264
  prompt_with_ingredient = f"""