Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增Claude聊天机器人接口(逆向cookie实现) #1382

Merged
merged 19 commits into from
Sep 1, 2023

Conversation

resphinas
Copy link
Contributor

@resphinas resphinas commented Aug 28, 2023

暂时不可用 会被封号,将在2024年一月份进行更新

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

添加 claude AI(逆向)bot
目前已知主流国家ip中 中国大陆和中国香港的不在claude支持名单中

相关参数

1.claude_api_cookie (选此bot时填写)

(有效期:目测一周,测试过有效期的小伙伴可以留言下)
获取cookie方法: 浏览器f12 打开控制台发送一条消息,复制完整cookie字符串即可
image

2. proxy(选此bot时非海外服务器时为必须项,claude需海外ip)

3. claude_uuid(可选,指定对话id,没有的话默认新建对话,不太了解claude机制的建议的直接置空,上下文共享优先级大于配置里的group_in_one_session,设定对话id即可指定对话又可强制全员共享该对话上下文)

新增依赖包

用于请求api的curl_cffi 包(必要),用于模拟指纹,是一种requests-like的包
curl_cffi包所在目录中不能存在中文
1.修改一切出现在报错中的中文为英文
2.重新采用 python -m venv venv 创建全新英文目录环境

生态小变动:

1.无法查看 tokens, 返回tokens = invisible
2.如文心一言接口一样去除role = system功能
改动均在该bot下,不影响其他接口。

待优化事项:

1.版本可能会提示 no module named bot.claude.claide_ai_session
只需要把claude目录中的 claide_ai_session 文件加上 .py后缀
2.claude_uuid指定对话暂不可用
3.重复函数待删除
4.ip被ban、cookie格式、速率限制相关提示
5.........

应用测试
1693214936921

@resphinas resphinas changed the title 新增Claude机器人模块(逆向cookie实现) 新增Claude聊天机器人(逆向cookie实现) Aug 28, 2023
@resphinas resphinas changed the title 新增Claude聊天机器人(逆向cookie实现) 新增Claude聊天机器人(逆向cookie实现,稳定不失效) Aug 28, 2023
@resphinas
Copy link
Contributor Author

resphinas commented Aug 28, 2023

部署测试 image
配置:日本东京linux 1g1c
参数:在config.json 填写相应claude_api_cookie ,proxy为空, 无claude_uuid
一键拉取项目+ 部署成功

@resphinas
Copy link
Contributor Author

resphinas commented Aug 28, 2023

容错测试

  1. 提供错误的 cookie 测试回显
    image
    2.ip被禁 测试回显
    image
    返回的是这个页面
    image

  2. 未在官网开通付费计划的情况下,一定时间有对话上限,超出了会返回 rate limited 字样, 到指定时间即可恢复, 与官网聊天网页同步,出现此现象可以前往网页端查看解禁时间。

@resphinas resphinas changed the title 新增Claude聊天机器人(逆向cookie实现,稳定不失效) 新增Claude聊天机器人接口(逆向cookie实现,稳定不失效) Aug 28, 2023
@@ -4,6 +4,9 @@
"channel_type": "wx",
"proxy": "",
"hot_reload": false,
"model": "claude",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model 和 channel_type 这两个参数重复了,可以移除下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

都改好啦,感谢指正!

requirements.txt Outdated Show resolved Hide resolved
@zhayujie
Copy link
Owner

zhayujie commented Sep 1, 2023

感谢pr

@zhayujie zhayujie merged commit a23a65c into zhayujie:master Sep 1, 2023
@zhayujie
Copy link
Owner

zhayujie commented Sep 1, 2023

支持上下文记忆嘛

@resphinas
Copy link
Contributor Author

你用GPT 的API是没问题的

@resphinas
Copy link
Contributor Author

你用GPT 的API是没问题的

看了下claude官网支持的国家,新加坡是在名单的,奇怪

@stonechen03
Copy link

是啊,是不是因为我用Linux系统的原因?

@resphinas
Copy link
Contributor Author

resphinas commented Sep 2, 2023

是啊,是不是因为我用Linux系统的原因?

.......这么说的话我用的是centos,不过真的会跟这个有关系吗😂玄学
有个强制跳过小技巧你用一下看看后面有没有新的报错
image
找到这个uuid 手动把他改成organization_uuid的值试试 让他直接return 具体值
image
返回是一个html的话 那基本ip问题没跑了0.o 不过为什么你的新加坡就不行呢 费解费解费解!

@stonechen03
Copy link

好的,我试试

