Spaces:
Sleeping
Sleeping
Initial commit
Browse files- app.py +10 -5
- schemas.py +2 -2
app.py
CHANGED
|
@@ -62,23 +62,28 @@ app.add_middleware(
|
|
| 62 |
|
| 63 |
@app.post("/ask", response_model=AskRes)
|
| 64 |
async def ask(request: Request, req: AskReq):
|
| 65 |
-
|
| 66 |
-
|
| 67 |
|
| 68 |
-
if not (req.session_id and req.npc_id and req.user_input
|
| 69 |
raise HTTPException(status_code=400, detail="missing fields")
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
result = await handle_dialogue(
|
| 72 |
request=request,
|
| 73 |
session_id=req.session_id,
|
| 74 |
npc_id=req.npc_id,
|
| 75 |
user_input=req.user_input,
|
| 76 |
-
context=context.
|
| 77 |
-
npc_config=
|
| 78 |
)
|
| 79 |
return result
|
| 80 |
|
| 81 |
|
|
|
|
| 82 |
@app.post("/wake")
|
| 83 |
async def wake(request: Request):
|
| 84 |
body = await request.json()
|
|
|
|
| 62 |
|
| 63 |
@app.post("/ask", response_model=AskRes)
|
| 64 |
async def ask(request: Request, req: AskReq):
|
| 65 |
+
if not req.context:
|
| 66 |
+
raise HTTPException(status_code=400, detail="missing context")
|
| 67 |
|
| 68 |
+
if not (req.session_id and req.npc_id and req.user_input):
|
| 69 |
raise HTTPException(status_code=400, detail="missing fields")
|
| 70 |
|
| 71 |
+
context = req.context
|
| 72 |
+
npc_config = context.npc_config
|
| 73 |
+
npc_config_dict = npc_config.model_dump() if npc_config else None
|
| 74 |
+
|
| 75 |
result = await handle_dialogue(
|
| 76 |
request=request,
|
| 77 |
session_id=req.session_id,
|
| 78 |
npc_id=req.npc_id,
|
| 79 |
user_input=req.user_input,
|
| 80 |
+
context=context.model_dump(),
|
| 81 |
+
npc_config=npc_config_dict
|
| 82 |
)
|
| 83 |
return result
|
| 84 |
|
| 85 |
|
| 86 |
+
|
| 87 |
@app.post("/wake")
|
| 88 |
async def wake(request: Request):
|
| 89 |
body = await request.json()
|
schemas.py
CHANGED
|
@@ -16,7 +16,7 @@ class DialogueTurn(BaseModel):
|
|
| 16 |
npc: str
|
| 17 |
|
| 18 |
class Context(BaseModel):
|
| 19 |
-
require: Dict[str, Any] = Field(
|
| 20 |
player_state: Dict[str, Any] = Field(..., description="νλ μ΄μ΄ νμ¬ μν")
|
| 21 |
game_state: Dict[str, Any] = Field(..., description="κ²μ μ μ μν")
|
| 22 |
npc_state: Dict[str, Any] = Field(..., description="DB μ΅μ NPC μν")
|
|
@@ -28,7 +28,7 @@ class AskReq(BaseModel):
|
|
| 28 |
session_id: str = Field(..., description="μΈμ
κ³ μ ID")
|
| 29 |
npc_id: str = Field(..., description="NPC κ³ μ ID")
|
| 30 |
user_input: str = Field(..., description="νλ μ΄μ΄ μ
λ ₯ λ¬Έμ₯")
|
| 31 |
-
context:
|
| 32 |
|
| 33 |
class AskRes(BaseModel):
|
| 34 |
session_id: str
|
|
|
|
| 16 |
npc: str
|
| 17 |
|
| 18 |
class Context(BaseModel):
|
| 19 |
+
require: Optional[Dict[str, Any]] = Field(None, description="pre 1μ°¨ 쑰건 νλ¨μ© νμ/μ ν μμ[rag λ¬Έμμ μμ±λ¨]")
|
| 20 |
player_state: Dict[str, Any] = Field(..., description="νλ μ΄μ΄ νμ¬ μν")
|
| 21 |
game_state: Dict[str, Any] = Field(..., description="κ²μ μ μ μν")
|
| 22 |
npc_state: Dict[str, Any] = Field(..., description="DB μ΅μ NPC μν")
|
|
|
|
| 28 |
session_id: str = Field(..., description="μΈμ
κ³ μ ID")
|
| 29 |
npc_id: str = Field(..., description="NPC κ³ μ ID")
|
| 30 |
user_input: str = Field(..., description="νλ μ΄μ΄ μ
λ ₯ λ¬Έμ₯")
|
| 31 |
+
context: Context = Field(..., description="κ²μ λ° NPC μν μ 보")
|
| 32 |
|
| 33 |
class AskRes(BaseModel):
|
| 34 |
session_id: str
|