This is a minimal viable example of a Chatbot based on the new Assistant's API of OpenAI utilizing LangchainJS abstractions.
The prompt of the Chatbot is to only answer questions about the content of a given document. I uploaded the LangchainJS Documentation for OpenAI Assistant to the Knowledge Base. This is far from perfect but it works well to illustrate the concept of using OpenAI's native RAG.
The JavaScript framework of choice is SvelteKit, however the code should be easily transferable to other frameworks (most is just simple JavaScript / Node.js code ).
The Template is held purposefully simple in its implementation while still beeing fully functional.
It is best used as reference to learn the basics of how the new Assistant API works and how to use it with LangchainJS.
Caution: This is by no means a finished product. This API is still in beta and the integrated RAG from uploaded Files is average at best.
- Official Langchain Assistant Documentation: https://js.langchain.com/docs/modules/agents/agent_types/openai_assistant
- Official OpenAI Assistant Documentation: https://platform.openai.com/docs/assistants/overview
- Build a QA Chatbot with RAG - Step by step tutorial: https://simon-prammer.vercel.app/blog/post/easiest-qa-chatbot
- Easy Chatbot - Introduction to the basics: https://simon-prammer.vercel.app/blog/post/sveltekit-langchain
This app features:
- Endpoint to create an Assistant with Knowledge Base from a Document
- Endpoint to chat with that Assistant (can pass in assistantId to prevent creating over and over again)
- Minimalistic Chat interface
In the current configuration, you need:
- An OpenAI API Key
pnpm i
Run the development server at http://localhost:5173/.
pnpm run dev
If you build your own example, note that this repos uses a modified vite.config.ts which is necessary to use the environment variables in local development without explicitly declaring them in the code. This is not necessary in production.