このプロジェクトは、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 start#またはyarn start
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#またはYARNサーバー
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トークンを返します。
endpoint: /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"、 "recutedat": "timestamp"}慎重にコードを使用します。 content_copy 3。質問を取得します:
endpoint: /api/questions (get)
応答:
[
{ ...question1 object ... },
{ ...question2 object ... },
...
] endpoint: /api/questions/user/<user_id> (get)
応答: