This Node.js application integrates the OpenAI Assistant's API with an Express server. It allows users to interact with an OpenAI-powered chatbot through a RESTful API.
- Integration with OpenAI API.
- Express server setup with middleware.
- Endpoint for chat interactions.
- Node.js installed.
- An OpenAI API key.
-
Clone the Repository:
git clone https://github.com/RaheesAhmed/Assistant-Api.git cd openai-express-app
-
Install Dependencies:
npm install
-
Set Up Environment Variables: Create a
.env
file in the root directory and add your OpenAI API key:OPENAI_API_KEY=your_openai_api_key
-
Start the Server:
npm start
-
Interact with the Chatbot: Send a POST request to
/chat
with a JSON payload:{ "message": "Your query here" }
You can use tools like Postman or a frontend interface to send the request.
-
View Responses: The server will respond with the chatbot's answer.
- The application uses
body-parser
for parsing incoming request bodies andmorgan
for HTTP request logging. - CORS is enabled for cross-origin requests.
- The
createAssistant
function initializes a new OpenAI assistant with specific instructions and settings. - All chat interactions are managed through the
/chat
endpoint.
Contributions, issues, and feature requests are welcome!
This project is licensed under the MIT License.