ChatGPT icon indicating copy to clipboard operation
ChatGPT copied to clipboard

[Feature Request]: Implementation for WebChatGPT

Open LuckyHead11 opened this issue 2 years ago • 72 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues and checked the recent builds/commits

What would your feature do ?

I have just come across the GitHub page: https://github.com/qunash/chatgpt-advanced ChatGPT-Advanced or WebChatGPT. The title is self-explanatory and gives ChatGPT access to the web similar to what BingGPT does through a Chrome Extension. I would like to know if you can implement something like it. This is what it does:

  1. Searches google and looks for relevant info.
  2. Changes the user's prompt to something like this: With the prompt being What is the ChatGPT Github page by acheong all about? Screenshot 2023-02-21 171235 Screenshot 2023-02-21 171814

You can ask directly to @qunash if you can implement or share code. Or you can copy the idea and make a similar feature to the API.

Proposed workflow

When you initialize the ChatBot in python you would simply add a "web" parameter. Which could be equal to True or False.

Additional information

No response

LuckyHead11 avatar Feb 21 '23 23:02 LuckyHead11

It'll take some time. I'll try to implement this next week when my mock exams are over

acheong08 avatar Feb 21 '23 23:02 acheong08

@f1nniboy has something similar to this as well. I'll ask him to share source code.

acheong08 avatar Feb 21 '23 23:02 acheong08

Alright thank you for considering!

LuckyHead11 avatar Feb 22 '23 00:02 LuckyHead11

good idea!

wlc002 avatar Feb 22 '23 06:02 wlc002

Thanks! I didn't really come up with the idea for WebChatGPT at first. I just thought it would be cool to see it here.

LuckyHead11 avatar Feb 22 '23 21:02 LuckyHead11

pynecone has something similar to the request, with local users and questions/answers management. You can take it as a reference. https://github.com/pynecone-io/pynecone-examples/tree/main/gpt

boxiyang avatar Feb 23 '23 04:02 boxiyang

I just reverse engineered the plugin and switched to python below. you can put it in code with a simple function. https://github.com/noseon/WebChatGPT-/blob/main/WebChatGPT%20.py

noseon avatar Feb 25 '23 18:02 noseon

@noseon that is very impressing!

LuckyHead11 avatar Feb 26 '23 01:02 LuckyHead11

Haha, i also reverse-engineered it for my project. Should've looked into issues earlier, could've been first :)

NymdaFromSalad avatar Feb 26 '23 15:02 NymdaFromSalad

@NymdaFromSalad is it on a GitHub repo?

LuckyHead11 avatar Feb 27 '23 23:02 LuckyHead11

I just reverse engineered the plugin and switched to python below. you can put it in code with a simple function. noseon/WebChatGPT-@main/WebChatGPT%20.py

I would rather not use a third party API. I wrote my own DuckDuckGo scraper API today in Go: https://github.com/acheong08/DuckDuckGo-API

acheong08 avatar Mar 01 '23 14:03 acheong08

As a side note, this will probably be a separate repository rather than part of this one.

I feel that an API would be most suitable for this rather than a Python library

acheong08 avatar Mar 01 '23 14:03 acheong08

pass your code to python and use it as a secondary api to your ChatGPT.

noseon avatar Mar 01 '23 15:03 noseon

Sounds great!

LuckyHead11 avatar Mar 02 '23 21:03 LuckyHead11

@LuckyHead11 No. It's here :) :

import requests, time

def apiSearch(query: str, numResults: int, timePeriod: str='', region: str=''):

    searchParams = ''
    searchParams += f'q={query}'
    searchParams += f'&max_results={numResults}'
    if timePeriod:
        searchParams += f'&time={timePeriod}'
    if region:
        searchParams += f'&region={region}'

    url = f'https://ddg-webapp-aagd.vercel.app/search?{searchParams}'

    response = requests.get(url)

    results = response.json()

    return results

def prepare_results(results):
    i=1
    res = ""
    for result in results:
        res+=f'[{i}] "{result["body"]}"\nURL: {result["href"]}\n\n'
        i+=1
    return res

def headers(results):
    res = []
    for result in results:
        #res.append({'text':f'[{i}] {result["title"]}', 'link':result["href"]})
        res.append(result["href"])
    return res

