abanm commited on
Commit
249c38e
·
verified ·
1 Parent(s): e026944

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -25,7 +25,7 @@ app.add_middleware(
25
  )
26
 
27
  # Load your API key from the environment (defaults to "change_me")
28
- OLLAMA_API_KEY = os.environ.get("API_KEY", "change_me")
29
 
30
  @app.post("/api/generate")
31
  async def generate(request: Request):
@@ -38,7 +38,7 @@ async def generate(request: Request):
38
  raise HTTPException(status_code=401, detail="Missing or invalid Authorization header")
39
 
40
  token = auth_header.split(" ")[1]
41
- if token != OLLAMA_API_KEY:
42
  raise HTTPException(status_code=401, detail="Invalid API key")
43
 
44
  # 2. Parse the request JSON
@@ -62,7 +62,7 @@ async def generate(request: Request):
62
  stderr=subprocess.PIPE,
63
  text=True
64
  )
65
- output, error = process.communicate(timeout=60) # Timeout after 60 seconds
66
 
67
  if process.returncode != 0:
68
  logger.error(f"Ollama Error: {error.strip()}")
 
25
  )
26
 
27
  # Load your API key from the environment (defaults to "change_me")
28
+ API_KEY = os.environ.get("API_KEY", "change_me")
29
 
30
  @app.post("/api/generate")
31
  async def generate(request: Request):
 
38
  raise HTTPException(status_code=401, detail="Missing or invalid Authorization header")
39
 
40
  token = auth_header.split(" ")[1]
41
+ if token != API_KEY:
42
  raise HTTPException(status_code=401, detail="Invalid API key")
43
 
44
  # 2. Parse the request JSON
 
62
  stderr=subprocess.PIPE,
63
  text=True
64
  )
65
+ output, error = process.communicate(timeout=600) # Timeout after 60 seconds
66
 
67
  if process.returncode != 0:
68
  logger.error(f"Ollama Error: {error.strip()}")