higher5fh commited on
Commit
40102e3
Β·
verified Β·
1 Parent(s): d44f0a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -13
app.py CHANGED
@@ -23,11 +23,8 @@ 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
-
29
-
30
-
31
 
32
  # ─── SETTINGS ────────────────────────────────────────────────────────────────────
33
  class Settings(BaseSettings):
@@ -95,16 +92,10 @@ openai_client = OpenAI(api_key=settings.OPENAI_API_KEY)
95
  async def moderate_content(text: str) -> bool:
96
  try:
97
  resp = openai_client.moderations.create(input=text)
98
- # If moderation returns no results, allow the content (avoid false blocks)
99
- if not getattr(resp, "results", None):
100
- logger.warning("Moderation returned no results β€” allowing content")
101
- return True
102
  return not resp.results[0].flagged
103
  except Exception as e:
104
- # Log and allow to avoid blocking on moderation outages
105
- logger.warning(f"Moderation API error β€” allowing content. Error: {e}")
106
- return True
107
-
108
 
109
  # ─── SESSION MANAGEMENT ──────────────────────────────────────────────────────────
110
  class SessionData(BaseModel):
 
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
  # ─── SETTINGS ────────────────────────────────────────────────────────────────────
30
  class Settings(BaseSettings):
 
92
  async def moderate_content(text: str) -> bool:
93
  try:
94
  resp = openai_client.moderations.create(input=text)
 
 
 
 
95
  return not resp.results[0].flagged
96
  except Exception as e:
97
+ logger.error(f"Moderation error: {e}")
98
+ return False
 
 
99
 
100
  # ─── SESSION MANAGEMENT ──────────────────────────────────────────────────────────
101
  class SessionData(BaseModel):