Spaces:
Build error
Build error
Merge branch 'main' into space
Browse files- chat_poets/chat.py +10 -8
- gradio_ui/gr_chat.py +4 -2
chat_poets/chat.py
CHANGED
|
@@ -90,8 +90,10 @@ class ChatPoet:
|
|
| 90 |
return "请求次数过多,请重试"
|
| 91 |
|
| 92 |
if pattern == "adult":
|
|
|
|
| 93 |
response = cls.chat_adult(question_type=question_type, history=history)
|
| 94 |
else:
|
|
|
|
| 95 |
response = cls.chat_teen_or_child(pattern=pattern, question_type=question_type, history=history)
|
| 96 |
print(f"response:{response}")
|
| 97 |
return response
|
|
@@ -128,9 +130,9 @@ class ChatPoet:
|
|
| 128 |
return cls.get_str_response_appreciate(history)
|
| 129 |
elif question_type == "词语解释":
|
| 130 |
return cls.get_str_response_vocab(history)
|
| 131 |
-
elif question_type == "写作背景":
|
| 132 |
-
return cls.get_str_response_author(history)
|
| 133 |
elif question_type == "作者简介":
|
|
|
|
|
|
|
| 134 |
return cls.get_str_response_background(history)
|
| 135 |
|
| 136 |
@classmethod
|
|
@@ -144,21 +146,21 @@ class ChatPoet:
|
|
| 144 |
"""
|
| 145 |
prompt_mode = cls.prompts["pattern"][pattern]
|
| 146 |
|
| 147 |
-
if question_type == "
|
| 148 |
return cls.get_str_response_origin(history)
|
| 149 |
-
elif question_type == "
|
| 150 |
str_prompt_vernacular_s = prompt_mode + cls.get_str_response_vernacular(history)
|
| 151 |
return cls.llm(str_prompt_vernacular_s)
|
| 152 |
-
elif question_type == "
|
| 153 |
str_prompt_appreciate_s = prompt_mode + cls.get_str_response_appreciate(history)
|
| 154 |
return cls.llm(str_prompt_appreciate_s)
|
| 155 |
-
elif question_type == "
|
| 156 |
str_prompt_vocab_s = prompt_mode + cls.get_str_response_vocab(history)
|
| 157 |
return cls.llm(str_prompt_vocab_s)
|
| 158 |
-
elif question_type == "
|
| 159 |
str_prompt_author_s = prompt_mode + cls.get_str_response_author(history)
|
| 160 |
return cls.llm(str_prompt_author_s)
|
| 161 |
-
elif question_type == "
|
| 162 |
str_prompt_background_s = prompt_mode + cls.get_str_response_background(history)
|
| 163 |
return cls.llm(str_prompt_background_s)
|
| 164 |
|
|
|
|
| 90 |
return "请求次数过多,请重试"
|
| 91 |
|
| 92 |
if pattern == "adult":
|
| 93 |
+
print("成人模式")
|
| 94 |
response = cls.chat_adult(question_type=question_type, history=history)
|
| 95 |
else:
|
| 96 |
+
print("青少年或儿童模式")
|
| 97 |
response = cls.chat_teen_or_child(pattern=pattern, question_type=question_type, history=history)
|
| 98 |
print(f"response:{response}")
|
| 99 |
return response
|
|
|
|
| 130 |
return cls.get_str_response_appreciate(history)
|
| 131 |
elif question_type == "词语解释":
|
| 132 |
return cls.get_str_response_vocab(history)
|
|
|
|
|
|
|
| 133 |
elif question_type == "作者简介":
|
| 134 |
+
return cls.get_str_response_author(history)
|
| 135 |
+
elif question_type == "写作背景":
|
| 136 |
return cls.get_str_response_background(history)
|
| 137 |
|
| 138 |
@classmethod
|
|
|
|
| 146 |
"""
|
| 147 |
prompt_mode = cls.prompts["pattern"][pattern]
|
| 148 |
|
| 149 |
+
if question_type == "诗词原文":
|
| 150 |
return cls.get_str_response_origin(history)
|
| 151 |
+
elif question_type == "诗词白话文翻译":
|
| 152 |
str_prompt_vernacular_s = prompt_mode + cls.get_str_response_vernacular(history)
|
| 153 |
return cls.llm(str_prompt_vernacular_s)
|
| 154 |
+
elif question_type == "诗词鉴赏":
|
| 155 |
str_prompt_appreciate_s = prompt_mode + cls.get_str_response_appreciate(history)
|
| 156 |
return cls.llm(str_prompt_appreciate_s)
|
| 157 |
+
elif question_type == "词语解释":
|
| 158 |
str_prompt_vocab_s = prompt_mode + cls.get_str_response_vocab(history)
|
| 159 |
return cls.llm(str_prompt_vocab_s)
|
| 160 |
+
elif question_type == "作者简介":
|
| 161 |
str_prompt_author_s = prompt_mode + cls.get_str_response_author(history)
|
| 162 |
return cls.llm(str_prompt_author_s)
|
| 163 |
+
elif question_type == "写作背景":
|
| 164 |
str_prompt_background_s = prompt_mode + cls.get_str_response_background(history)
|
| 165 |
return cls.llm(str_prompt_background_s)
|
| 166 |
|
gradio_ui/gr_chat.py
CHANGED
|
@@ -68,9 +68,11 @@ def chat_user(user_message: str, history: list[list], action: bool):
|
|
| 68 |
单次对话中,首先调用的函数
|
| 69 |
"""
|
| 70 |
print("调用chat_user")
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 73 |
ChatPoet.allow_chat(user_message=user_message)
|
|
|
|
| 74 |
if (action is True) or (ChatPoet.res_dict != {}) and (ChatPoet.res_dict["exist"]):
|
| 75 |
print(f"action is True: {action is True}")
|
| 76 |
print(f"ChatPoet.res_dict: {ChatPoet.res_dict == {}}")
|
|
|
|
| 68 |
单次对话中,首先调用的函数
|
| 69 |
"""
|
| 70 |
print("调用chat_user")
|
| 71 |
+
if action is True:
|
| 72 |
+
allowed = True
|
| 73 |
+
else:
|
| 74 |
ChatPoet.allow_chat(user_message=user_message)
|
| 75 |
+
allowed = False
|
| 76 |
if (action is True) or (ChatPoet.res_dict != {}) and (ChatPoet.res_dict["exist"]):
|
| 77 |
print(f"action is True: {action is True}")
|
| 78 |
print(f"ChatPoet.res_dict: {ChatPoet.res_dict == {}}")
|