zhayujie / chatgpt-on-wechat

基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择GPT3.5/GPT-4o/GPT-o1/ Claude/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Claude/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。
https://docs.link-ai.tech/cow
MIT License
31.57k stars 8.21k forks source link

想在chatgpt-on-wechat中提供API接口,给第三方接口使用。 #1512

Open hevenwus opened 1 year ago

hevenwus commented 1 year ago

⚠️ 搜索是否存在类似issue

总结

想在chatgpt-on-wechat中使用FastAPI启动接口服务,提供给第三方使用。 微信主要功能:给某个人或群组发送定时消息等。

举例

`import uvicorn from fastapi import FastAPI from bridge.reply import Reply, ReplyType from channel.wechat.wechat_channel import WechatChannel

app = FastAPI()

@app.get("/") async def root(): reply = Reply(ReplyType.TEXT, "你好!有什么问题或者需要帮助的吗?")
WechatChannel().send(reply , “如何封装Context?”)`

但是以上的做法会报错:

INFO: 192.168.1.8:49765 - "GET / HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi result = await app( # type: ignore[func-returns-value] File "/usr/local/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__ return await self.app(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 1106, in __call__ await super().__call__(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__ await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__ raise exc File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__ await self.app(scope, receive, _send) File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__ raise exc File "/usr/local/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__ await self.app(scope, receive, sender) File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__ raise e File "/usr/local/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__ await self.app(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__ await route.handle(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/starlette/routing.py", line 66, in app response = await func(request) File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 274, in app raw_response = await run_endpoint_function( File "/usr/local/lib/python3.10/site-packages/fastapi/routing.py", line 191, in run_endpoint_function return await dependant.call(**values) File "/app/api/main.py", line 11, in root WechatChannel().send(reply , None) File "/app/channel/wechat/wechat_channel.py", line 295, in send itchat.send(reply.content, toUserName=receiver) File "/app/lib/itchat/components/messages.py", line 513, in send r = self.send_msg(msg, toUserName) File "/app/lib/itchat/components/messages.py", line 283, in send_msg r = self.send_raw_msg(1, msg, toUserName) File "/app/lib/itchat/components/messages.py", line 264, in send_raw_msg url = '%s/webwxsendmsg' % self.loginInfo['url'] KeyError: 'url'

动机

想在chatgpt-on-wechat中使用FastAPI启动接口服务,提供给第三方使用。 微信主要功能:给某个人或群组发送定时消息等。

clyquan commented 1 year ago

配置channel_type为wechatcom_app时,其实启动一个web服务,内部再调用openai,可以参考一下这块的实现

livypy commented 3 months ago

实现里吗 能分享一下吗

lovehug-lin commented 3 months ago

请问你这个问题解决了吗