diff --git a/pgml-apps/pgml-chat/.gitignore b/pgml-apps/pgml-chat/.gitignore index 2eea525d8..6769e21d9 100644 --- a/pgml-apps/pgml-chat/.gitignore +++ b/pgml-apps/pgml-chat/.gitignore @@ -1 +1,160 @@ -.env \ No newline at end of file +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/pgml-apps/pgml-chat/README.md b/pgml-apps/pgml-chat/README.md index a16737f5f..7ca5eb0d0 100644 --- a/pgml-apps/pgml-chat/README.md +++ b/pgml-apps/pgml-chat/README.md @@ -14,24 +14,24 @@ Before you begin, make sure you have the following: - Python version >=3.8 - OpenAI API key - Python 3.8+ -- Poetry + # Getting started -1. Clone this repository, start a poetry shell and install dependencies +1. Create a virtual environment and install `pgml-chat` using `pip`: ```bash -git clone https://github.com/postgresml/postgresml -cd postgresml/pgml-apps/pgml-chat -poetry shell -poetry install -pip install . +pip install pgml-chat ``` -2. Update environment variables in `.env` file +`pgml-chat` will be installed in your PATH. + +2. Download `.env.template` file from PostgresML Github repository. + ```bash -cp .env.template .env +wget https://github.com/postgresml/postgresml/blob/master/pgml-apps/pgml-chat/.env.template ``` +3. Copy the template file to `.env` -Update environment variables with your OpenAI API key and PostgresML database credentials. +4. Update environment variables with your OpenAI API key and PostgresML database credentials. ```bash OPENAI_API_KEY= DATABASE_URL= @@ -157,13 +157,32 @@ Once the discord app is running, you can interact with the chatbot on Discord as ![Discord Chatbot](./images/discord_screenshot.png) -## Options +# Developer Guide + +1. Clone this repository, start a poetry shell and install dependencies + +```bash +git clone https://github.com/postgresml/postgresml +cd postgresml/pgml-apps/pgml-chat +poetry shell +poetry install +pip install . +``` + +2. Create a .env file in the root directory of the project and add all the environment variables discussed in [Getting Started](#getting-started) section. +3. All the logic is in `pgml_chat/main.py` +4. Check the [roadmap](#roadmap) for features that you would like to work on. +5. If you are looking for features that are not included here, please open an issue and we will add it to the roadmap. + + + +# Options You can control the behavior of the chatbot by setting the following environment variables: - `SYSTEM_PROMPT`: This is the prompt that is used to initialize the chatbot. You can customize this prompt to change the behavior of the chatbot. For example, you can change the name of the chatbot or the location of the chatbot. - `BASE_PROMPT`: This is the prompt that is used to generate responses to user queries. You can customize this prompt to change the behavior of the chatbot. - `MODEL`: This is the open source embedding model used to generate embeddings for the documents. You can change this to use a different model. -## Roadmap +# Roadmap - ~~`hyerbot --chat_interface {cli, slack, discord}` that supports Slack, and Discord.~~ - Support for file formats like rst, html, pdf, docx, etc. - Support for open source models in addition to OpenAI for chat completion. diff --git a/pgml-apps/pgml-chat/pgml_chat/main.py b/pgml-apps/pgml-chat/pgml_chat/main.py index 56b2534f4..a43d0653d 100644 --- a/pgml-apps/pgml-chat/pgml_chat/main.py +++ b/pgml-apps/pgml-chat/pgml_chat/main.py @@ -258,14 +258,11 @@ async def get_prompt(user_input: str = ""): ) log.info(vector_results) context = "" + for result in vector_results: - if result[0] > 0.7: - context += result[1] + "\n" - if context: - print("Found relevant documentation.... ") - query = base_prompt.format(context=context, question=user_input) - else: - query = user_input + context += result[1] + "\n" + + query = base_prompt.format(context=context, question=user_input) return query diff --git a/pgml-apps/pgml-chat/pyproject.toml b/pgml-apps/pgml-chat/pyproject.toml index dd6becfc5..ae3254f3e 100644 --- a/pgml-apps/pgml-chat/pyproject.toml +++ b/pgml-apps/pgml-chat/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pgml-chat" -version = "0.1.0" +version = "0.1.1" description = "PostgresML bot builder for all your documentation" authors = ["PostgresML "] license = "MIT"