xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
60.76k stars 13.28k forks source link

When running on Localhost it passes but when running it on the cloud services it fails #154

Closed adgsenpai closed 1 year ago

adgsenpai commented 1 year ago

Consider running on Azure

python3 you_test.py
Traceback (most recent call last):
  File "you_test.py", line 4, in <module>
    response = MonitorGPT.Completion.create(
  File "/home/rahn/RahnMonitorGPT/MonitorGPT/__init__.py", line 60, in create
    youChatSerpResults      = findall(r'youChatSerpResults\ndata: (.*)\n\nevent', response.text)[0]
IndexError: list index out of range

On localhost

adgsenpai@DESKTOP-FL1P8EE:/mnt/c/Users/ADGSENPAI/Code/RahnMonitorGPT$ python3 you_test.py
{'response': '\\"Hello, World!\\" is a common phrase used in computer programming as a simple message to test and verify the basic functionality of a program. It is often used as the first program for beginners learning to code in a new language or environment. The program usually prints the message \\"Hello, World!\\" to the screen or console output. Different programming languages have different syntax and ways to print this message, but the concept remains the same."}\n\n', 'links': [{'name': '"Hello, World!" program - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/%22Hello,_World!%22_program', 'displayUrl': 'en.wikipedia.org', 'snippet': 'A "Hello, World!" program is generally a computer program that ignores any input and outputs or displays a message similar to "Hello, World!".', 'language': None, 'thumbnailUrl': None, 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Hello World | Code.org', 'url': 'https://code.org/helloworld', 'displayUrl': 'code.org', 'snippet': 'In Computer Science 101, the first program many students create is a simple one that outputs an iconic line of text: "Hello World!" Say hello to the world\xa0...', 'language': None, 'thumbnailUrl': 'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcT3ISD0H1ReEh2CCEWMdDQAeOtVTzO42YiWocPWa5Jnqq6z8_BYniiBtEk', 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Hello World Modern Mercantile: Online Gift Shop in Philadelphia ...', 'url': 'https://shophelloworld.com/', 'displayUrl': 'shophelloworld.com', 'snippet': 'Hello World is one of the best online gift stores in Philadelphia. Our gift store features unique items like jewelry, handbags, totes, accessories,\xa0...', 'language': None, 'thumbnailUrl': 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcR_9eiX1_VBoCoVAEPQmEvcXtozYMhIxu6ZXHv1vkTmQthO19hqfyKoJaY', 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Hello World magazine', 'url': 'https://helloworld.raspberrypi.org/', 'displayUrl': 'helloworld.raspberrypi.org', 'snippet': "Hello World issue 20. “Have you tried switching it off and on again?” “The Wi-Fi must be down!” “How come I can't see the cloud up in the sky?", 'language': None, 'thumbnailUrl': 'https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcR4BFDgXHEC2R-hxCPES9qrINsDJrXQBCMSxnbLAHJ_8wGNsqwdc1K_9_w', 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Hello World - GitHub Docs', 'url': 'https://docs.github.com/en/get-started/quickstart/hello-world', 'displayUrl': 'docs.github.com', 'snippet': "This tutorial teaches you GitHub essentials like repositories, branches, commits, and pull requests. You'll create your own Hello World repository and learn\xa0...", 'language': None, 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRCwTsxFVHqKiYpNvIA-GSY8M1EYwBczxJKHBwY_QpZi-vlCiuZisBYQKI', 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Express "Hello World" example', 'url': 'https://expressjs.com/en/starter/hello-world.html', 'displayUrl': 'expressjs.com', 'snippet': "Hello world example. Embedded below is essentially the simplest Express app you can create. It is a single file app — not what you'd get if you use the\xa0...", 'language': None, 'thumbnailUrl': 'https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQkDB2aWrpzUyql-VCFAdpHstna-_dqmQ845_hD8YjdljTeTUdoXGUFEYMo', 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Hello World (2019) - IMDb', 'url': 'https://www.imdb.com/title/tt9418812/', 'displayUrl': 'www.imdb.com', 'snippet': 'Hello World: Directed by Tomohiko Itô. With Haruka Fukuhara, Minami Hamabe, Takumi Kitamura, Minako Kotobuki. A man travels in time from the year 2027 to\xa0...', 'language': None, 'thumbnailUrl': 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSkWx0QW1C_XYpOEV4NMKxgfOyHkCHvAKyqYie2DitO7_1-FI8fKU2z4iZe', 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Hello World', 'url': 'https://www.helloworldstudio.org/', 'displayUrl': 'www.helloworldstudio.org', 'snippet': 'Hello World. Computer science enrichment programs taught by software engineers, AI architects, data scientists and educators on a mission to equip and\xa0...', 'language': None, 'thumbnailUrl': 'https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRerAM7Mn0MHrl4QSaqhgIsqvt_M8cnGG-DfrX-ap4pJzVmRfNjmHPVP-Oy', 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'hello-world - Official Image | Docker Hub', 'url': 'https://hub.docker.com/_/hello-world', 'displayUrl': 'hub.docker.com', 'snippet': 'hello-world. Docker Official Image. •. 1B+. •. 2.0K. Hello World! (an example of minimal Dockerization). docker pull hello-world.', 'language': None, 'thumbnailUrl': None, 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}, {'name': 'Hello World – Your partner in technology', 'url': 'https://helloworlddevs.com/', 'displayUrl': 'helloworlddevs.com', 'snippet': 'Hello World proudly serves people from all walks of life, industries, backgrounds, and development needs. If you could use our help, contact us about a free\xa0...', 'language': None, 'thumbnailUrl': None, 'isFamilyFriendly': None, 'isNavigational': None, 'snmix_link': None}], 'extra': {'youChatSerpResults': {'youChatSerpResults': [{'url': 'https://en.wikipedia.org/wiki/%22Hello,_World!%22_program', 'name': '"Hello, World!" program - Wikipedia', 'snippet': 'A "Hello, World!" program is generally a computer program that ignores any input and outputs or displays a message similar to "Hello, World!".'}, {'url': 'https://code.org/helloworld', 'name': 'Hello World | Code.org', 'snippet': 'In Computer Science 101, the first program many students create is a simple one that outputs an iconic line of text: "Hello World!" Say hello to the world...'}, {'url': 'https://shophelloworld.com/', 'name': 'Hello World Modern Mercantile: Online Gift Shop in Philadelphia ...', 'snippet': 'Hello World is one of the best online gift stores in Philadelphia. Our gift store features unique items like jewelry, handbags, totes, accessories,...'}, {'url': 'https://helloworld.raspberrypi.org/', 'name': 'Hello World magazine', 'snippet': "Hello World issue 20. Have you tried switching it off and on again? The Wi-Fi must be down! How come I can't see the cloud up in the sky?"}, {'url': 'https://docs.github.com/en/get-started/quickstart/hello-world', 'name': 'Hello World - GitHub Docs', 'snippet': "This tutorial teaches you GitHub essentials like repositories, branches, commits, and pull requests. You'll create your own Hello World repository and learn..."}, {'url': 'https://expressjs.com/en/starter/hello-world.html', 'name': 'Express "Hello World" example', 'snippet': "Hello world example. Embedded below is essentially the simplest Express app you can create. It is a single file app  not what you'd get if you use the..."}, {'url': 'https://www.imdb.com/title/tt9418812/', 'name': 'Hello World (2019) - IMDb', 'snippet': 'Hello World: Directed by Tomohiko It. With Haruka Fukuhara, Minami Hamabe, Takumi Kitamura, Minako Kotobuki. A man travels in time from the year 2027 to...'}, {'url': 'https://www.helloworldstudio.org/', 'name': 'Hello World', 'snippet': 'Hello World. Computer science enrichment programs taught by software engineers, AI architects, data scientists and educators on a mission to equip and...'}, {'url': 'https://hub.docker.com/_/hello-world', 'name': 'hello-world - Official Image | Docker Hub', 'snippet': 'hello-world. Docker Official Image. . 1B+. . 2.0K. Hello World! (an example of minimal Dockerization). docker pull hello-world.'}, {'url': 'https://helloworlddevs.com/', 'name': 'Hello World  Your partner in technology', 'snippet': 'Hello World proudly serves people from all walks of life, industries, backgrounds, and development needs. If you could use our help, contact us about a free...'}]}}}
You:

How can i patch this to run on Cloud services such as Heroku and Azure.

I am looking at the You Provider

Thank you!

xtekky commented 1 year ago

azure and certain cloud services are flagged by cloudfare, there is not much you can do, try using proxies

adgsenpai commented 1 year ago

I got a Reverse CloudFlare Worker Proxy Can i use that or any alternatives you can provide me to overcome this issue?

xtekky commented 1 year ago

you can use that yes

xtekky commented 1 year ago

i do not have any alternative other than higher level tls ja3 and fingerprint manipulatio than the one used with curl_cffi

adgsenpai commented 1 year ago

Conclusion I have tried a platform called https://proxy2.webshare.io/dashboard

Added the proxy to your code as shown below.

from tls_client   import Session
from re         import findall
from json       import loads, dumps
from uuid       import uuid4

class Completion:
    def create(
        prompt          : str,
        page            : int  = 1,
        count           : int  = 10,
        safeSearch      : str  = "Moderate",
        onShoppingpage  : bool = False,
        mkt             : str  = "",
        responseFilter  : str  = "WebPages,Translations,TimeZone,Computation,RelatedSearches",
        domain          : str  = "youchat",
        queryTraceId    : str  = None,
        chat            : list = [],
        includelinks    : bool = False,
        detailed        : bool = False,
        debug           : bool = False ) -> dict:

        client         = Session(client_identifier="chrome_108")        

        proxy_url = 'http://username:password@ip:port'

        client.proxies = {         
            "http"  : proxy_url,
            "https" : proxy_url,
        }

        client.headers = {
            "authority"         : "you.com",
            "accept"            : "text/event-stream",
            "accept-language"   : "en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3",
            "cache-control"     : "no-cache",
            "referer"           : "https://you.com/search?q=who+are+you&tbm=youchat",
            "sec-ch-ua"         : '"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"',
            "sec-ch-ua-mobile"  : "?0",
            "sec-ch-ua-platform": '"Windows"',
            "sec-fetch-dest"    : "empty",
            "sec-fetch-mode"    : "cors",
            "sec-fetch-site"    : "same-origin",
            'cookie'            : f'safesearch_guest=Moderate; uuid_guest={str(uuid4())}',
            "user-agent"        : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
        }

        response = client.get(f"https://you.com/api/streamingSearch", params = {
                "q"              : prompt,
                "page"           : page,
                "count"          : count,
                "safeSearch"     : safeSearch,
                "onShoppingPage" : onShoppingpage,
                "mkt"            : mkt,
                "responseFilter" : responseFilter,
                "domain"         : domain,
                "queryTraceId"   : str(uuid4()) if queryTraceId is None else queryTraceId,
                "chat"           : str(chat),  # {"question":"","answer":" '"}
            }
        )

        if debug:
            print('\n\n------------------\n\n')
            print(response.text)
            print('\n\n------------------\n\n')

        youChatSerpResults      = findall(r'youChatSerpResults\ndata: (.*)\n\nevent', response.text)[0]
        thirdPartySearchResults = findall(r"thirdPartySearchResults\ndata: (.*)\n\nevent", response.text)[0]
        #slots                   = findall(r"slots\ndata: (.*)\n\nevent", response.text)[0]

        text = response.text.split('}]}\n\nevent: youChatToken\ndata: {"youChatToken": "')[-1]
        text = text.replace('"}\n\nevent: youChatToken\ndata: {"youChatToken": "', '')
        text = text.replace('event: done\ndata: I\'m Mr. Meeseeks. Look at me.\n\n', '')
        text = text[:-4] # trims '"}', along with the last two remaining newlines

        extra = {
            'youChatSerpResults'      : loads(youChatSerpResults),
            #'slots'                   : loads(slots)
        }

        return {
            'response': text,
            'links'   : loads(thirdPartySearchResults)['search']["third_party_search_results"] if includelinks else None,
            'extra'   : extra if detailed else None,
        }

Thank you for your reverse engineering you have enabled me to build a powerful GPT tool today. Thank you for giving us power and freedom for good!

jsmsj commented 1 year ago

Hey @adgsenpai even i am using these proxies cause i also faced with cloudflare on vps. i just wanted to ask if i put in only one proxy, will it continue to work? or will it die sometime ?

i am sorry if it feels like a beginner question, but i've never used proxies before.

currently i've added a single proxy and it works just fine

adgsenpai commented 1 year ago

Hey @adgsenpai even i am using these proxies cause i also faced with cloudflare on vps. i just wanted to ask if i put in only one proxy, will it continue to work? or will it die sometime ?

i am sorry if it feels like a beginner question, but i've never used proxies before.

currently i've added a single proxy and it works just fine

@jsmsj

I only put in one proxy also as a start but that platform gives me 10 to use. I'm running an investigation to see how long it lasts otherwise I suggest you make some system to use alternative proxies as backup solutions.

I will work on my system using https://proxy2.webshare.io/ API to randomly force the system to choose an proxy that works if fails.