Spaces:
Sleeping
Sleeping
shengwei62
commited on
Commit
•
b1a3f0c
1
Parent(s):
be2fbc5
Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Form
|
2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
3 |
+
from fastapi.staticfiles import StaticFiles
|
4 |
+
from fastapi.responses import HTMLResponse
|
5 |
+
from .ai.chatbot import gpt_chatbot, llama_chatbot, taide_chatbot
|
6 |
+
|
7 |
+
isProduction = False
|
8 |
+
|
9 |
+
origins = ["*"]
|
10 |
+
|
11 |
+
if isProduction:
|
12 |
+
app = FastAPI(
|
13 |
+
title="LLM API Endpoints",
|
14 |
+
docs_url=None, # Disable docs (Swagger UI)
|
15 |
+
redoc_url=None, # Disable redoc
|
16 |
+
)
|
17 |
+
#app.mount("/static", StaticFiles(directory="static"), name="static")
|
18 |
+
else:
|
19 |
+
app = FastAPI(title="LLM API Endpoints")
|
20 |
+
#app.mount("/static", StaticFiles(directory="static"), name="static")
|
21 |
+
|
22 |
+
app.add_middleware(
|
23 |
+
CORSMiddleware,
|
24 |
+
allow_origins=origins,
|
25 |
+
allow_credentials=True,
|
26 |
+
allow_methods=["POST", "GET", "PUT", "DELETE"],
|
27 |
+
allow_headers=["*"],
|
28 |
+
)
|
29 |
+
|
30 |
+
|
31 |
+
# Create a homepage route
|
32 |
+
@app.get("/")
|
33 |
+
async def index():
|
34 |
+
return {"server ok": True}
|
35 |
+
|
36 |
+
|
37 |
+
@app.post("/api/chat/gpt3", tags=["OpenAI GPT-3"])
|
38 |
+
async def gpt_chat(user_request: str = Form(...)):
|
39 |
+
"""
|
40 |
+
Chat with LLM Backend - GPT-3
|
41 |
+
"""
|
42 |
+
# Get the text content in the user request
|
43 |
+
result = gpt_chatbot(user_request=user_request)
|
44 |
+
|
45 |
+
return {"result": result}
|
46 |
+
|
47 |
+
|
48 |
+
@app.post("/api/chat/llama", tags=["Llama 2 7B Chat"])
|
49 |
+
async def llama_chat(user_request: str = Form(...)):
|
50 |
+
"""
|
51 |
+
Chat with LLM Backend - Llama 2 7b Chat
|
52 |
+
"""
|
53 |
+
# Get the text content in the user request
|
54 |
+
result = llama_chatbot(user_request=user_request)
|
55 |
+
|
56 |
+
return {"result": result}
|
57 |
+
|
58 |
+
@app.post("/api/chat/taide", tags=["taide Chat"])
|
59 |
+
async def taide_chat(user_request: str = Form(...)):
|
60 |
+
"""
|
61 |
+
Chat with LLM Backend - Llama 2 7b Chat
|
62 |
+
"""
|
63 |
+
# Get the text content in the user request
|
64 |
+
result = taide_chatbot(user_request=user_request)
|
65 |
+
|
66 |
+
return {"result": result}
|