From cc3a0fc367d7217d520cb2550b8f9cc2acc08d12 Mon Sep 17 00:00:00 2001 From: resphina <69687075+resphinas@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:28:13 +0800 Subject: [PATCH 1/3] Update config-template.json --- config-template.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config-template.json b/config-template.json index 003fbb6..6956a24 100644 --- a/config-template.json +++ b/config-template.json @@ -2,11 +2,11 @@ "open_ai_api_key": "YOUR API KEY", "model": "gpt-3.5-turbo", "channel_type": "wx", - "proxy": "http://127.0.0.1:33210", + "proxy": ", "hot_reload": false, "model": "claude", "channel_type": "wx", - "claude_api_cookie": "intercom-device-id-lupk8zyo=b37192f8-c3a5-408d-8525-60ad8c2cc57c; sessionKey=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; intercom-session-lupk8zyo=dHBseWhqVVIvVW4vZU1NMWM3eUpTQldjQkUwYUMwQVlGQ3g4azR6RlQ3ZDBkTTRqQWd4aGN6ZmY4MSt4aEVERy0tdXY0OGdnUTdYdVhsYWx3c2ErUFFTdz09--58fbe081d071984de6a196e49d513761e8b806e9; cf_clearance=9R_XpUT12.KKIRtXlXUFng05L_sdc0GDwz55ZBGsZ6o-1693003153-0-1-636ec5eb.e36b35e5.346f9a0b-0.2.1693003153; __cf_bm=TLFZA8a7JhAo6NRLVIL0jYsD8nb4cDna6slscBAns3A-1693004564-0-AfWzEcpZbRjF6cLEjxhPUnA84TNQDNQofUkZCuabIKkmQan+BlCvvYIeZod8ISJ/RLq1URvIsp++UwTDJyKfLI8=", + "claude_api_cookie": "", "hot_reload": true, "single_chat_prefix": [ "bot", @@ -18,7 +18,6 @@ ], "group_name_white_list": [ "ChatGPT测试群", - "高中数学应用题", "ChatGPT测试群2" ], "group_chat_in_one_session": [ From 187601da1e2e0969dd20c5b35fbc13e9688f192e Mon Sep 17 00:00:00 2001 From: resphina <69687075+resphinas@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:30:03 +0800 Subject: [PATCH 2/3] Update config-template.json --- config-template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config-template.json b/config-template.json index 6956a24..3af9fbc 100644 --- a/config-template.json +++ b/config-template.json @@ -2,7 +2,7 @@ "open_ai_api_key": "YOUR API KEY", "model": "gpt-3.5-turbo", "channel_type": "wx", - "proxy": ", + "proxy": "", "hot_reload": false, "model": "claude", "channel_type": "wx", From 8d9d5b7b6ff76de657ead33de5681a912ae09950 Mon Sep 17 00:00:00 2001 From: resphina <69687075+resphinas@users.noreply.github.com> Date: Mon, 28 Aug 2023 17:40:27 +0800 Subject: [PATCH 3/3] Update claude_ai_bot.py --- bot/claude/claude_ai_bot.py | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/bot/claude/claude_ai_bot.py b/bot/claude/claude_ai_bot.py index bb1cbd8..71cc970 100644 --- a/bot/claude/claude_ai_bot.py +++ b/bot/claude/claude_ai_bot.py @@ -2,7 +2,6 @@ import re import time import json import uuid - from curl_cffi import requests from bot.bot import Bot from bot.chatgpt.chat_gpt_session import ChatGPTSession @@ -15,10 +14,6 @@ from config import conf class ClaudeAIBot(Bot, OpenAIImage): - # authentication failed - AUTH_FAILED_CODE = 401 - NO_QUOTA_CODE = 406 - def __init__(self): super().__init__() self.sessions = SessionManager(ChatGPTSession, model=conf().get("model") or "gpt-3.5-turbo") @@ -32,9 +27,6 @@ class ClaudeAIBot(Bot, OpenAIImage): self.con_uuid = None self.get_uuid() - - - def generate_uuid(self): random_uuid = uuid.uuid4() random_uuid_str = str(random_uuid) @@ -48,11 +40,8 @@ class ClaudeAIBot(Bot, OpenAIImage): self.con_uuid = self.generate_uuid() self.create_new_chat() - - def get_organization_id(self): url = "https://claude.ai/api/organizations" - headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0', @@ -65,12 +54,11 @@ class ClaudeAIBot(Bot, OpenAIImage): 'Connection': 'keep-alive', 'Cookie': f'{self.claude_api_cookie}' } - response = requests.get(url, headers=headers,impersonate="chrome110",proxies=self.proxies) res = json.loads(response.text) uuid = res[0]['uuid'] - return uuid + def reply(self, query, context: Context = None) -> Reply: if context.type == ContextType.TEXT: return self._chat(query, context) @@ -108,9 +96,9 @@ class ClaudeAIBot(Bot, OpenAIImage): print(response.text) return uuid + def create_new_chat(self): url = f"https://claude.ai/api/organizations/{self.org_uuid}/chat_conversations" - payload = json.dumps({"uuid": self.con_uuid, "name": ""}) headers = { 'User-Agent': @@ -127,11 +115,10 @@ class ClaudeAIBot(Bot, OpenAIImage): 'Sec-Fetch-Site': 'same-origin', 'TE': 'trailers' } - response = requests.post( url, headers=headers, data=payload,impersonate="chrome110", proxies= self.proxies) - # Returns JSON of the newly created conversation information return response.json() + def _chat(self, query, context, retry_count=0) -> Reply: """ 发起对话请求 @@ -146,7 +133,6 @@ class ClaudeAIBot(Bot, OpenAIImage): return Reply(ReplyType.ERROR, "请再问我一次吧") try: - session_id = context["session_id"] session = self.sessions.session_query(query, session_id) model = conf().get("model") or "gpt-3.5-turbo" @@ -154,8 +140,6 @@ class ClaudeAIBot(Bot, OpenAIImage): if session.messages[0].get("role") == "system": if model == "wenxin": session.messages.pop(0) - - logger.info(f"[CLAUDEAI] query={query}") # do http request @@ -189,7 +173,6 @@ class ClaudeAIBot(Bot, OpenAIImage): } res = requests.post(base_url + "/api/append_message", headers=headers, data=payload,impersonate="chrome110",proxies= self.proxies,timeout=400) - if res.status_code == 200 or "pemission" in res.text: # execute success decoded_data = res.content.decode("utf-8") @@ -206,7 +189,6 @@ class ClaudeAIBot(Bot, OpenAIImage): logger.info(f"[CLAUDE] reply={reply_content}, total_tokens=100") self.sessions.session_reply(reply_content, session_id, 100) return Reply(ReplyType.TEXT, reply_content) - else: response = res.json() error = response.get("error") @@ -218,7 +200,6 @@ class ClaudeAIBot(Bot, OpenAIImage): time.sleep(2) logger.warn(f"[CLAUDE] do retry, times={retry_count}") return self._chat(query, context, retry_count + 1) - return Reply(ReplyType.ERROR, "提问太快啦,请休息一下再问我吧") except Exception as e: