(request: Request)
| 20 | |
| 21 | @app.post("/") |
| 22 | async def create_item(request: Request): |
| 23 | global model, tokenizer |
| 24 | json_post_raw = await request.json() |
| 25 | json_post = json.dumps(json_post_raw) |
| 26 | json_post_list = json.loads(json_post) |
| 27 | prompt = json_post_list.get('prompt') |
| 28 | history = json_post_list.get('history') |
| 29 | max_length = json_post_list.get('max_length') |
| 30 | top_p = json_post_list.get('top_p') |
| 31 | temperature = json_post_list.get('temperature') |
| 32 | response, history = model.chat(tokenizer, |
| 33 | prompt, |
| 34 | history=history, |
| 35 | max_length=max_length if max_length else 2048, |
| 36 | top_p=top_p if top_p else 0.7, |
| 37 | temperature=temperature if temperature else 0.95) |
| 38 | now = datetime.datetime.now() |
| 39 | time = now.strftime("%Y-%m-%d %H:%M:%S") |
| 40 | answer = { |
| 41 | "response": response, |
| 42 | "history": history, |
| 43 | "status": 200, |
| 44 | "time": time |
| 45 | } |
| 46 | log = "[" + time + "] " + '", prompt:"' + prompt + '", response:"' + repr(response) + '"' |
| 47 | print(log) |
| 48 | torch_gc() |
| 49 | return answer |
| 50 | |
| 51 | |
| 52 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected