Implement a functionality using FastAPI to periodically provide clients with briefings on the results of an AI Inference Pipeline. Enable interaction between the client and the server through request and response mechanisms.
Please refer to the attached "requirements.txt" for the versions of packages and libraries needed for environment installation.
pip install fastapi
pip install "uvicorn[standard]"
pip install websockets
pip install apscheduler
pip install pymongo
Install MongoDB following the instructions on the
pip install python-dotenv
Create a separate file named .env.production and add the following content:
DATABASE_ID="your_id"
DATABASE_PASSWORD="your_pw"
DATABASE_URI=mongodb+srv://<DATABASE_ID>:<DATABASE_PASSWORD>@"your_dbname".keizkxa.mongodb.net
Ensure that you keep this file secure and do not share sensitive information.
This file contains configuration details for your production environment, including database credentials. Keep in mind the importance of securing this information and not exposing it publicly.
Index | Method | URI | Description |
---|---|---|---|
1 | POST | /login | 로그인 API |
2 | WebSocket | /ws | Web socket (Db 변화 감지) |
3 | WebSocket | /reloadBriefing | Web socket (진행 중 briefing 확인) |
4 | POST | /endBriefing | Briefing 종료 |
5 | POST | /getAllRequest | 모든 request 조회 |
6 | POST | /getBriefing | 모든 briefing 조회 |
7 | POST | /aiSummary | 브리핑 요약 |
8 | POST | /getCustom | Custom 획득 |
9 | POST | /updateCustom | Custom 갱신 |
-
-
description
-
Utilize check_user in models.py to verify new and existing users.
- In the case of an existing user, return
{"message": "signup", "user_id": <user_id>}
. - For a new user, return
{"message": "login", "user_id": <user_id>}
.
- In the case of an existing user, return
-
-
Endpoint | Method |
---|---|
POST /login |
POST |
Request | |
---|---|
Header | |
"No special headers required" | |
Body | |
Parameter | Type |
username | String |
Response |
---|
1) Success Response |
Status Code: 200 OK |
Body: |
json { "message" : "signup", "user_id" : "user_id_value"} |
or |
json { "message" : "login", "user_id" : "user_id_value"} |
2) Error Response |
Status Code: 500 Internal Server Error |
Body: |
json { "detail": "Login Error: error_message"} |
-
- Description:
- Handle WebSocket connections for continuous updates.
- Establish WebSocket connection.
- Store new request in the database and register with the scheduler.
- Continuously send updates to the frontend through the WebSocket.
- Description:
Endpoint | Method |
---|---|
websocket/ws |
WebSocket |
Parameters
Name | Type | Description |
---|---|---|
websocket | WebSocket | The WebSocket connection object. |
username | String | User's username. |
interval | String | Requested interval for updates. |
endtime | String | Requested end time for updates. |
-
- Description
- Display the ongoing briefing.
- Establish WebSocket connection.
- Send reloaded briefing data to the frontend.
- Get the latest request ID and continuously watch the database for updates.
- Description
Endpoint | Method |
---|---|
websocket/reloadBriefing |
WebSocket |
Parameters
Name | Type | Description |
---|---|---|
websocket | WebSocket | The WebSocket connection object. |
username | String | User's username. |
-
- description
-
Terminate the ongoing briefing.
-
The function endBriefing uses the endBriefing_worker from utils.py and end_scheduler from scheduler.py.
- Upon success, it prints a success message and returns a success response with the message
"Briefing successfully terminated"
. - In case of failure (e.g., an
exception
), it catches the"HTTPException"
, logs the error message, and returns an error response with the corresponding status code and details.
- Upon success, it prints a success message and returns a success response with the message
-
- description
Endpoint | Method |
---|---|
POST /endBriefing |
POST |
Request | |
---|---|
Header | |
"No special headers required" | |
Body | |
Parameter | Type |
username | String |
Response |
---|
1) Success Response |
Status Code: 200 OK |
Body: |
"message": "브리핑 성공적으로 종료" |
2)Error Response |
Status Code: 500 Internal Server Error |
Body: |
Internal Server Error |
-
- description
- Implement a functionality to retrieve all requests for a specific username from the
"request" Collection
within the database. - getAllRequest utilizes the get_all_request function from utils.py to retrieve and return the list of requests for a specific username from the "request" Collection in the database.
- Implement a functionality to retrieve all requests for a specific username from the
- description
-
- description
- Retrieve briefing information based on the provided
request_id
. - Utilize the
get_briefing
function fromutils.py
to perform a functionality that retrieves all briefings for a specific request_id from the"briefing" Collection
in the database.
- Retrieve briefing information based on the provided
- description
-
- description
-
Generates an AI summary captions based on the provided
request_id
. -
This API utilizes two methods:
get_briefing
inutils.py
for querying all data from the database andchat_summary
inutils.py
for generating AI summaries based on the returned briefing data list. -
To provide additional details on
chat_summary
, it involves using theOpenAI API key
to generate messages based on a specified format prompt. This process utilizes theGPT-4-preview model
and performsprompt engineering
on the briefing data list retrieved earlier, adjusting hyperparameters such as"tone, writing style, temperature, top_p,"
and others.
-
- description
-
- description
- this API retrieves the
"custom"
data for a specific username. The obtainedcustom_list
is then used to generate an HTTP response in JSON format, encoded in UTF-8. - The
get_custom
inmodels.py
process involves searching for the specified username within the "user" collection in the database and referring to it as a custom list.
- this API retrieves the
- description
-
- description
- Utilizing the
update_custom
function inmodels.py
, this API updates the"custom"
field in the "user" table.- If the custom_list is successfully updated, it returns the message
"Success to update Custom."
- In case of exceptions or errors, it raises an
HTTPException
with a status code of 500 and the detail"Fail to update Custom."
- If the custom_list is successfully updated, it returns the message
- Utilizing the
- description