@resphinas resphinas changed the title 新增Claude聊天机器人接口(逆向cookie实现,稳定不失效) 新增Claude聊天机器人接口(逆向cookie实现) Sep 2, 2023
@stonechen03
Copy link

[ERROR][2023-09-02 15:59:15][chat_channel.py:280] - Worker return exception: invalid decimal literal (claude_ai_bot.py, line 98)
Traceback (most recent call last):
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/data/chatgpt-on-wechat/channel/chat_channel.py", line 155, in _handle
reply = self._generate_reply(context)
File "/data/chatgpt-on-wechat/channel/chat_channel.py", line 165, in _generate_reply
e_context = PluginManager().emit_event(
File "/data/chatgpt-on-wechat/plugins/plugin_manager.py", line 189, in emit_event
instance.handlers[e_context.event](e_context, *args, **kwargs)
File "/data/chatgpt-on-wechat/plugins/newgpt_turbo/main.py", line 98, in on_handle_context
all_sessions = Bridge().get_bot("chat").sessions
File "/data/chatgpt-on-wechat/bridge/bridge.py", line 44, in get_bot
self.bots[typename] = create_bot(self.btype[typename])
File "/data/chatgpt-on-wechat/bot/bot_factory.py", line 44, in create_bot
from bot.claude.claude_ai_bot import ClaudeAIBot
File "/data/chatgpt-on-wechat/bot/claude/claude_ai_bot.py", line 98
return 5e399996-51aa-439f-94be-7c88ecfb0ab5
^
SyntaxError: invalid decimal literal

@resphinas
Copy link
Contributor Author

return "5e399996-51aa-439f-94be-7c88ecfb0ab5"

@stonechen03
Copy link

模型设置为: claude), receiver=@14e8d737b0dbc8e4fbdca85baa2d29cd
[INFO][2023-09-02 16:06:54][main.py:97] - newgpt_turbo query=你好
[INFO][2023-09-02 16:06:54][bridge.py:38] - create bot claude for chat

    <!DOCTYPE html><html lang="en" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#">

<head><link

rel="dns-prefetch" href="https://www.anthropic.com/" crossorigin><script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js"></script>

    <script src="/js/site.js?id=9c708111992f94585c703251d84eb26b"></script>

<script>(function() {

var tag = document.createElement('script');
tag.src = "https://cdn.usefathom.com/script.js";
tag.defer = true;
tag.setAttribute("data-site", "FWWARNSL");
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
})();
</script>

<script type="application/ld+json">{"@context":"http://schema.org","@graph":[{"@type":"WebPage","author":{"@id":"https://anthropic.com#identity"},"copyrightHolder":{"@id":"https://anthropic.com#identity"},"copyrightYear":"2023","creator":{"@id":"https://anthropic.com#creator"},"dateModified":"2023-05-11T07:21:04-07:00","datePublished":"2023-03-03T21:21:00-08:00","description":"Anthropic is an AI safety and research company that's working to build reliable, interpretable, and steerable AI systems.","headline":"App unavailable","image":{"@type":"ImageObject","url":"https://www-images.anthropic.com/production/images/anthropic-social_share.png?w=1200&h=630&q=82&auto=format&fit=crop&dm=1676585898&s=21b0a416036ef14a47124429243b4041"},"inLanguage":"en-us","mainEntityOfPage":"https://www.anthropic.com/app-unavailable-in-region","name":"App unavailable","publisher":{"@id":"https://anthropic.com#creator"},"url":"https://www.anthropic.com/app-unavailable-in-region"},{"@id":"https://anthropic.com#identity","@type":"LocalBusiness","alternateName":"Anthropic","description":"Anthropic is an AI safety and research company. We build reliable, interpretable, and steerable AI systems.","name":"Anthropic PBC","priceRange":"$","sameAs":["https://twitter.com/AnthropicAI","https://www.linkedin.com/company/anthropicresearch"],"url":"https://anthropic.com"},{"@id":"#creator","@type":"Organization"},{"@type":"BreadcrumbList","description":"Breadcrumbs list","itemListElement":[{"@type":"ListItem","item":"https://www.anthropic.com","name":"Home","position":1},{"@type":"ListItem","item":"https://www.anthropic.com/app-unavailable-in-region","name":"App unavailable","position":2}],"name":"Breadcrumbs"}]}</script>

