Nodejs a REST API is designed to provide users with an interactive chat interface where they can ask questions and receive responses generated by an AI model. The application utilizes OpenAI embeddings and Langchain to process the user's input and generate relevant responses based on the context of the conversation.
The backend of the application is built with Node.js,Express.js and uses Langchain's document loaders to load various file formats such as JSON, TXT, CSV, PDF, and DOCX. These documents are used to create a vector store, which is then used to retrieve relevant context for the user's query. The application uses OpenAI's language model to generate responses based on this context.
This REST API demonstrates how OpenAI embeddings and Langchain can be used to create a context-aware chatbot that can provide users with informative and relevant responses.
-
Clone the repository:
git clone https://github.com/RaheesAhmed/openai-embeddings-api.git
-
Install dependencies:
cd openai-embeddings-api npm install
-
Start the server:
npm start
-
Open your web browser and navigate to
http://localhost:3000
. -
Enter your message in the chat input field and press Enter.
-
The server will process your input using OpenAI embeddings and return a response.
Here are examples of how to make a request to the /chat
API endpoint.
URL: /chat
Method: POST
Content-Type: application/json
Request Body: JSON object
with a userInput key containing the user's question.
Response: JSON object
with a response key containing the chatbot's response.
Example Request and Response
{
"userInput": "What is the capital of France?"
}
Response:
{
"response": "The capital of France is Paris."
}
upload your files to the data
folder.
You can configure the prompt template and model by modifying the openai_embedings.js
file.