mirror of https://github.com/THUDM/ChatGLM-6B
parent
044cf323a7
commit
6ba39b421c
10
api.py
10
api.py
|
@ -1,9 +1,8 @@
|
||||||
import torch
|
|
||||||
import asyncio
|
|
||||||
import concurrent.futures
|
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from transformers import AutoTokenizer, AutoModel
|
from transformers import AutoTokenizer, AutoModel
|
||||||
import uvicorn, json, datetime
|
import uvicorn, json, datetime
|
||||||
|
import torch
|
||||||
|
import asyncio
|
||||||
|
|
||||||
DEVICE = "cuda"
|
DEVICE = "cuda"
|
||||||
DEVICE_ID = "0"
|
DEVICE_ID = "0"
|
||||||
|
@ -52,10 +51,7 @@ async def create_item(request: Request):
|
||||||
torch_gc()
|
torch_gc()
|
||||||
return answer
|
return answer
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
return await asyncio.to_thread(_sync_chat, history=history)
|
||||||
executor = concurrent.futures.ThreadPoolExecutor()
|
|
||||||
answer = await loop.run_in_executor(executor, _sync_chat, history)
|
|
||||||
return answer
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue