Dieses Projekt bietet eine Backend-API für ein Fragen-Answer-System, das vom generativen Sprachmodell von Google AI betrieben wird. Benutzer können Fragen einreichen, Antworten erhalten, die vom KI -Modell generiert werden, und speichern ihre Fragen und Antworten optional für zukünftige Referenz.
Klonen Sie dieses Repository:
git clone [https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git](https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git)
Navigieren Sie zum Projektverzeichnis:
cd faiz-mohammad-answersai-backend
3- Abhängigkeiten installieren:
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 # oder Garnstart
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 -Server # oder Garnserver ausführen
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 {"Benutzername": "Your_username", "Passwort": "Your_password"}
Antragsbehörde:
{
"username": "your_username",
"password": "your_password"
}
Antwort:
JSON {"Token": "your_jwt_token"}
Nach erfolgreicher Login gibt der Server ein JWT -Token zurück, das Sie in nachfolgende Anforderungen einbeziehen müssen, die eine Authentifizierung erfordern.
Endpunkt: /api /Fragen (Post)
Anfrage Header:
Autorisierung: Bearer <Your_Jwt_Token> Anforderungsbehörde:
JSON {"Frage": "Your_Question"} Verwenden Sie Code mit Vorsicht. Content_copy Antwort:
JSON {"_id": "Frage_ID", "user_id": "user_id", "Inhalt": "Your_Question", "Antwort": "ai_generated_answer", "erstellt": "Timestamp"} Verwenden Sie Code. content_copy 3.. Fragen abrufen:
Endpunkt: /api/questions (get)
Antwort:
[
{ ...question1 object ... },
{ ...question2 object ... },
...
] Endpunkt: /api/questions/user/<user_id> (get)
Antwort: