langchain-ai / opengpts
- четверг, 9 ноября 2023 г. в 00:00:08
This is an open source effort to create a similar experience as OpenAI's GPTs. This builds upon LangChain, LangServe and LangSmith 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).
Check out a simple hosted version here
1. Start the backend
Install requirements
cd backend
pip install -r requirements.txt
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.
export OPENAI_API_KEY="sk-..."
Set up LangSmith. This is optional, but it will help with debugging, logging, monitoring. Sign up at the link above and then set the relevant environment variables
export LANGCHAIN_TRACING_V2="true"
export LANGCHAIN_API_KEY=...
Start the backend server
langchain serve --port=8100
2. Start the frontend
cd frontend
yarn
yarn dev
Navigate to http://localhost:5173/ and enjoy!
As much as possible, we are striving for feature parity with OpenAI.
frontend
: Code for the frontendbackend
: Code for the backend
app
: LangServe code (for exposing APIs)packages
: Core logic
agent-executor
: Runtime for the agentgizmo-agent
: Configuration for the agentThe big appeal of OpenGPTs as compared to using OpenAI directly is that it is more customizable. Specifically, you can choose which language models to use as well as more easily add custom tools. You can also use the underlying APIs directly and build a custom UI yourself should you choose.
You can choose between different LLMs to use. This takes advantage of LangChain's many integrations. It is important to note that depending on which LLM you use, you may need to change how you are prompting it.
We have expose four agent types by default:
We will work to add more when we have confidence they can work well.
If you want to add your own LLM or agent configuration, or want to edit the existing ones, you can find them in backend/packages/gizmo-agent/gizmo_agent/agent_types
If using Claude 2, you will need to set the following environment variable:
export ANTHROPIC_API_KEY=sk-...
If using Azure OpenAI, you will need to set the following environment variables:
export OPENAI_API_BASE=...
export OPENAI_API_VERSION=...
export OPENAI_API_KEY=...
export OPENAI_DEPLOYMENT_NAME=...
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:
In practice, most teams we see define their own tools. This is easy to do within LangChain. See this guide for details on how to best do this.
1. Build the frontend
cd frontend
yarn
yarn build
2. Deploy to Google Cloud Run
You can deploy to GCP Cloud Run using the following command:
First create a .env.gcp.yaml
file with the contents from .env.gcp.yaml.example
and fill in the values. Then run:
gcloud run deploy opengpts --source . --port 8001 --env-vars-file .env.gcp.yaml --allow-unauthenticated --region us-central1 --min-instances 1