j-js commited on
Commit
72b2888
·
verified ·
1 Parent(s): ccbb9de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -21,7 +21,7 @@ generator = GeneratorEngine()
21
  engine = ConversationEngine(retriever=retriever, generator=generator)
22
  store = LoggingStore()
23
 
24
- app = FastAPI(title="Trading Game AI V2", version="2.2.0")
25
  app.add_middleware(
26
  CORSMiddleware,
27
  allow_origins=["*"],
@@ -33,7 +33,11 @@ app.add_middleware(
33
 
34
  @app.get("/health")
35
  def health() -> Dict[str, Any]:
36
- return {"ok": True, "app": "Trading Game AI V2", "generator_available": generator.available()}
 
 
 
 
37
 
38
 
39
  @app.get("/", response_class=HTMLResponse)
@@ -61,14 +65,20 @@ async def chat(request: Request) -> JSONResponse:
61
  game_fields = extract_game_context_fields(hidden_context)
62
 
63
  question_text = (getattr(req, "question_text", None) or "").strip() or game_fields["question"]
64
- options_text = game_fields["options"]
 
 
 
 
 
65
 
66
  tone = clamp01(req_data.get("tone", getattr(req, "tone", 0.5)), 0.5)
67
  verbosity = clamp01(req_data.get("verbosity", getattr(req, "verbosity", 0.5)), 0.5)
68
  transparency = clamp01(req_data.get("transparency", getattr(req, "transparency", 0.5)), 0.5)
69
 
70
  incoming_help_mode = req_data.get("help_mode", getattr(req, "help_mode", None))
71
- intent = detect_intent(actual_user_message or full_text, incoming_help_mode)
 
72
  help_mode = intent_to_help_mode(intent)
73
 
74
  result = engine.generate_response(
@@ -81,6 +91,7 @@ async def chat(request: Request) -> JSONResponse:
81
  chat_history=getattr(req, "chat_history", None) or getattr(req, "history", None) or [],
82
  question_text=question_text,
83
  options_text=options_text,
 
84
  )
85
 
86
  return JSONResponse(
@@ -137,4 +148,4 @@ if __name__ == "__main__":
137
  import uvicorn
138
 
139
  port = int(os.getenv("PORT", "7860"))
140
- uvicorn.run(app, host="0.0.0.0", port=port)
 
21
  engine = ConversationEngine(retriever=retriever, generator=generator)
22
  store = LoggingStore()
23
 
24
+ app = FastAPI(title="Trading Game AI V2", version="2.3.0")
25
  app.add_middleware(
26
  CORSMiddleware,
27
  allow_origins=["*"],
 
33
 
34
  @app.get("/health")
35
  def health() -> Dict[str, Any]:
36
+ return {
37
+ "ok": True,
38
+ "app": "Trading Game AI V2",
39
+ "generator_available": generator.available(),
40
+ }
41
 
42
 
43
  @app.get("/", response_class=HTMLResponse)
 
65
  game_fields = extract_game_context_fields(hidden_context)
66
 
67
  question_text = (getattr(req, "question_text", None) or "").strip() or game_fields["question"]
68
+ options_text = getattr(req, "options_text", None) or game_fields["options"]
69
+ category = (
70
+ req_data.get("category")
71
+ or getattr(req, "category", None)
72
+ or game_fields.get("category")
73
+ )
74
 
75
  tone = clamp01(req_data.get("tone", getattr(req, "tone", 0.5)), 0.5)
76
  verbosity = clamp01(req_data.get("verbosity", getattr(req, "verbosity", 0.5)), 0.5)
77
  transparency = clamp01(req_data.get("transparency", getattr(req, "transparency", 0.5)), 0.5)
78
 
79
  incoming_help_mode = req_data.get("help_mode", getattr(req, "help_mode", None))
80
+ explicit_intent = req_data.get("intent", getattr(req, "intent", None))
81
+ intent = explicit_intent or detect_intent(actual_user_message or full_text, incoming_help_mode)
82
  help_mode = intent_to_help_mode(intent)
83
 
84
  result = engine.generate_response(
 
91
  chat_history=getattr(req, "chat_history", None) or getattr(req, "history", None) or [],
92
  question_text=question_text,
93
  options_text=options_text,
94
+ category=category,
95
  )
96
 
97
  return JSONResponse(
 
148
  import uvicorn
149
 
150
  port = int(os.getenv("PORT", "7860"))
151
+ uvicorn.run(app, host="0.0.0.0", port=port)