Este projeto fornece uma API de back-end para um sistema de resposta a perguntas alimentado pelo modelo de linguagem generativa do Google AI. Os usuários podem enviar perguntas, receber respostas geradas pelo modelo de IA e, opcionalmente, armazenar suas perguntas e respostas para referência futura.
Clone este repositório:
git clone [https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git](https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git)
Navegue até o diretório do projeto:
cd faiz-mohammad-answersai-backend
3- Instale dependências:
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 Iniciar # ou Início do fio
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 Run Server # ou servidor de fio
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 {"Nome de usuário": "Your_Username", "Senha": "Your_password"}
Solicitar corpo:
{
"username": "your_username",
"password": "your_password"
}
Resposta:
Json {"Token": "your_jwt_token"}
Após o login bem -sucedido, o servidor retorna um token JWT que você precisará incluir nas solicitações subsequentes que exigem autenticação.
Endpoint: /API /perguntas (postagem)
Cabeçalhos de solicitação:
Autorização: Portador <Your_Jwt_Token> Solicitar corpo:
JSON {"PERGUNTA": "Your_Question"} Use o código com cautela. Content_copy Response:
Json {"_id": "question_id", "user_id": "user_id", "content": "your_question", "Answer": "ai_generated_answer", "criado": "timestamp"} use código com cautela. Content_copy 3. Recupere as perguntas:
Endpoint: /api/questions (get)
Resposta:
[
{ ...question1 object ... },
{ ...question2 object ... },
...
] Endpoint: /api/questions/user/<user_id> (get)
Resposta: