|
@@ -38,11 +38,15 @@ class CozeChat:
|
|
|
response = self.coze.chat.create_and_poll(
|
|
|
bot_id=bot_id, user_id=user_id, additional_messages=messages,
|
|
|
custom_variables=custom_variables)
|
|
|
- logging.debug("coze response: {}".format(response.messages))
|
|
|
+ logging.debug("Coze response size: {}".format(len(response.messages)))
|
|
|
+ if response.chat.status != ChatStatus.COMPLETED:
|
|
|
+ logging.error("Coze chat not completed: {}".format(response.chat.status))
|
|
|
+ return None
|
|
|
+ final_response = None
|
|
|
for message in response.messages:
|
|
|
if message.type == MessageType.ANSWER:
|
|
|
- return message.content
|
|
|
- return None
|
|
|
+ final_response = message.content
|
|
|
+ return final_response
|
|
|
|
|
|
def setup_token_refresh(self):
|
|
|
thread = threading.Thread(target=self.refresh_token_loop)
|
|
@@ -73,7 +77,7 @@ if __name__ == '__main__':
|
|
|
coze = Coze(auth=TokenAuth(token=COZE_API_TOKEN), base_url=COZE_CN_BASE_URL)
|
|
|
|
|
|
# Create a bot instance in Coze, copy the last number from the web link as the bot's ID.
|
|
|
- bot_id = "7479005417885417487"
|
|
|
+ bot_id = "7491250992952999973"
|
|
|
# The user id identifies the identity of a user. Developers can use a custom business ID
|
|
|
# or a random string.
|
|
|
user_id = "dev_user"
|
|
@@ -81,7 +85,7 @@ if __name__ == '__main__':
|
|
|
chat = coze.chat.create_and_poll(
|
|
|
bot_id=bot_id,
|
|
|
user_id=user_id,
|
|
|
- additional_messages=[Message.build_user_question_text("北京今天天气怎么样")],
|
|
|
+ additional_messages=[Message.build_user_question_text("钱塘江边 樱花开得不错,推荐一个视频吧")],
|
|
|
custom_variables={
|
|
|
'agent_name': '芳华',
|
|
|
'agent_age': '25',
|