def compile_prompt(prompt, results, reply_in = 'language of the query'):
    return f'''Web search results:

{prepare_results(results)}
Current date: {time.strftime("%d.%m.%Y")}

Instructions: Using the provided web search results, write a comprehensive reply to the given query. Make sure to cite results using [number] notation after the reference. If the provided search results refer to multiple subjects with the same name, write separate answers for each subject.
Query: {prompt}
Reply in {reply_in}'''

def Webify(text:str, query: str, numResults: int, timePeriod: str='', region: str='', reply_in: str='undefined'):
    searchResults = apiSearch(query, numResults, timePeriod, region)
    return compile_prompt(text, searchResults, reply_in), headers(searchResults)

if __name__ == '__main__':
    print(Webify('Testing', 3))

text and query are separate, 'cause i also wanted to do other filters, which can add instructions

Also if you wandering, why the function is called headers, that's because in my native language, headlines, titles and headers means the same

NymdaFromSalad avatar Mar 02 '23 21:03 NymdaFromSalad

Awesome! @NymdaFromSalad @acheong08 with the code provided by Nymda implementing the Web/ChatGPT mix should be easy. Unless you would like to create your own way of using the web with ChatGPT ;) As you said though, you wouldn't use a 3rd party API.

LuckyHead11 avatar Mar 02 '23 22:03 LuckyHead11

@LuckyHead11Não. Está aqui :) :

import requests, time

def apiSearch(query: str, numResults: int, timePeriod: str='', region: str=''):

    searchParams = ''
    searchParams += f'q={query}'
    searchParams += f'&max_results={numResults}'
    if timePeriod:
        searchParams += f'&time={timePeriod}'
    if region:
        searchParams += f'&region={region}'

    url = f'https://ddg-webapp-aagd.vercel.app/search?{searchParams}'

    response = requests.get(url)

    results = response.json()

    return results

def prepare_results(results):
    i=1
    res = ""
    for result in results:
        res+=f'[{i}] "{result["body"]}"\nURL: {result["href"]}\n\n'
        i+=1
    return res

def headers(results):
    res = []
    for result in results:
        #res.append({'text':f'[{i}] {result["title"]}', 'link':result["href"]})
        res.append(result["href"])
    return res

def compile_prompt(prompt, results, reply_in = 'language of the query'):
    return f'''Web search results:

{prepare_results(results)}
Current date: {time.strftime("%d.%m.%Y")}

Instructions: Using the provided web search results, write a comprehensive reply to the given query. Make sure to cite results using [number] notation after the reference. If the provided search results refer to multiple subjects with the same name, write separate answers for each subject.
Query: {prompt}
Reply in {reply_in}'''

def Webify(text:str, query: str, numResults: int, timePeriod: str='', region: str='', reply_in: str='undefined'):
    searchResults = apiSearch(query, numResults, timePeriod, region)
    return compile_prompt(text, searchResults, reply_in), headers(searchResults)

if __name__ == '__main__':
    print(Webify('Testing', 3))

texto e consulta são separados, porque eu também queria fazer outros filtros, que podem adicionar instruções

Além disso, se você está vagando, por que a função é chamada de cabeçalhos, é porque no meu idioma nativo, manchetes, títulos e cabeçalhos significam o mesmo

and that's how it works

noseon avatar Mar 03 '23 02:03 noseon

Also need a mechanism for it to detect whether to search or not and convert natural language to a search query

acheong08 avatar Mar 03 '23 02:03 acheong08

Also need a mechanism for it to detect whether to search or not and convert natural language to a search query

Well, that's natural language processing and it is hard. Simplest solution would be to require user press the button and either using the whole query as the search parameter, or asking user for a search term. Honestly, forgot to check if WebGPT has any other mechanism. If it does - well, i need to reverse engineer it either way.

Also can use keywords, like putting /search at the start, makes it use WebGPT

Also you can ask ChatGPT to do NLP, as it is NLM :)

NymdaFromSalad avatar Mar 03 '23 07:03 NymdaFromSalad

and that's how it works

Also must mention:

  1. Search app gets content and cuts it to a certain size. (Maybe article preview feature can be used to extract data?)
  2. In the OG ChatGPT (website chat), WebGPT makes it use markdown and put references as (url)[number].
  3. For some reason WebGPT, when you select default profile, asks to 'Reply in Undefined'
  4. Headers function is used to put links into the final message, as API returns plaintext (and refs turn into just [number]) you can modify it, depending on how you want to put references in

NymdaFromSalad avatar Mar 03 '23 07:03 NymdaFromSalad

Also need a mechanism for it to detect whether to search or not and convert natural language to a search query

