{"id":13456939,"url":"https://github.com/langchain-ai/opengpts","last_synced_at":"2025-05-14T04:07:36.223Z","repository":{"id":205861642,"uuid":"714388063","full_name":"langchain-ai/opengpts","owner":"langchain-ai","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-06T14:44:52.000Z","size":3418,"stargazers_count":6467,"open_issues_count":130,"forks_count":858,"subscribers_count":67,"default_branch":"main","last_synced_at":"2024-10-29T15:34:25.084Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rich Text Format","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/langchain-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-04T18:58:15.000Z","updated_at":"2024-10-29T06:32:22.000Z","dependencies_parsed_at":"2024-02-28T17:27:39.362Z","dependency_job_id":"2345b2b0-55e8-4fe1-8cab-7c1c505e813c","html_url":"https://github.com/langchain-ai/opengpts","commit_stats":null,"previous_names":["langchain-ai/opengpts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Fopengpts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Fopengpts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Fopengpts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/langchain-ai%2Fopengpts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/langchain-ai","download_url":"https://codeload.github.com/langchain-ai/opengpts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254069216,"owners_count":22009511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:01:30.515Z","updated_at":"2025-05-14T04:07:36.180Z","avatar_url":"https://github.com/langchain-ai.png","language":"Rich Text Format","funding_links":[],"categories":["Rich Text Format","**Section 4** : LangChain Features, Usage, and Comparisons","GPTs 开源项目","A01_文本生成_文本对话","Project","Learning","Repos","🟢 Official LangGraph Projects 🦜","AI Agent Frameworks \u0026 SDKs","📦 Legacy \u0026 Inactive Projects","Agentic Systems"],"sub_categories":["**LangChain features and related libraries**","大语言对话模型及数据","Repositories","🟩 Apps \u0026 Agents 📱","Cognitive Architecture Frameworks"],"readme":"# OpenGPTs\n\nThis is an open source effort to create a similar experience to OpenAI's GPTs and Assistants API.\nIt is powered by [LangGraph](https://github.com/langchain-ai/langgraph) - a framework for creating agent runtimes.\nIt also builds upon [LangChain](https://github.com/langchain-ai/langchain), [LangServe](https://github.com/langchain-ai/langserve) and [LangSmith](https://smith.langchain.com/).\nOpenGPTs gives you more control, allowing you to configure:\n\n- The LLM you use (choose between the 60+ that LangChain offers)\n- The prompts you use (use LangSmith to debug those)\n- The tools you give it (choose from LangChain's 100+ tools, or easily write your own)\n- The vector database you use (choose from LangChain's 60+ vector database integrations)\n- The retrieval algorithm you use\n- The chat history database you use\n\nMost importantly, it gives you full control over the **cognitive architecture** of your application.\nCurrently, there are three different architectures implemented:\n\n- Assistant\n- RAG\n- Chatbot\n\nSee below for more details on those.\nBecause this is open source, if you do not like those architectures or want to modify them, you can easily do that!\n\n\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"Configure\" src=\"_static/configure.png\" width=\"49%\" /\u003e\n    \u003cimg alt=\"Chat\" src=\"_static/chat.png\" width=\"49%\" /\u003e\n\u003c/p\u003e\n\n**Key Links**\n\n- [GPTs: a simple hosted version](https://opengpts-example-vz4y4ooboq-uc.a.run.app/)\n- [Assistants API: a getting started guide](API.md)\n- [Auth: a guide for production](auth.md)\n\n## Quickstart with Docker\n\nThis project supports a Docker-based setup, streamlining installation and execution. It automatically builds images for \nthe frontend and backend and sets up Postgres using docker-compose.\n\n\n1. **Prerequisites:**  \n    Ensure you have Docker and docker-compose installed on your system.\n\n\n2. **Clone the Repository:**  \n   Obtain the project files by cloning the repository.\n\n   ```\n   git clone https://github.com/langchain-ai/opengpts.git\n   cd opengpts\n   ```\n\n3. **Set Up Environment Variables:**  \n   Create a `.env` file in the root directory of the project by copying `.env.example` as a template, and add the \n   following environment variables:\n   ```shell\n   # At least one language model API key is required\n   OPENAI_API_KEY=sk-...\n   # LANGCHAIN_TRACING_V2=true\n   # LANGCHAIN_API_KEY=...\n   \n   # Setup for Postgres. Docker compose will use these values to set up the database.\n   POSTGRES_PORT=5432\n   POSTGRES_DB=opengpts\n   POSTGRES_USER=postgres\n   POSTGRES_PASSWORD=...\n   ```\n\n   Replace `sk-...` with your OpenAI API key and `...` with your LangChain API key.\n\n\n4. **Run with Docker Compose:**  \n   In the root directory of the project, execute:\n\n   ```\n   docker compose up\n   ```\n\n   This command builds the Docker images for the frontend and backend from their respective Dockerfiles and starts all \n   necessary services, including Postgres.\n\n5. **Access the Application:**  \n   With the services running, access the frontend at [http://localhost:5173](http://localhost:5173), substituting `5173` with the \n   designated port number.\n\n\n6. **Rebuilding After Changes:**  \n   If you make changes to either the frontend or backend, rebuild the Docker images to reflect these changes. Run:\n   ```\n   docker compose up --build\n   ```\n   This command rebuilds the images with your latest changes and restarts the services.\n\n\n## Quickstart without Docker\n\n**Prerequisites**\nThe following instructions assume you have Python 3.11+ installed on your system. We strongly recommend using a virtual \nenvironment to manage dependencies.\n\nFor example, if you are using `pyenv`, you can create a new virtual environment with:\n```shell\npyenv install 3.11\npyenv virtualenv 3.11 opengpts\npyenv activate opengpts\n```\n\nOnce your Python environment is set up, you can install the project dependencies:\n\nThe backend service uses [poetry](https://python-poetry.org/docs/#installation) to manage dependencies.\n\n```shell \npip install poetry\npip install langchain-community\n```\n\n**Install Postgres and the Postgres Vector Extension**\n```\nbrew install postgresql pgvector\nbrew services start postgresql\n```\n\n**Configure persistence layer**\n\nThe backend uses Postgres for saving agent configurations and chat message history.\nIn order to use this, you need to set the following environment variables:\n\n```shell\nexport POSTGRES_HOST=localhost\nexport POSTGRES_PORT=5432\nexport POSTGRES_DB=opengpts\nexport POSTGRES_USER=postgres\nexport POSTGRES_PASSWORD=...\n```\n\n**Create the database**\n```shell\ncreatedb opengpts\n```\n\n**Connect to the database and create the `postgres` role**\n```shell\npsql -d opengpts\n```\n\n```sql\nCREATE ROLE postgres WITH LOGIN SUPERUSER CREATEDB CREATEROLE;\n```\n\n**Install Golang Migrate**\n\nDatabase migrations are managed with [golang-migrate](https://github.com/golang-migrate/migrate). \n\nOn MacOS, you can install it with `brew install golang-migrate`. Instructions for other OSs or the Golang toolchain, \ncan be found [here](https://github.com/golang-migrate/migrate/blob/master/cmd/migrate/README.md#installation).\n\nOnce `golang-migrate` is installed, you can run all the migrations with:\n```shell\nmake migrate\n```\n\nThis will enable the backend to use Postgres as a vector database and create the initial tables.\n\n\n**Install backend dependencies**\n```shell\ncd backend\npoetry install\n```\n\n\n**Alternate vector databases**\n\nThe instructions above use Postgres as a vector database,\nalthough you can easily switch this out to use any of the 50+ vector databases in LangChain.\n\n**Set up language models**\n\nBy default, this uses OpenAI, but there are also options for Azure OpenAI and Anthropic.\nIf you are using those, you may need to set different environment variables.\n\n```shell\nexport OPENAI_API_KEY=\"sk-...\"\n```\n\nOther language models can be used, and in order to use them you will need to set more environment variables.\nSee the section below on `LLMs` for how to configure Azure OpenAI, Anthropic, and Amazon Bedrock.\n\n**Set up tools**\n\nBy default this uses a lot of tools.\nSome of these require additional environment variables.\nYou do not need to use any of these tools, and the environment variables are not required to spin up the app\n(they are only required if that tool is called).\n\nFor a full list of environment variables to enable, see the `Tools` section below.\n\n**Set up monitoring**\n\nSet up [LangSmith](https://smith.langchain.com/).\nThis is optional, but it will help with debugging, logging, monitoring.\nSign up at the link above and then set the relevant environment variables\n\n```shell\nexport LANGCHAIN_TRACING_V2=\"true\"\nexport LANGCHAIN_API_KEY=...\n```\n\nStart the backend server\n\n```shell\nmake start\n```\n\n### Start the frontend\n\n```shell\ncd frontend\nnpm install\nnpm run dev\n```\n\nNavigate to [http://localhost:5173/](http://localhost:5173/) and enjoy!\n\n## Migrating data from Redis to Postgres\n\nRefer to this [guide](tools/redis_to_postgres/README.md) for migrating data from Redis to Postgres.\n\n## Breaking Changes\n\n### Migration 5 - Checkpoint Management Update\nVersion 5 of the database migrations introduces a significant change to how thread checkpoints are managed:\n- Transitions from a pickle-based checkpointing system to a new multi-table checkpoint management system (breaking change)\n- Aligns with LangGraph's new checkpoint architecture for better state management and persistence\n- **Important**: Historical threads/checkpoints (created before this migration) will not be accessible in the UI\n- Previous checkpoint data is preserved in the `old_checkpoints` table but cannot be accessed by the new system\n- This architectural change improves how thread state is stored and managed, enabling more reliable state persistence in LangGraph-based agents.\n\n## Features\n\nAs much as possible, we are striving for feature parity with OpenAI.\n\n- [x] Sandbox - Provides an environment to import, test, and modify existing chatbots.\n  - The chatbots used are all in code, so are easily editable\n- [x] Custom Actions - Define additional functionality for your chatbot using OpenAPI specifications\n  - Supported by adding tools\n- [x] Knowledge Files - attach additional files that your chatbot can reference\n  - Upload files from the UI or API, used by Retrieval tool\n- [x] Tools - Provides basic tools for web browsing, image creation, etc.\n  - Basic DuckDuckGo and PythonREPL tools enabled by default\n  - Image creation coming soon\n- [x] Analytics - View and analyze chatbot usage data\n  - Use LangSmith for this\n- [x] Drafts - Save and share drafts of chatbots you're creating\n  - Supports saving of configurations\n- [x] Publishing - publicly distribute your completed chatbot\n  - Can do by deploying via LangServe\n- [x] Sharing - Set up and manage chatbot sharing\n  - Can do by deploying via LangServe\n- [ ] Marketplace - Search and deploy chatbots created by other users\n  - Coming soon\n\n## Repo Structure\n\n- `frontend`: Code for the frontend\n- `backend`: Code for the backend\n  - `app`: LangServe code (for exposing APIs)\n  - `packages`: Core logic\n    - `agent-executor`: Runtime for the agent\n    - `gizmo-agent`: Configuration for the agent\n\n## Customization\n\nThe big appeal of OpenGPTs as compared to using OpenAI directly is that it is more customizable.\nSpecifically, you can choose which language models to use as well as more easily add custom tools.\nYou can also use the underlying APIs directly and build a custom UI yourself should you choose.\n\n### Cognitive Architecture\n\nThis refers to the logic of how the GPT works.\nThere are currently three different architectures supported, but because they are all written in LangGraph, it is very \neasy to modify them or add your own.\n\nThe three different architectures supported are assistants, RAG, and chatbots.\n\n**Assistants**\n\nAssistants can be equipped with arbitrary amount of tools and use an LLM to decide when to use them. This makes them \nthe most flexible choice, but they work well with fewer models and can be less reliable.\n\nWhen creating an assistant, you specify a few things.\n\nFirst, you choose the language model to use. Only a few language models can be used reliably well: GPT-3.5, GPT-4, \nClaude, and Gemini.\n\nSecond, you choose the tools to use. These can be predefined tools OR a retriever constructed from uploaded files. You \ncan choose however many you want.\n\nThe cognitive architecture can then be thought of as a loop. First, the LLM is called to determine what (if any) \nactions to take. If it decides to take actions, then those actions are executed and it loops back. If no actions are \ndecided to take, then the response of the LLM is the final response, and it finishes the loop.\n\n![](_static/agent.png)\n\nThis can be a really powerful and flexible architecture. This is probably closest to how us humans operate. However, \nthese also can be not super reliable, and generally only work with the more performant models (and even then they can \nmess up). Therefore, we introduced a few simpler architecures.\n\nAssistants are implemented with [LangGraph](https://github.com/langchain-ai/langgraph) `MessageGraph`. A `MessageGraph` is a graph that models its state as a `list` of messages.\n\n**RAGBot**\n\nOne of the big use cases of the GPT store is uploading files and giving the bot knowledge of those files. What would it \nmean to make an architecture more focused on that use case?\n\nWe added RAGBot - a retrieval-focused GPT with a straightforward architecture. First, a set of documents are retrieved. \nThen, those documents are passed in the system message to a separate call to the language model so it can respond.\n\nCompared to assistants, it is more structured (but less powerful). It ALWAYS looks up something - which is good if you \nknow you want to look things up, but potentially wasteful if the user is just trying to have a normal conversation. \nAlso importantly, this only looks up things once - so if it doesn't find the right results then it will yield a bad \nresult (compared to an assistant, which could  decide to look things up again).\n\n![](_static/rag.png)\n\nDespite this being a more simple architecture, it is good for a few reasons. First, because it is simpler it can work \npretty well with a wider variety of models (including lots of open source models). Second, if you have a use case where \nyou don't NEED the flexibility of an assistant (eg you know users will be looking up information every time) then it \ncan be more focused. And third, compared to the final architecture below it can use external knowledge.\n\nRAGBot is implemented with [LangGraph](https://github.com/langchain-ai/langgraph) `StateGraph`. A `StateGraph` is a generalized graph that can model arbitrary state (i.e. `dict`), not just a `list` of messages.\n\n**ChatBot**\n\nThe final architecture is dead simple - just a call to a language model, parameterized by a system message. This allows \nthe GPT to take on different personas and characters. This is clearly far less powerful than Assistants or RAGBots \n(which have access to external sources of data/computation) - but it's still valuable! A lot of popular GPTs are just \nsystem messages at the end of the day, and CharacterAI is crushing it despite largely just being system messages as \nwell.\n\n![](_static/chatbot.png)\n\nChatBot is implemented with [LangGraph](https://github.com/langchain-ai/langgraph) `StateGraph`. A `StateGraph` is a generalized graph that can model arbitrary state (i.e. `dict`), not just a `list` of messages.\n\n### LLMs\n\nYou can choose between different LLMs to use.\nThis takes advantage of LangChain's many integrations.\nIt is important to note that depending on which LLM you use, you may need to change how you are prompting it.\n\nWe have exposed four agent types by default:\n\n- \"GPT 3.5 Turbo\"\n- \"GPT 4\"\n- \"Azure OpenAI\"\n- \"Claude 2\"\n\nWe will work to add more when we have confidence they can work well.\n\nIf you want to add your own LLM or agent configuration, or want to edit the existing ones, you can find them in \n`backend/app/agent_types`\n\n#### Claude 2\n\nIf using Claude 2, you will need to set the following environment variable:\n\n```shell\nexport ANTHROPIC_API_KEY=sk-...\n```\n\n#### Azure OpenAI\n\nIf using Azure OpenAI, you will need to set the following environment variables:\n\n```shell\nexport AZURE_OPENAI_API_BASE=...\nexport AZURE_OPENAI_API_VERSION=...\nexport AZURE_OPENAI_API_KEY=...\nexport AZURE_OPENAI_DEPLOYMENT_NAME=...\n```\n\n#### Amazon Bedrock\n\nIf using Amazon Bedrock, you either have valid credentials in `~/.aws/credentials` or set the following environment \nvariables:\n\n```shell\nexport AWS_ACCESS_KEY_ID=...\nexport AWS_SECRET_ACCESS_KEY=...\n```\n\n### Tools\n\nOne of the big benefits of having this be open source is that you can more easily add tools (directly in Python).\n\nIn practice, most teams we see define their own tools.\nThis is easy to do within LangChain.\nSee [this guide](https://python.langchain.com/docs/modules/agents/tools/custom_tools) for details on how to best do \nthis.\n\nIf you want to use some preconfigured tools, these include:\n\n**_Sema4.ai Action Server_**\n\nRun AI Python based actions with [Sema4.ai Action Server](https://github.com/Sema4AI/actions).\nDoes not require a service API key, but it requires the credentials for a running Action Server instance to be defined.\nThese you set while creating an assistant.\n\n**_Connery Actions_**\n\nConnect OpenGPTs to the real world with [Connery](https://github.com/connery-io/connery).\n\nRequires setting an environment variable, which you get during the [Connery Runner setup](https://docs.connery.io/docs/runner/quick-start/):\n\n```shell\nCONNERY_RUNNER_URL=https://your-personal-connery-runner-url\nCONNERY_RUNNER_API_KEY=...\n```\n\n**DuckDuckGo Search**\n\nSearch the web with [DuckDuckGo](https://pypi.org/project/duckduckgo-search/). Does not require any API keys.\n\n**Tavily Search**\n\nUses the [Tavily](https://app.tavily.com/) search engine. Requires setting an environment variable:\n\n```shell\nexport TAVILY_API_KEY=tvly-...\n```\n\nSign up for an API key [here](https://app.tavily.com/).\n\n**Tavily Search (Answer Only)**\n\nUses the [Tavily](https://app.tavily.com/) search engine.\nThis returns only the answer, no supporting evidence.\nGood when you need a short response (small context windows).\nRequires setting an environment variable:\n\n```shell\nexport TAVILY_API_KEY=tvly-...\n```\n\nSign up for an API key [here](https://app.tavily.com/).\n\n**You.com Search**\n\nUses [You.com](https://you.com/) search, optimized responses for LLMs.\nRequires setting an environment variable:\n\n```shell\nexport YDC_API_KEY=...\n```\n\nSign up for an API key [here](https://you.com/)\n\n**SEC Filings (Kay.ai)**\n\nSearches through SEC filings using [Kay.ai](https://www.kay.ai/).\nRequires setting an environment variable:\n\n```shell\nexport KAY_API_KEY=...\n```\n\nSign up for an API key [here](https://www.kay.ai/)\n\n**Press Releases (Kay.ai)**\n\nSearches through press releases using [Kay.ai](https://www.kay.ai/).\nRequires setting an environment variable:\n\n```shell\nexport KAY_API_KEY=...\n```\n\nSign up for an API key [here](https://www.kay.ai/)\n\n**Arxiv**\n\nSearches [Arxiv](https://arxiv.org/). Does not require any API keys.\n\n**PubMed**\n\nSearches [PubMed](https://pubmed.ncbi.nlm.nih.gov/). Does not require any API keys.\n\n**Wikipedia**\n\nSearches [Wikipedia](https://pypi.org/project/wikipedia/). Does not require any API keys.\n\n## Deployment\n\n### Deploy via Cloud Run\n\n**1. Build the frontend**\n\n```shell\ncd frontend\nyarn\nyarn build\n```\n\n**2. Deploy to Google Cloud Run**\n\nYou can deploy to GCP Cloud Run using the following command:\n\nFirst create a `.env.gcp.yaml` file with the contents from `.env.gcp.yaml.example` and fill in the values. Then run:\n\n```shell\ngcloud run deploy opengpts --source . --port 8000 --env-vars-file .env.gcp.yaml --allow-unauthenticated \\\n--region us-central1 --min-instances 1\n```\n\n### Deploy in Kubernetes\n\nWe have a Helm chart for deploying the backend to Kubernetes. You can find more information here: \n[README.md](https://github.com/langchain-ai/helm/tree/main/charts/open-gpts)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flangchain-ai%2Fopengpts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flangchain-ai%2Fopengpts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flangchain-ai%2Fopengpts/lists"}