-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.py
52 lines (41 loc) · 1.48 KB
/
frontend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import modal
from pathlib import Path
app = modal.App("browserman-frontend")
frontend_path = Path(__file__).parent / "llm-frontend"
web_image = modal.Image.debian_slim(python_version="3.11").pip_install(
"fastapi[standard]==0.115.4"
)
@app.function(
image=web_image,
mounts=[modal.Mount.from_local_dir(frontend_path, remote_path="/assets")],
keep_warm=1,
allow_concurrent_inputs=20,
timeout=60 * 10,
)
@modal.asgi_app(label="browserman-test")
def tgi_mixtral():
import json
import fastapi
from fastapi import staticfiles
from fastapi.responses import StreamingResponse
from fastapi import FastAPI
web_app = FastAPI()
Model = modal.Cls.lookup("browserman", "Model")
@web_app.get("/stats")
async def stats():
stats = await Model().inference.get_current_stats.aio()
return {
"backlog": stats.backlog,
"num_total_runners": stats.num_total_runners,
"model": "Llama 3.2",
}
@web_app.get("/completion/{question}")
async def completion(question: str):
from urllib.parse import unquote
async def generate():
# TODO: stream
text = await Model().inference.remote.aio(unquote(question))
yield f"data: {json.dumps(dict(text=text), ensure_ascii=False)}\n\n"
return StreamingResponse(generate(), media_type="text/event-stream")
web_app.mount("/", fastapi.staticfiles.StaticFiles(directory="/assets", html=True))
return web_app