add CoT
Browse files- 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 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 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 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
dishes
|
| 256 |
-
|
| 257 |
-
|
| 258 |
|
| 259 |
-
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"""
|