3v324v23 commited on
Commit
fa3f31a
·
1 Parent(s): 182889e

fix: accept both 'action' and 'response' field names in /step endpoint

Browse files
Files changed (1) hide show
  1. api.py +10 -2
api.py CHANGED
@@ -1,7 +1,7 @@
1
  from fastapi import FastAPI, HTTPException
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.openapi.docs import get_swagger_ui_html
4
- from pydantic import BaseModel
5
  from typing import Optional
6
 
7
  from environment import CustomerSupportEnv, STEP_ORDER
@@ -33,7 +33,15 @@ class ResetRequest(BaseModel):
33
 
34
 
35
  class StepRequest(BaseModel):
36
- action: str
 
 
 
 
 
 
 
 
37
 
38
 
39
  def _build_observation():
 
1
  from fastapi import FastAPI, HTTPException
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from fastapi.openapi.docs import get_swagger_ui_html
4
+ from pydantic import BaseModel, model_validator
5
  from typing import Optional
6
 
7
  from environment import CustomerSupportEnv, STEP_ORDER
 
33
 
34
 
35
  class StepRequest(BaseModel):
36
+ action: Optional[str] = None # accepts {"action": "..."}
37
+ response: Optional[str] = None # accepts {"response": "..."}
38
+
39
+ @model_validator(mode="after")
40
+ def resolve_action(self):
41
+ self.action = self.action or self.response
42
+ if not self.action:
43
+ raise ValueError("Provide either 'action' or 'response' field with the agent reply.")
44
+ return self
45
 
46
 
47
  def _build_observation():