higher5fh commited on
Commit
0145b4c
Β·
verified Β·
1 Parent(s): f40cc21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -23,9 +23,9 @@ from openai import OpenAI
23
  from langchain_community.embeddings import OpenAIEmbeddings
24
  from langchain_community.vectorstores import Chroma
25
  from langchain_community.chat_models import ChatOpenAI
26
- from langchain_classic.prompts import PromptTemplate
27
- from langchain_classic.chains import LLMChain
28
- from langchain_classic.prompts import PromptTemplate
29
 
30
 
31
  # ─── SETTINGS ────────────────────────────────────────────────────────────────────
@@ -94,14 +94,10 @@ openai_client = OpenAI(api_key=settings.OPENAI_API_KEY)
94
  async def moderate_content(text: str) -> bool:
95
  try:
96
  resp = openai_client.moderations.create(input=text)
97
- # Allow if the API failed or if the model returns no result
98
- if not resp.results:
99
- return True
100
  return not resp.results[0].flagged
101
  except Exception as e:
102
- logger.warning(f"Moderation check failed, allowing text. Error: {e}")
103
- return True # don't block on moderation errors
104
-
105
 
106
  # ─── SESSION MANAGEMENT ──────────────────────────────────────────────────────────
107
  class SessionData(BaseModel):
@@ -311,5 +307,4 @@ async def get_session_history(session: SessionData = Depends(get_session)):
311
  if __name__ == "__main__":
312
  import uvicorn
313
  port = int(os.environ.get("PORT", 7860))
314
- uvicorn.run("app:app", host="0.0.0.0", port=port, workers=4, log_level="info")
315
-
 
23
  from langchain_community.embeddings import OpenAIEmbeddings
24
  from langchain_community.vectorstores import Chroma
25
  from langchain_community.chat_models import ChatOpenAI
26
+ from langchain.chains import LLMChain
27
+ from langchain.prompts import PromptTemplate
28
+
29
 
30
 
31
  # ─── SETTINGS ────────────────────────────────────────────────────────────────────
 
94
  async def moderate_content(text: str) -> bool:
95
  try:
96
  resp = openai_client.moderations.create(input=text)
 
 
 
97
  return not resp.results[0].flagged
98
  except Exception as e:
99
+ logger.error(f"Moderation error: {e}")
100
+ return False
 
101
 
102
  # ─── SESSION MANAGEMENT ──────────────────────────────────────────────────────────
103
  class SessionData(BaseModel):
 
307
  if __name__ == "__main__":
308
  import uvicorn
309
  port = int(os.environ.get("PORT", 7860))
310
+ uvicorn.run("app:app", host="0.0.0.0", port=port, workers=4, log_level="info")