AI assistant (RAG) based on Jonathan Scholtes's article
Service for booking cruises with the help of AI assistant (LangChain & FastAPI & MongoDB+ChromaDB)
Instructions:
- OpenAI and LangChain(LangSmith) API keys required to run the service.
- Files "ships.json" and "destinations.json" contain "cruise data" which will be used to build cruise itineraries (check "ships_destinations" dir).
- For MongoDB the service uses a Docker image without AVX support (switch to appropriate if needed).
- Instead of using MongoDB Atlas Vector Search the service uses ChromaDB for vectorized documents storage.
- As for UI it is possible to use FastAPI's build-in SwaggerUI page to make HTTP requests.
- For WebSocket requests it is possible to use "Web Socket Client" extension for Google Chrome browser.
- Service is not fully dockerized yet: FastAPI service have to be started separately.
- Create and fill-in the .env file in base directory (follow the 'env.example' file).
- Start docker network with command:
CURRENT_UID=0:0 docker-compose -f docker-compose.yml up - After MongoDB and RabbitMQ containers are up and ready to accept connections
then start FastAPI service with command: python3 -m src.main - In web-browser open page: "http://127.0.0.1:8088/docs" and in section "Data Storage" upload "cruise_data"
via sending POST request on:
"http://127.0.0.1:8088/storage/cruises-upload" including ships.json and destinations.json files - After that all the "cruise data" is loaded into MongoDB and ChromaDB databases
- Service can be used via HTTP protocol or WebSocket protocol:
HTTP: sending POST requests to "http://127.0.0.1:8088/prompts/travel-agent"
WebSocket: connecting to "ws://localhost:8088/prompts/travel-chat" - Sending HTTP POST request require to send unique "session_id" along with "input" in body of request.
The "session_id" can be obtained via HTTP GET request to "http://127.0.0.1:8088/prompts/session-id" - Connecting via WebSocket protocol replies with "Session_id" header holding "session_id string".
It must be sent along with "input" data in the body of every ws-request to the service - The "session_id" helps service to identify dialog and keeps track of it's history.
That is why it's recommended to store it on the "client" till the end of the dialog - If WebSocket connection was closed for any reason it is possible to restore it by adding
query param to url "ws://localhost:8088/prompts/travel-chat?session_id=XXXXXXXXX" during reconnect. - History of every dialog will be stored in "history" collection of MongoDB.
- All requests can be monitored in LangSmith service.
Thanks for visiting!
And Big Kudos to Jonathan Scholtes and his blog for helping to implement first RAG app.
It's working!🚀