|
from flask import Flask, request |
|
from flask_restful import Resource, Api, reqparse |
|
from flask_cors import CORS |
|
from encoder_file import get_encoder |
|
|
|
encoder = get_encoder() |
|
app = Flask(__name__) |
|
CORS(app) |
|
api = Api(app) |
|
parser = reqparse.RequestParser() |
|
|
|
class Status(Resource): |
|
def get(self): |
|
return {'status': 'Server Running Successfully'} |
|
|
|
|
|
DATASET_CONSTANT = { |
|
"data": [ |
|
"dataset-1", |
|
"dataset-2", |
|
"dataset-3", |
|
"dataset-4", |
|
"dataset-5" |
|
] |
|
} |
|
|
|
class Data(Resource): |
|
def get(self): |
|
return DATASET_CONSTANT |
|
|
|
|
|
class Datas(Resource): |
|
def post(self): |
|
parser.add_argument('prompt', type=str, required=True) |
|
args = parser.parse_args() |
|
prompt_ = args['prompt'] |
|
|
|
try: |
|
return_output = len(encoder.encode(prompt_)) |
|
|
|
|
|
total_consumed = 561 + return_output |
|
return {'status': '1', 'token_legth': return_output, |
|
'char_length': len(prompt_), |
|
'remaining_tokens': 4000 - total_consumed} |
|
|
|
except Exception as e: |
|
return {'status': '-1', 'e': e} |
|
|
|
|
|
api.add_resource(Status, '/') |
|
api.add_resource(Data, '/data') |
|
api.add_resource(Datas, '/get_size') |
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
app.run(debug=True) |