cohere-ai / sandbox-grounded-qa

A sandbox repo for grounded question answering with Cohere and Google Search

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

################################################################################
#    ____      _                     ____                  _ _                 #
#   / ___|___ | |__   ___ _ __ ___  / ___|  __ _ _ __   __| | |__   _____  __  #
#  | |   / _ \| '_ \ / _ \ '__/ _ \ \___ \ / _` | '_ \ / _` | '_ \ / _ \ \/ /  #
#  | |__| (_) | | | |  __/ | |  __/  ___) | (_| | | | | (_| | |_) | (_) >  <   #
#   \____\___/|_| |_|\___|_|  \___| |____/ \__,_|_| |_|\__,_|_.__/ \___/_/\_\  #
#                                                                              #
# This project is part of Cohere Sandbox, Cohere's Experimental Open Source    #
# offering. This project provides a library, tooling, or demo making use of    #
# the Cohere Platform. You should expect (self-)documented, high quality code  #
# but be warned that this is EXPERIMENTAL. Therefore, also expect rough edges, #
# non-backwards compatible changes, or potential changes in functionality as   #
# the library, tool, or demo evolves. Please consider referencing a specific   #
# git commit or version if depending upon the project in any mission-critical  #
# code as part of your own projects.                                           #
#                                                                              #
# Please don't hesitate to raise issues or submit pull requests, and thanks    #
# for checking out this project!                                               #
#                                                                              #
################################################################################

Maintainer: nickfrosst
Project maintained until at least (YYYY-MM-DD): 2023-01-01

Grounded Question Answering

This is a Cohere API / Serp API powered contextualized factual question answering bot!

It responds to question in discord or in the cli by understanding the context, google searching what it believes to be the appropriate question, finding relevant information on the google result pages and then answering the question based on what it found.

Motivation

Language models are very good at creating sensible answers to complex questions. They are not however very good at creating truthful answers. This is because language models don't have a mechanism for determining truth. They are trained on data from the web, and so pick up statistical correlations between words that make them ok at answering simple and static questions (things like "how far away is the moon from the earth", which has a single and unchanging factual answer), but more nuanced questions or that have factual answers which change over time (things like "who is the prime minister of the UK") are difficult or impossible for language models to answer.

Google search, on the other hand, is very good at retrieving factual information about these time-sensitive questions. Google makes use of a consensus mechanism for determining truth. Google search results are heavily affected by human user behaviour; which links people click, which links they stay on, and which ones they revisit all affect the ordering of the results. In this way, google determines which links are truthful through user consensus. Google however is quite poor at responding to contextual questions, and at responding to complex questions in natural language.

This project attempts to join the best of both of these methods; It uses Cohere's large language models to contextualize the given questions and create a natural language answer, but it uses google search as a source of truth.

Example

image

Overview Video

Here is a quick video demoing the project and talking about ways in which it can be improved.

Installation and Demo Use

To use this library, you will need:

  1. Clone the repository.
  2. Install all the dependencies
pip install -r requirements.txt
  1. Try the demo by running the cli tool
python3 cli_demo.py --cohere_api_key <API_KEY> --serp_api_key <API_KEY>

or with increased verbosity

python3 cli_demo.py --cohere_api_key <API_KEY> --serp_api_key <API_KEY> --verbosity 2
  1. (Optional) Run the discord bot demo:
    You can create a discord both with this functionality by creating a bot account with message read and write permissions at https://discord.com/developers then running the following command
python3 discord_bot.py --cohere_api_key <API_KEY> --serp_api_key <API_KEY> --discord_key <DISCORD_KEY>
  1. (Optional) Run the demo as REST based web service:
python3 rest_bot.py --cohere_api_key <API_KEY> --serp_api_key <API_KEY> --discord_key <DISCORD_KEY>

and send a request

curl --request POST --url http://localhost:5007/api/v1/ask --header 'content-type: application/json' --data '{ "question":"When was the fall of Constantinople?" }'

Get support

If you have any questions or comments, please file an issue or reach out to us on Discord.

Contributors

If you would like to contribute to this project, please read CONTRIBUTORS.md in this repository, and sign the Contributor License Agreement before submitting any pull requests. A link to sign the Cohere CLA will be generated the first time you make a pull request to a Cohere repository.

License

Grounded Question Answering has an MIT license, as found in the LICENSE file.

About

A sandbox repo for grounded question answering with Cohere and Google Search

License:MIT License


Languages

Language:Python 100.0%