interstellard / chatgpt-advanced

WebChatGPT: A browser extension that augments your ChatGPT prompts with web results.
https://webchatgpt.app
MIT License
6.45k stars 838 forks source link

Howto use the `bangs' shortcut search of duckduckgo in this plug-in? #92

Closed jumbojing closed 1 year ago

jumbojing commented 1 year ago

Howto use the `bangs' shortcut search of duckduckgo in this plug-in?

What are bangs?

Bangs are shortcuts that quickly take you to search results on other sites. For example, when you know you want to search on another site like Wikipedia or Amazon, our bangs get you there fastest. A search for !w filter bubble will take you directly to Wikipedia.

Remember, though, because your search is actually taking place on that other site, you are subject to that site’s policies, including its data collection practices.

We’ve had bangs since 2008 as part of our geek roots. Now we have thousands of !bangs and you can even submit your own.

Howto use the `bangs' shortcut search of duckduckgo in this plug-in, but it doesn't work after I try it. Can you @ qunash develop this function? I wrote a piece of code that might be useful.

def resolve_bang(bang):
    if not bang.startswith('!'):
        bang = '!%s' % bang
    gibberish = 'randomgibberish'
    url = 'https://duckduckgo.com/?q=%s+%s' % (urllib.parse.quote(bang), gibberish)
    r = requests.get(url)
    soup = bs4.BeautifulSoup(r.text, 'html.parser')
    # e.g., !gt => '0; url=http://translate.google.com/#auto/en/randomgibberish'
    redirect_url = soup.select_one('meta[http-equiv=refresh]')['content'][7:]
    if redirect_url.startswith('/'):
        redirect_url = urllib.parse.parse_qs(urllib.parse.urlparse(redirect_url).query)['uddg'][0]
    bang_url = redirect_url.replace(gibberish, '{{{s}}}')
    assert bang_url.startswith('http'), '%s is not an HTTP URL' % bang_url
    with open('resolve_bang.json', 'w') as f:
    json.dump(bang_url, f, indent=2)
    return
qunash commented 1 year ago

Hi, see the #99 announcement for the v3.0.0, which supports duckduckgo bangs!