[INFO][2023-09-02 16:06:57][main.py:307] - 模型响应无函数调用,跳过处理
[ERROR][2023-09-02 16:06:58][claude_ai_bot.py:214] - Expecting value: line 2 column 9 (char 9)
Traceback (most recent call last):
File "/data/chatgpt-on-wechat/bot/claude/claude_ai_bot.py", line 144, in _chat
con_uuid = self.conversation_share_check(session_id)
File "/data/chatgpt-on-wechat/bot/claude/claude_ai_bot.py", line 103, in conversation_share_check
self.create_new_chat(self.con_uuid_dic[session_id])
File "/data/chatgpt-on-wechat/bot/claude/claude_ai_bot.py", line 126, in create_new_chat
return response.json()
File "/usr/local/lib/python3.10/dist-packages/curl_cffi/requests/cookies.py", line 54, in json
return loads(self.content, **kw)
File "/usr/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 9 (char 9)
[WARNING][2023-09-02 16:07:00][claude_ai_bot.py:217] - [CLAUDE] do retry, times=0
[INFO][2023-09-02 16:07:00][claude_ai_bot.py:150] - [CLAUDEAI] query=你好
[ERROR][2023-09-02 16:07:01][claude_ai_bot.py:214] - Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "/data/chatgpt-on-wechat/bot/claude/claude_ai_bot.py", line 191, in _chat
data = json.loads(json_str)
File "/usr/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
[WARNING][2023-09-02 16:07:03][claude_ai_bot.py:217] - [CLAUDE] do retry, times=1
[WARNING][2023-09-02 16:07:03][claude_ai_bot.py:138] - [CLAUDEAI] failed after maximum number of retry times
[INFO][2023-09-02 16:07:03][wechat_channel.py:189] - [WX] sendMsg=Reply(type=ERROR, content=[ERROR]
请再问我一次吧), receiver=@14e8d737b0dbc8e4fbdca85baa2d29cd

@resphinas
Copy link
Contributor Author

resphinas commented Sep 2, 2023 via email

@stonechen03
Copy link

无解,只能等API的方式了。

@resphinas
Copy link
Contributor Author

resphinas commented Sep 2, 2023

只是个ip的问题,处理方式还是有很多的,用下代理就可以了。

@stonechen03
Copy link

😄懒得折腾了,在SG还代理,岂不是没必要

@resphinas
Copy link
Contributor Author

单个代理一个月可能才几元钱 还是可以考虑下

@fatwang2
Copy link
Contributor

fatwang2 commented Sep 3, 2023

指定对话id后没有生效,还是依然新建对话,请问有什么排查思路吗?

@resphinas
Copy link
Contributor Author

resphinas commented Sep 3, 2023 via email

@resphinas
Copy link
Contributor Author

指定对话id后没有生效,还是依然新建对话,请问有什么排查思路吗?

已提交pr修复

@leungyiuhoi
Copy link

我成功了
6cb4863b9a5264c5321c313b7967bed

@leungyiuhoi
Copy link

啊? 我用新加坡ip就用不了chatgpt.... image

换美国的服务器吧

@leungyiuhoi
Copy link

用了两天就被封号了
1697797022715

@resphinas
Copy link
Contributor Author

用了两天就被封号了 1697797022715

可能是你的对话内容涉及到禁止,也可能是这个逆向被识别,不过概率比较低,具体原因有待观察

@LargeCupPanda
Copy link

Claude cook有效,之前正常使用,未做任何改动,今日提示不可用:Invalid model
[ERROR][2023-11-21 16:49:57][claude_ai_bot.py:207] - [CLAUDE] chat failed, status_code=403, msg=Invalid model, type=permission_error, detail: {"error":{"type":"permission_error","message":"Invalid model","code":"model_not_allowed"}}, uuid: 40-35-4*4-f-15f3e6

@joyce677
Copy link

逆向已经失效

@fatwang2
Copy link
Contributor

fatwang2 commented Nov 24, 2023 via email

@resphinas
Copy link
Contributor Author

resphinas commented Nov 24, 2023

最近在忙,2024年一月份会进行更新

@stonechen03
Copy link

最近很忙,2024年一月份会进行更新

更新api支持方式啊。别用这种了。现在api还申请。

@resphinas
Copy link
Contributor Author

resphinas commented Dec 5, 2023 via email

Leslie0310 pushed a commit to Leslie0310/chatgpt-on-wechat that referenced this pull request Dec 8, 2024
新增Claude聊天机器人接口(逆向cookie实现,稳定不失效)
zcpisme pushed a commit to zcpisme/dify-on-wechat that referenced this pull request Dec 28, 2024
新增Claude聊天机器人接口(逆向cookie实现,稳定不失效)
zcpisme pushed a commit to zcpisme/dify-on-wechat that referenced this pull request Dec 28, 2024
新增Claude聊天机器人接口(逆向cookie实现,稳定不失效)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants