添加请求与响应模型

pull/547/head
Whitroom 2023-04-12 14:45:52 +08:00
parent 0c2806fea8
commit 24dada9d5a
1 changed files with 19 additions and 3 deletions

22
api.py
View File

@ -1,7 +1,11 @@
from fastapi import FastAPI, Request import datetime
from transformers import AutoTokenizer, AutoModel import json
import uvicorn, json, datetime
import torch import torch
import uvicorn
from fastapi import FastAPI, Request
from pydantic import BaseModel
from transformers import AutoModel, AutoTokenizer
DEVICE = "cuda" DEVICE = "cuda"
DEVICE_ID = "0" DEVICE_ID = "0"
@ -17,6 +21,18 @@ def torch_gc():
app = FastAPI() app = FastAPI()
class Item(BaseModel):
prompt: str
history: list[tuple[str, str]] = [[]]
max_length: int = 2048
top_p: float = 0.7
temperature: float = 0.95
class Answer(BaseModel):
response: str
history: list[tuple[str, str]]
status: int
time: str
@app.post("/") @app.post("/")
async def create_item(request: Request): async def create_item(request: Request):