|
1 | 1 | # -*- coding: utf-8 -*- |
2 | | -from fastapi import FastAPI |
| 2 | +from fastapi import FastAPI, responses, status |
3 | 3 | import controller |
4 | 4 | from data import data_type |
5 | 5 | from typing import List, Dict, Tuple |
|
25 | 25 | @app.get("/classification/recommend/{data_type}") |
26 | 26 | def recommendations( |
27 | 27 | data_type: str, |
28 | | -) -> Tuple[List[Dict[str, str]], int]: |
| 28 | +) -> responses.JSONResponse: |
29 | 29 | recommends = [ |
30 | 30 | ### English ### |
31 | 31 | { |
@@ -92,39 +92,44 @@ def recommendations( |
92 | 92 | }, |
93 | 93 | ] |
94 | 94 |
|
95 | | - return recommends, 200 |
| 95 | + return responses.JSONResponse(status_code=status.HTTP_200_OK, content=recommends) |
96 | 96 |
|
97 | 97 |
|
98 | 98 | @app.post("/classification/encode") |
99 | | -def encode_classification(request: data_type.Request) -> Tuple[int, str]: |
| 99 | +def encode_classification(request: data_type.Request) -> responses.PlainTextResponse: |
100 | 100 | # session logic for threads in side |
101 | | - return controller.start_encoding_thread(request, "classification"), "" |
| 101 | + status_code = controller.start_encoding_thread(request, "classification") |
| 102 | + |
| 103 | + return responses.PlainTextResponse(status_code=status_code) |
102 | 104 |
|
103 | 105 |
|
104 | 106 | @app.post("/extraction/encode") |
105 | | -def encode_extraction(request: data_type.Request) -> Tuple[int, str]: |
| 107 | +def encode_extraction(request: data_type.Request) -> responses.PlainTextResponse: |
106 | 108 | # session logic for threads in side |
107 | | - return controller.start_encoding_thread(request, "extraction"), "" |
| 109 | + status_code = controller.start_encoding_thread(request, "extraction") |
| 110 | + return responses.PlainTextResponse(status_code=status_code) |
108 | 111 |
|
109 | 112 |
|
110 | 113 | @app.delete("/delete/{project_id}/{embedding_id}") |
111 | | -def delete_embedding(project_id: str, embedding_id: str) -> Tuple[int, str]: |
| 114 | +def delete_embedding(project_id: str, embedding_id: str) -> responses.PlainTextResponse: |
112 | 115 | session_token = general.get_ctx_token() |
113 | | - return_value = controller.delete_embedding(project_id, embedding_id) |
| 116 | + status_code = controller.delete_embedding(project_id, embedding_id) |
114 | 117 | general.remove_and_refresh_session(session_token) |
115 | | - return return_value, "" |
| 118 | + return responses.PlainTextResponse(status_code=status_code) |
116 | 119 |
|
117 | 120 |
|
118 | 121 | @app.post("/upload_tensor_data/{project_id}/{embedding_id}") |
119 | | -def upload_tensor_data(project_id: str, embedding_id: str) -> Tuple[int, str]: |
| 122 | +def upload_tensor_data( |
| 123 | + project_id: str, embedding_id: str |
| 124 | +) -> responses.PlainTextResponse: |
120 | 125 | session_token = general.get_ctx_token() |
121 | 126 | controller.upload_embedding_as_file(project_id, embedding_id) |
122 | 127 | request_util.post_embedding_to_neural_search(project_id, embedding_id) |
123 | 128 | general.remove_and_refresh_session(session_token) |
124 | | - return 200, "" |
| 129 | + return responses.PlainTextResponse(status_code=status.HTTP_200_OK) |
125 | 130 |
|
126 | 131 |
|
127 | 132 | @app.put("/config_changed") |
128 | | -def config_changed() -> int: |
| 133 | +def config_changed() -> responses.PlainTextResponse: |
129 | 134 | config_handler.refresh_config() |
130 | | - return 200 |
| 135 | + return responses.PlainTextResponse(status_code=status.HTTP_200_OK) |
0 commit comments