|
@@ -167,7 +167,7 @@ def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
|
memory.USER_INTERACTIVE_CACHE[wxid] = { |
|
|
memory.USER_INTERACTIVE_CACHE[wxid] = { |
|
|
"interactive":False |
|
|
"interactive":False |
|
|
} |
|
|
} |
|
|
text='' |
|
|
|
|
|
|
|
|
text='' |
|
|
for item in reply_content: |
|
|
for item in reply_content: |
|
|
if item["type"] == "text": |
|
|
if item["type"] == "text": |
|
|
text=item["text"]["content"] |
|
|
text=item["text"]["content"] |
|
@@ -183,6 +183,20 @@ def handle_text(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
|
messages_to_send=gewe_chat.wxchat.save_session_messages_to_cache(hash_key, prompt) |
|
|
messages_to_send=gewe_chat.wxchat.save_session_messages_to_cache(hash_key, prompt) |
|
|
res=fast_gpt_api(messages_to_send,f'{wxid}-{callback_to_user}') |
|
|
res=fast_gpt_api(messages_to_send,f'{wxid}-{callback_to_user}') |
|
|
reply_content=res["choices"][0]["message"]["content"] |
|
|
reply_content=res["choices"][0]["message"]["content"] |
|
|
|
|
|
# print('-------------------------------------------------') |
|
|
|
|
|
# print(reply_content) |
|
|
|
|
|
# print('-------------------------------------------------') |
|
|
|
|
|
|
|
|
|
|
|
if isinstance(reply_content, list) : |
|
|
|
|
|
reply_content=reply_content[0].get('text').get("content") |
|
|
|
|
|
# print(reply_content) |
|
|
|
|
|
# print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') |
|
|
|
|
|
|
|
|
|
|
|
# try: |
|
|
|
|
|
# json_data = json.loads(reply_content) |
|
|
|
|
|
# reply_content=json_data[0].get('text').get("content") |
|
|
|
|
|
# except ValueError: |
|
|
|
|
|
# print("reply_content is a string, but not a valid JSON.") |
|
|
else: |
|
|
else: |
|
|
reply_content=text |
|
|
reply_content=text |
|
|
else: |
|
|
else: |
|
@@ -321,6 +335,11 @@ def handle_text_group(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
|
logger.info("发送对话 %s",input_message) |
|
|
logger.info("发送对话 %s",input_message) |
|
|
else: |
|
|
else: |
|
|
logger.info('群聊公开消息') |
|
|
logger.info('群聊公开消息') |
|
|
|
|
|
callback_to_user=msg_data["FromUserName"]["string"] |
|
|
|
|
|
dialogue_message=[{"type": "text", "text": msg_content}] |
|
|
|
|
|
input_message=utils.dialogue_message(callback_to_user,wxid,dialogue_message) |
|
|
|
|
|
kafka_helper.kafka_client.produce_message(input_message) |
|
|
|
|
|
logger.info("发送对话 %s",input_message) |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
def handle_image(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
|
def handle_image(token_id,app_id, wxid,msg_data,from_wxid, to_wxid): |
|
@@ -643,8 +662,8 @@ def get_messages_from_cache(hash_key,object:object)->list: |
|
|
return messages |
|
|
return messages |
|
|
|
|
|
|
|
|
def fast_gpt_api(messages:list,session_id:str): |
|
|
def fast_gpt_api(messages:list,session_id:str): |
|
|
#api_key="sk-tdi7u0zuLsR0JpPMGBeFZxymOpL0zoFVafX8EEEvEakIDAGQ22NyQ6w" |
|
|
|
|
|
api_key="sk-uJDBdKmJVb2cmfldGOvlIY6Qx0AzqWMPD3lS1IzgQYzHNOXv9SKNI" |
|
|
|
|
|
|
|
|
api_key="sk-jr69ONIehfGKe9JFphuNk4DU5Y5wooHKHhQv7oSnFzVbwCnW65fXO9kvH" #测试 |
|
|
|
|
|
#api_key="sk-uJDBdKmJVb2cmfldGOvlIY6Qx0AzqWMPD3lS1IzgQYzHNOXv9SKNI" #开发2 |
|
|
api_url = "http://106.15.182.218:3000/api/v1/chat/completions" |
|
|
api_url = "http://106.15.182.218:3000/api/v1/chat/completions" |
|
|
headers = { |
|
|
headers = { |
|
|
|
|
|
|
|
@@ -657,7 +676,7 @@ def fast_gpt_api(messages:list,session_id:str): |
|
|
"chatId": session_id, |
|
|
"chatId": session_id, |
|
|
"detail": True |
|
|
"detail": True |
|
|
} |
|
|
} |
|
|
print(json.dumps(data,ensure_ascii=False)) |
|
|
|
|
|
|
|
|
#print(json.dumps(data,ensure_ascii=False)) |
|
|
logger.info("[CHATGPT] 请求={}".format(json.dumps(data, ensure_ascii=False))) |
|
|
logger.info("[CHATGPT] 请求={}".format(json.dumps(data, ensure_ascii=False))) |
|
|
response = requests.post(url=api_url, headers=headers, data=json.dumps(data), timeout=600) |
|
|
response = requests.post(url=api_url, headers=headers, data=json.dumps(data), timeout=600) |
|
|
response.raise_for_status() |
|
|
response.raise_for_status() |
|
|