-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
40 lines (31 loc) · 989 Bytes
/
server.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
# Custom Module
from src import PersonaChatbot
# API
from fastapi import FastAPI
from pydantic import BaseModel
# Create the FastAPI app
app = FastAPI()
class APIKey(BaseModel):
api_key: str
class ChatComponent(BaseModel):
prompt: str
api_key: str
db_path: str
@app.get("/")
def root():
return {"Hello": "World"}
@app.post("/chat/")
def chat_with_bot(chat_component: ChatComponent) -> dict:
model = PersonaChatbot(api_key=chat_component.api_key,
db_path=chat_component.db_path)
result = model.chat(chat_component.prompt)
return {"output": result}
# @app.post("/get_model")
# def get_chatbot(api_key: APIKey) -> PersonaChatbot:
# chatbot = PersonaChatbot(api_key.api_key)
# return {"model": chatbot}
# @app.post("/chat/")
# def chat_with_bot(model_prompt: ChatPrompt=Depends(get_chatbot)) -> dict:
# model = model_prompt.chatbot
# result = model.chat(model_prompt.prompt)
# return {"response": result}