m97j commited on
Commit
18ac473
Β·
1 Parent(s): 39671d3

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +10 -5
  2. 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
- context = req.context or {}
66
- npc_config = context.npc_config
67
 
68
- if not (req.session_id and req.npc_id and req.user_input and npc_config):
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.dict(),
77
- npc_config=npc_config.dict()
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(..., description="pre 1μ°¨ 쑰건 νŒλ‹¨μš© ν•„μˆ˜/선택 μš”μ†Œ")
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: Optional[Context] = Field(default_factory=Context, description="κ²Œμž„ 및 NPC μƒνƒœ 정보")
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