* feature(intelligent-search): Added API to connect to Llama.cpp in EC2 and filter the response into OR filters * updated sql to filter script and added init.sql for tables * feature(intelligent-search): Changed llama.cpp for llama in GPU now contained in API * Updated Dockerfile to use GPU and download LLM from S3 * Added link to facebook/research/llama * Updated Dockerfile * Updated requirements and Dockerfile base images * fixed minor issues: Not used variables, updated COPY and replace values * fix(intelligent-search): Fixed WHERE statement filter * feature(smart-charts): Added method to create charts using llama. style(intelligent-search): Changed names for attributes to match frontend format. fix(intelligent-search): Fixed vulnerability in requiments and small issues fix * Added some test before deploying the service * Added semaphore to handle concurrency --------- Co-authored-by: EC2 Default User <ec2-user@ip-10-0-2-226.eu-central-1.compute.internal>
33 lines
854 B
Python
33 lines
854 B
Python
from fastapi.security import OAuth2PasswordBearer
|
|
from fastapi import HTTPException, Depends, status
|
|
from decouple import config
|
|
|
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
|
|
|
|
|
|
class AuthHandler:
|
|
def __init__(self):
|
|
"""
|
|
Authorization method using an API key.
|
|
"""
|
|
self.__api_keys = [config("LLAMA_API_AUTH_KEY")]
|
|
|
|
def __contains__(self, api_key):
|
|
return api_key in self.__api_keys
|
|
|
|
def add_key(self, key):
|
|
"""Adds new key for authentication."""
|
|
self.__api_keys.append(key)
|
|
|
|
|
|
auth_method = AuthHandler()
|
|
|
|
|
|
def api_key_auth(api_key: str = Depends(oauth2_scheme)):
|
|
"""Method to verify auth."""
|
|
global auth_method
|
|
if api_key not in auth_method:
|
|
raise HTTPException(
|
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
|
detail="Forbidden"
|
|
)
|