Este proyecto proporciona una API de back-end para un sistema de respuesta de preguntas impulsado por el modelo de lenguaje generativo de Google AI. Los usuarios pueden enviar preguntas, recibir respuestas generadas por el modelo AI y opcionalmente almacenar sus preguntas y respuestas para referencia futura.
Clon este repositorio:
git clone [https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git](https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git)
Navegue al directorio del proyecto:
cd faiz-mohammad-answersai-backend
3- Instalar dependencias:
npm i
Configuration
# # 1. Environment Variables:
# Create a file named .env in your project's root directory. This file should contain the following environment variables (replace with your actual values):
Access_token_secret = your_secret_key mongo_uri = mongodb: // your_mongo_connection_string gemini_api_key = your_google_cloud_api_key
# Important:
ACCESS_TOKEN_SECRET: A secret key used for signing JWT tokens for user authentication. Choose a strong and unique key.
MONGO_URI: The connection string for your MongoDB database.
GEMINI_API_KEY: Your Google Cloud API key for accessing the Generative AI service.
Note: You can exclude the .env file from version control using tools like .gitignore.
## 2. MongoDB Database:
Set up a MongoDB database instance and configure the MONGO_URI environment variable accordingly.
Running the Application
Start the development server:
NPM Start # o inicio de hilo
Use code with caution.
content_copy
This will start the Node.js server and listen for incoming requests on the default port (usually 8000).
(Optional) Start a live-reloading server for development:
NPM Ejecutar servidor # o servidor de hilo
Use code with caution.
content_copy
This will use Nodemon to automatically restart the server whenever you make changes to your code.
API Usage
The API endpoints are documented below. You can use tools like Postman or curl to send requests to the server.
1. User Authentication:
# Endpoint: /api/users/ (POST)
JSON {"Nombre de usuario": "Your_Username", "Contraseña": "Your_Password"}
Solicitud de cuerpo:
{
"username": "your_username",
"password": "your_password"
}
Respuesta:
Json {"token": "your_jwt_token"}
Tras un inicio de sesión exitoso, el servidor devuelve un token JWT que deberá incluir en solicitudes posteriores que requieren autenticación.
Endpoint: /API /Preguntas (POST)
Encabezados de solicitud:
Autorización: Bearer <Your_JWT_Token> Solicitud de cuerpo:
JSON {"Pregunta": "Your_Question"} Use el código con precaución. Respuesta content_copy:
JSON {"_id": "Pregunta_id", "user_id": "user_id", "contenido": "your_question", "respuesta": "ai_generated_answer", "creatingat": "timestamp"} Use código con precaución. content_copy 3. recuperar preguntas:
Endpoint: /api/questions (Get)
Respuesta:
[
{ ...question1 object ... },
{ ...question2 object ... },
...
] Endpoint: /api/questions/user/<user_id> (Get)
Respuesta: