이 프로젝트는 Google AI의 생성 언어 모델로 구동되는 질문 응답 시스템에 대한 백엔드 API를 제공합니다. 사용자는 질문을 제출하고 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_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 시작 # 또는 원사 시작
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 실행 서버 # 또는 원사 서버
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 { "username": "your_username", "password": "your_password"}
요청 본문 :
{
"username": "your_username",
"password": "your_password"
}
응답:
JSON { "TOKEN": "your_jwt_token"}}
성공적인 로그인시 서버는 인증이 필요한 후속 요청에 포함 해야하는 JWT 토큰을 반환합니다.
엔드 포인트 : /API /질문 (게시물)
헤더 요청 :
승인 : Bearer <Your_jwt_token> 요청 본문 :
json { "Question": "Your_Question"}주의와 함께 코드를 사용하십시오. content_copy 응답 :
json { "_id": "Question_id", "user_id": "user_id", "content": "your_question", "answer": "ai_generated_answer", "createat": "timestamp"} 코드를주의해서 사용하십시오. content_copy 3. 질문 검색 :
엔드 포인트 : /api/questions (GET)
응답:
[
{ ...question1 object ... },
{ ...question2 object ... },
...
] 엔드 포인트 : /api/questions/user/<user_id> (get)
응답: