โครงการนี้ให้แบ็กเอนด์ API สำหรับระบบการตอบคำถามที่ขับเคลื่อนโดยโมเดลภาษากำเนิดของ Google AI ผู้ใช้สามารถส่งคำถามรับคำตอบที่สร้างขึ้นโดยโมเดล AI และเลือกเก็บคำถามและคำตอบสำหรับการอ้างอิงในอนาคต
โคลนที่เก็บนี้:
git clone [https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git](https://github.com/Faizgeeky/faiz-mohammad-answersai-backend.git)
นำทางไปยังไดเรกทอรีโครงการ:
cd faiz-mohammad-answersai-backend
3- ติดตั้งการพึ่งพา:
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_apkey
# 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 เริ่ม # หรือเริ่มต้นด้วยเส้นด้าย
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 # หรือเส้นด้ายเซิร์ฟเวอร์
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 {"ชื่อผู้ใช้": "your_username", "รหัสผ่าน": "your_password"}
ขอร่าง:
{
"username": "your_username",
"password": "your_password"
}
การตอบสนอง:
json {"โทเค็น": "your_jwt_token"}
เมื่อเข้าสู่ระบบที่ประสบความสำเร็จเซิร์ฟเวอร์จะส่งคืนโทเค็น JWT ที่คุณจะต้องรวมไว้ในคำขอที่ตามมาซึ่งต้องใช้การรับรองความถูกต้อง
จุดสิ้นสุด: /API /คำถาม (โพสต์)
ขอส่วนหัว:
การอนุญาต: ผู้ถือ <your_jwt_token> คำขอร่างกาย:
JSON {"คำถาม": "your_question"} ใช้รหัสด้วยความระมัดระวัง การตอบสนอง content_copy:
JSON {"_ID": "question_id", "user_id": "user_id", "เนื้อหา": "your_question", "คำตอบ": "ai_generated_answer", "createdat": "timestamp"} ใช้รหัสด้วยคำเตือน content_copy 3. ดึงคำถาม:
จุดสิ้นสุด: /api/questions (รับ)
การตอบสนอง:
[
{ ...question1 object ... },
{ ...question2 object ... },
...
] จุดสิ้นสุด: /api/questions/user/<user_id> (รับ)
การตอบสนอง: