Connect Your Custom LangChain to Slack Seamlessly
Integrating your LangChain app with Slack doesn't have to be complicated. With LangServe and Runbear, you can set up your custom LLM in just a few easy steps. Here's how to get started.
Step 1: Prepare Your LangChain Serving Endpoint
First, create a LangChain serving endpoint using LangServe. Here's a simple code snippet that sets up a web server with FastAPI, ready to handle requests:
import os
from typing import Any, Dict
from fastapi import FastAPI, HTTPException, Request
from langchain.chat_models import ChatOpenAI
from langserve import add_routes
app = FastAPI()
def verify_secret_key(config: Dict[str, Any], req: Request) -> Dict[str, Any]:
if req.headers.get("x-secret-key") != os.environ.get("SECRET_KEY"):
raise HTTPException(status_code=401, detail="Incorrect secret key")
return config
add_routes(
app,
ChatOpenAI(),
path="/chat",
per_req_config_modifier=verify_secret_key,
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=int(
os.getenv("PORT", default=8000)))You need to set the OPENAI_API_KEY environment variable to use the OpenAI API. You can create your API key from OpenAI API keys. Also, set the SECRET_KEY environment variable to secure your endpoint. If you set SECRET_KEY, you must pass the x-secret-key header with the same value to your endpoint.
If you wish to directly deploy a template app, you can proceed to Step 5.
Step 2: Test Your LangChain App Locally with Ngrok
Before deploying your app, you might want to test it locally. Ngrok is a tool that creates a secure tunnel to your localhost, making it accessible from the internet without deployment. Here’s how to use it:
- Download and install ngrok from ngrok's website.
- Once installed, open a terminal and run
ngrok http 8000. This will expose port 8000 (where your FastAPI app runs; you can change this port if necessary) to the internet. - Copy the forwarding URL provided by ngrok. This URL is now the public endpoint for your local LangServe app.

