tangxiaofeng7 / SecuriytAi

AI赋能网络安全做任何事-Security AI (Power by langchain)
11 stars 1 forks source link

问题请教 #2

Open IsBigLin opened 11 months ago

IsBigLin commented 11 months ago

你好 ​十分冒昧打扰到你了,我这边对接edge chat过程中遇到点问题,在github上看到您的回答,所以耽误你几分钟。 问题链接:https://github.com/acheong08/EdgeGPT/issues/584 我这边也是开启proxy代理后,报错“websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 200” 检查过代理是OK的,直接访问bing.com 可以正常使用。不知道什么原因?麻烦你可以帮忙解答下吗? 我的手机号是13758289287,微信:lnqdyy ,邮箱:naiqing.lnq@taobao.com 感谢

fenglilinglegeluan commented 11 months ago

https://github.com/acheong08/EdgeGPT/releases/tag/0.10.16 我用了这个版本,目前没问题

fenglilinglegeluan commented 11 months ago

但是问题是响应有点慢,我后面可能会放弃bing,转用其他的一些api。

IsBigLin commented 11 months ago

非常感谢哈, https://github.com/acheong08/EdgeGPT/releases/tag/0.10.16 请求demo实例方便发一下吗?10.16和文档中的请求示例不一致

fenglilinglegeluan commented 11 months ago

稍等,我一会看一下

IsBigLin commented 11 months ago

好的,谢谢你。

IsBigLin commented 11 months ago

image

IsBigLin commented 11 months ago

https://github.com/acheong08/EdgeGPT/releases/tag/0.10.16 我用了这个版本,目前没问题

你好,这是我本机通过代理测试的结果,基于0.10.16测试,网络连接不上,不知道你这边有这个问题吗?

fenglilinglegeluan commented 11 months ago
import re
import json
import os
from EdgeGPT.EdgeGPT import Chatbot
from EdgeGPT.conversation_style import ConversationStyle
import sys

class NewBing():
    def __init__(self):
        current_path = os.path.dirname(__file__)
        cookies_path = current_path + '\\bing_cookies.json'
        self.COOKIE = json.loads(open(cookies_path, encoding="utf-8").read()
                                 )
    async def bingChat(self,messageText):
        gbot = Chatbot(cookies=self.COOKIE,proxy="socks5://127.0.0.1:7890")
        response_dicts = await gbot.ask(prompt=messageText, conversation_style=ConversationStyle.precise)
        #json_str = json.dumps(response_dicts['item']['messages'])
        #file = open("json.txt",'w')
        #file.write(json_str)
        #file.close()
        #print("JSON: \n"+json_str)
        response_dict = response_dicts['item']['messages']
        responses = ""
        if "text" in response_dict[1]:
                responses = re.sub(r'\[\^\d\^\]', '',
                                  response_dict[1]['text']) + "\r"
        for i in range(2,len(response_dict)):
            if "hiddenText" in response_dict[i] and "text" not in response_dict[i]:
                response_old = re.sub(r'^```json|```$','',response_dict[i]['hiddenText'])
                try:
                    response_json = json.loads(response_old)
                except:
                    response = "未搜索到答案"
                    continue
                if type(response_json) is dict:
                    if 'web_search_results' in response_json:
                        if 'snippets' in response_json['web_search_results'][0]:
                            response = response_json['web_search_results'][0]['snippets'][0]
                            #print(response_json['web_search_results'][0]['snippets'])
                        else:
                            response = "发生了一些故障,请重新开始聊天。"
                    else:
                        response = "发生了一些故障,请重新开始聊天。"  
                elif type(response_json) is str:
                    response = response_json
            else:
                response = "发生了一些故障,请重新开始聊天。"
            responses = responses + str(i) + "\n*************\n" + response + "\n"
        response = responses

        if 'maxNumUserMessagesInConversation' in response_dicts['item']['throttling'] and 'numUserMessagesInConversation' in response_dicts['item']['throttling']:
            maxNumUserMessagesInConversation = response_dicts['item'][
                'throttling']['maxNumUserMessagesInConversation']
            numUserMessagesInConversation = response_dicts['item']['throttling']['numUserMessagesInConversation']
            response = response+"\n----------\n"
            response = response+"正在对话的消息 : %d / %d" % (
                numUserMessagesInConversation, maxNumUserMessagesInConversation)

        if numUserMessagesInConversation >= maxNumUserMessagesInConversation:
            await gbot.reset()
            response = response+"\n对话历史记录已自动清除"
        print("Bingsay: "+response)
        return response

        if (len(response_dict['item']['messages'][1]['sourceAttributions']) >= 3):
            providerDisplayName0 = re.sub(
                r'\[\^\d\^\]', '', response_dict['item']['messages'][1]['sourceAttributions'][0]['providerDisplayName'])
            seeMoreUrl0 = re.sub(
                r'\[\^\d\^\]', '', response_dict['item']['messages'][1]['sourceAttributions'][0]['seeMoreUrl'])
            providerDisplayName1 = re.sub(
                r'\[\^\d\^\]', '', response_dict['item']['messages'][1]['sourceAttributions'][1]['providerDisplayName'])
            seeMoreUrl1 = re.sub(
                r'\[\^\d\^\]', '', response_dict['item']['messages'][1]['sourceAttributions'][1]['seeMoreUrl'])
            providerDisplayName2 = re.sub(
                r'\[\^\d\^\]', '', response_dict['item']['messages'][1]['sourceAttributions'][2]['providerDisplayName'])
            seeMoreUrl2 = re.sub(
                r'\[\^\d\^\]', '', response_dict['item']['messages'][1]['sourceAttributions'][2]['seeMoreUrl'])
            response = response+"\n----------\nReference:\n"
            response = response + \
                "1.[%s](%s)\n" % (providerDisplayName0, seeMoreUrl0)
            response = response + \
                "2.[%s](%s)\n" % (providerDisplayName1, seeMoreUrl1)
            response = response + \
                "3.[%s](%s)\n" % (providerDisplayName2, seeMoreUrl2)

if __name__ == "__main__":
    bingChat = NewBing()
    while True:
        message = input("Lttsay: ")
        asyncio.run(bingChat.bingChat(message))
fenglilinglegeluan commented 11 months ago

不知道你搞定没有。。。下班聚餐给忘记了,刚发现