we could use a different package, like for V1: revChatGPT.V1 But for the web access one would be revChatGPT.V1_WEB or when you do chatbot.ask it would have a web parameter as I said in the beginning.

LuckyHead11 avatar Mar 03 '23 15:03 LuckyHead11

Also need a mechanism for it to detect whether to search or not and convert natural language to a search query

we could use a different package, like for V1: revChatGPT.V1 But for the web access one would be revChatGPT.V1_WEB or when you do chatbot.ask it would have a web parameter as I said in the beginning.

Oh, in that sense? Then:

  1. Needs better name, .webaccess .web or .webgpt are my picks
  2. You can create a web-accessing bot class, and either pass it chatbot object, or create internal chatbot instances, then it'll have additional functions to process web stuff and retain the OG ones

I dunno, i have some time on the weekend (and need to take a break from my personal project's SQL hijinx), if you guys want, i can make it (and do something i never done before - write decent code)

(Also, will try and use duckduckgo, as putting feature, that uses other people's (who do opensource, might i add) private servers without their consent into a library is not very nice. We only do it to evil corporations)

NymdaFromSalad avatar Mar 03 '23 16:03 NymdaFromSalad

Also need a mechanism for it to detect whether to search or not and convert natural language to a search query

we could use a different package, like for V1: revChatGPT.V1 But for the web access one would be revChatGPT.V1_WEB or when you do chatbot.ask it would have a web parameter as I said in the beginning.

Oh, in that sense? Then:

  1. Needs better name, .webaccess .web or .webgpt are my picks
  2. You can create a web-accessing bot class, and either pass it chatbot object, or create internal chatbot instances, then it'll have additional functions to process web stuff and retain the OG ones

I dunno, i have some time on the weekend (and need to take a break from my personal project's SQL hijinx), if you guys want, i can make it (and do something i never done before - write decent code)

(Also, will try and use duckduckgo, as putting feature, that uses other people's (who do opensource, might i add) private servers without their consent into a library is not very nice. We only do it to evil corporations)

Good Ideas! It's up to @acheong08 if you should make it. EDIT: Acheong did mention making another repository in that case WebGPT would be a good name for that.

LuckyHead11 avatar Mar 03 '23 16:03 LuckyHead11

Well, if you guys wanna use it, either way, it'll be time well spent

NymdaFromSalad avatar Mar 03 '23 16:03 NymdaFromSalad

EDIT: Acheong did mention making another repository in that case WebGPT would be a good name for that.

WebGPT is my slang for WebChatGPT, and it is also a name of another OpenAI product https://openai.com/research/webgpt Also, he was talking about an API to implement this feature, which is not my idea (as i see no benefit to putting it on a server. It is not a passive scraper, it only scrapes one query, on demand. The delay would be mostly due to page loading time anyway, and very minor too. Why not just do the scraping locally?)

NymdaFromSalad avatar Mar 03 '23 16:03 NymdaFromSalad

(Also, will try and use duckduckgo, as putting feature, that uses other people's (who do opensource, might i add) private servers without their consent into a library is not very nice. We only do it to evil corporations)

There is no need for that. I already wrote my own API for it and currently hosting on Heroku for testing https://github.com/acheong08/DuckDuckGo-API

acheong08 avatar Mar 03 '23 16:03 acheong08

I dunno, i have some time on the weekend

Let me know if you do. There's no point in duplicating efforts.

acheong08 avatar Mar 03 '23 16:03 acheong08

(Also, will try and use duckduckgo, as putting feature, that uses other people's (who do opensource, might i add) private servers without their consent into a library is not very nice. We only do it to evil corporations)

There is no need for that. I already wrote my own API for it and currently hosting on Heroku for testing https://github.com/acheong08/DuckDuckGo-API

Well, using your api is one of two options i consider. As i said, there is no need to put the code on a server, if it can perfectly run locally imo. But also, there is no point to inventing bicycle again, so it is a question of 'is it worth it to translate a scraper, if it will use less servers'

Also i was referring to WebChatGPT's server in that fragment

But hey, if you're against me scraping locally in this situation, then ok, will use your api

NymdaFromSalad avatar Mar 03 '23 17:03 NymdaFromSalad

I prefer scraping locally

acheong08 avatar Mar 03 '23 17:03 acheong08

I just wrote the API because I couldn't figure out how to scrape reliably locally in Python.

acheong08 avatar Mar 03 '23 17:03 acheong08