Skip to content

Commit

Permalink
Harrison/stateful (#39)
Browse files Browse the repository at this point in the history
* start statefullness

* cr

* cr

* cr

* Fix

* with_types

* cr

* Fix uuids

* expose session_id

* cr

* cr

* Add thread and assistant storage endpoints

* Add deps

* Add message list to output value of list_threads

* Return created objects

* Frontend: store bots in backend

* Update api

* Finish frontend

* Finish frontend

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* secrets

* Update deps

* Fix gpt4

* fe: sort chats and configs

* Lint

* Lint

* Comment

* Storage helper funcs

* Fix chat order

* Add loading state for thread history

* Add more loading states

* Add research preview banner

* Add scoping on user_id

* Lint

* Fix chat history

* Finish file upload api and frontend

* Clear files when switcing configs

* Make assistants shareable

* Some work for feedback buttons

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* x

* Add redis service to CI (#24)

Add redis service to CI (still not used by tests)

* Set up tests with redis (#26)

- Add testing with redis
- Fix bug in ingest runnable
- Add RunnableBindingBase to this repo until it's merged and released via langchain

* x (#27)

* x

* cr

* cr

* cr

* cr

* Make tests work

* Format, lint
* Add new env varaibles to make file
* Comment out code that's not been released on langchain

* Fix missing deps

* Display bot name

* Fix stream state not resetting when switching threads

* Display error message

* Display file errors, accummulate files

* Fix bottom padding, move public link button to top

* Add icon to view config for bot used in current chat

* Add tool markdown descriptions

* Add feedback buttons

* Add tests for endpoints involving storage on server (#32)

Add tests for endpoints involving storage

* x

* x (#34)

* Add some validation to endpoints (#35)

Add a bit more validation to endpoints

* Use models with longer context windows

* Update gcp env file

* Remove dupe

* Use disabled var

* Disable autofocus on new bot name

* Add libmagic

* Lint

* Better public bot share link

* Add feature public bots

* Localize access to REDIS_URL (#36)

* Localize a bit access to REDIS_URL

* cr

---------

Co-authored-by: Nuno Campos <[email protected]>
Co-authored-by: Eugene Yurtsev <[email protected]>
  • Loading branch information
3 people authored Nov 13, 2023
1 parent 40a3099 commit fdfda6f
Show file tree
Hide file tree
Showing 67 changed files with 9,073 additions and 607 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY=placeholder
ANTHROPIC_API_KEY=placeholder
11 changes: 11 additions & 0 deletions .env.gcp.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,14 @@ OPENAI_API_KEY: your_secret_key_here
LANGCHAIN_TRACING_V2: "true"
LANGCHAIN_PROJECT: langserve-launch-example
LANGCHAIN_API_KEY: your_secret_key_here
REDIS_URL: your_secret_here
TAVILY_API_KEY: your_secret_here
FIREWORKS_API_KEY: your_secret_here
YDC_API_KEY: your_secret_here
AWS_ACCESS_KEY_ID: your_secret_here
AWS_SECRET_ACCESS_KEY: your_secret_here
AZURE_OPENAI_DEPLOYMENT_NAME: your_secret_here
AZURE_OPENAI_API_BASE: your_secret_here
AZURE_OPENAI_API_VERSION: your_secret_here
AZURE_OPENAI_API_KEY: your_secret_here
KAY_API_KEY: your_secret_here
57 changes: 0 additions & 57 deletions .github/workflows/_test.yml

This file was deleted.

66 changes: 44 additions & 22 deletions .github/workflows/langserve_ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
paths:
- '.github/actions/poetry_setup/action.yml'
- '.github/workflows/_lint.yml'
- '.github/workflows/_test.yml'
- '.github/workflows/langserve_ci.yml'
- 'backend/**'
workflow_dispatch: # Allows to trigger the workflow manually in GitHub UI
Expand All @@ -25,14 +24,14 @@ concurrency:

env:
POETRY_VERSION: "1.5.1"
WORKDIR: "backend/"
WORKDIR: "./backend"

jobs:
lint:
uses:
./.github/workflows/_lint.yml
with:
working-directory: ${{ env.WORKDIR }}
working-directory: "./backend"
secrets: inherit

test:
Expand All @@ -49,34 +48,57 @@ jobs:
- "3.10"
- "3.11"
name: Python ${{ matrix.python-version }} tests
services:
# Label used to access the service container
redis:
image: redislabs/redisearch:latest
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- "6379:6379"
steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }} + Poetry ${{ env.POETRY_VERSION }}
uses: "./.github/actions/poetry_setup"
with:
python-version: ${{ matrix.python-version }}
poetry-version: ${{ env.POETRY_VERSION }}
working-directory: .
cache-key: langserve-all

- name: Install dependencies
shell: bash
- name: install redis
run: |
echo "Running extended tests, installing dependencies with poetry..."
poetry install --with test,lint --extras all
- name: Run tests
run: make test

- name: Ensure the tests did not create any additional files
shell: bash
pip install redis
- name: check redis is running
run: |
set -eu
python -c "import redis; redis.Redis(host='localhost', port=6379).ping()"
STATUS="$(git status)"
echo "$STATUS"
# grep will exit non-zero if the target message isn't found,
# and `set -e` above will cause the step to fail.
echo "$STATUS" | grep 'nothing to commit, working tree clean'
# - name: Install dependencies
# shell: bash
# run: |
# echo "Running tests, installing dependencies with poetry..."
# poetry install --with test,lint
#
# - name: Run tests
# run: make test
# env:
# # Adding a DB number to match unit tests
# # Unit tests use DB 3, so user doesn't accidentally wipe their data
# # if they run the tests against a real redis instance.
# # Need to follow up and swap out default port numbers and add `test`
# # password
# REDIS_URL: "redis://redis:6379/0"
# - name: Ensure the tests did not create any additional files
# shell: bash
# run: |
# set -eu
#
# STATUS="$(git status)"
# echo "$STATUS"
#
# # grep will exit non-zero if the target message isn't found,
# # and `set -e` above will cause the step to fail.
# echo "$STATUS" | grep 'nothing to commit, working tree clean'
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM python:3.11-slim
FROM python:3.11

RUN apt-get install -y libmagic1

WORKDIR /backend

Expand Down
144 changes: 130 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# OpenGPTs

This is an open source effort to create a similar experience as OpenAI's GPTs.
This builds upon [LangChain](https://github.com/langchain-ai/langchain), [LangServe](https://github.com/langchain-ai/langserve) and [LangSmith](https://smith.langchain.com/)
This gives you more control over the LLM you use (choose between the 60+ that LangChain offers),
the prompts you use (use LangSmith to debug those), and the tools you give it (choose from LangChain's 100+ tools, or easily write your own).
This is an open source effort to create a similar experience to OpenAI's GPTs.
It builds upon [LangChain](https://github.com/langchain-ai/langchain), [LangServe](https://github.com/langchain-ai/langserve) and [LangSmith](https://smith.langchain.com/).
OpenGPTs gives you more control, allowing you to configure:

- The LLM you use (choose between the 60+ that LangChain offers)
- The prompts you use (use LangSmith to debug those)
- The tools you give it (choose from LangChain's 100+ tools, or easily write your own)
- The vector database you use (choose from LangChain's 60+ vector database integrations)
- The retrieval algorithm you use
- The chat history database you use

<p align="center">
<img alt="Configure" src="_static/configure.png" width="49%" />
Expand All @@ -14,22 +20,53 @@ Check out a simple hosted version [here](https://opengpts-example-vz4y4ooboq-uc.

## Quickstart

**1. Start the backend**
### Start the backend

Install requirements
**Install requirements**

```shell
cd backend
pip install -r requirements.txt
```

**Set up persistence layer**

The backed by default uses Redis for saving agent configurations and chat message history.
In order to you use this, you need to a `REDIS_URL` variable.

```shell
export REDIS_URL=...
```

**Set up vector database**

The backend by default also uses Redis as a vector database,
although you can easily switch this out to use any of the 50+ vector databases in LangChain.
If you are using Redis as a vectorstore, the above environment variable should work
(assuming you've enabled `redissearch`)

**Set up language models**

By default, this uses OpenAI, but there are also options for Azure OpenAI and Anthropic.
If you are using those, you may need to set different environment variables.

```shell
export OPENAI_API_KEY="sk-..."
```

Other language models can be used, and in order to use them you will need to set more environment variables.
See the section below on `LLMs` for how to configure Azure OpenAI, Anthropic, and Amazon Bedrock.

**Set up tools**
By default this uses a lot of tools.
Some of these require additional environment variables.
You do not need to use any of these tools, and the environment variables are not required to spin up the app
(they are only required if that tool is called).

For a full list of environment variables to enable, see the `Tools` section below.

**Set up monitoring**

Set up [LangSmith](https://smith.langchain.com/).
This is optional, but it will help with debugging, logging, monitoring.
Sign up at the link above and then set the relevant environment variables
Expand Down Expand Up @@ -124,24 +161,103 @@ export ANTHROPIC_API_KEY=sk-...
If using Azure OpenAI, you will need to set the following environment variables:

```shell
export OPENAI_API_BASE=...
export OPENAI_API_VERSION=...
export OPENAI_API_KEY=...
export OPENAI_DEPLOYMENT_NAME=...
export AZURE_OPENAI_API_BASE=...
export AZURE_OPENAI_API_VERSION=...
export AZURE_OPENAI_API_KEY=...
export AZURE_OPENAI_DEPLOYMENT_NAME=...
```

#### Amazon Bedrock

If using Amazon Bedrock, you either have valid credentials in `~/.aws/credentials` or set the following environment variables:

```shell
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
```

### Tools

One of the big benefits of having this be open source is that you can more easily add tools (directly in Python).
We have enabled two tools by default:

- DuckDuckGo Search
- Python REPL (NOTE: this executes Python code directly in your environment and may not be safe)

In practice, most teams we see define their own tools.
This is easy to do within LangChain.
See [this guide](https://python.langchain.com/docs/modules/agents/tools/custom_tools) for details on how to best do this.

If you want to use some preconfigured tools, these include:

**DuckDuckGo Search**

Search the web with [DuckDuckGo](https://pypi.org/project/duckduckgo-search/). Does not require any API keys.

**Tavily Search**

Uses the [Tavily](https://app.tavily.com/) search engine. Requires setting an environment variable:

```shell
export TAVILY_API_KEY=tvly-...
```

Sign up for an API key [here](https://app.tavily.com/).

**Tavily Search (Answer Only)**

Uses the [Tavily](https://app.tavily.com/) search engine.
This returns only the answer, no supporting evidence.
Good when you need a short response (small context windows).
Requires setting an environment variable:

```shell
export TAVILY_API_KEY=tvly-...
```

Sign up for an API key [here](https://app.tavily.com/).

**You.com Search**

Uses [You.com](https://you.com/) search, optimized responses for LLMs.
Requires setting an environment variable:

```shell
export YDC_API_KEY=...
```

Sign up for an API key [here](https://you.com/)

**SEC Filings (Kay.ai)**

Searches through SEC filings using [Kay.ai](https://www.kay.ai/).
Requires setting an environment variable:

```shell
export KAY_API_KEY=...
```

Sign up for an API key [here](https://www.kay.ai/)

**Press Releases (Kay.ai)**

Searches through press releases using [Kay.ai](https://www.kay.ai/).
Requires setting an environment variable:

```shell
export KAY_API_KEY=...
```

Sign up for an API key [here](https://www.kay.ai/)

**Arxiv**

Searches [Arxiv](https://arxiv.org/). Does not require any API keys.

**PubMed**

Searches [PubMed](https://pubmed.ncbi.nlm.nih.gov/). Does not require any API keys.

**Wikipedia**

Searches [Wikipedia](https://pypi.org/project/wikipedia/). Does not require any API keys.

## Deployment

**1. Build the frontend**
Expand Down
2 changes: 2 additions & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
__pycache__/
.envrc
.env
*.swp
Loading

0 comments on commit fdfda6f

Please sign in to comment.