diff --git a/interpreter/core/async_core.py b/interpreter/core/async_core.py index 8c6096598c..df56f3725b 100644 --- a/interpreter/core/async_core.py +++ b/interpreter/core/async_core.py @@ -17,8 +17,18 @@ try: import janus import uvicorn - from fastapi import APIRouter, FastAPI, File, Form, UploadFile, WebSocket - from fastapi.responses import PlainTextResponse, StreamingResponse + from fastapi import ( + APIRouter, + FastAPI, + File, + Form, + HTTPException, + Request, + UploadFile, + WebSocket, + ) + from fastapi.responses import JSONResponse, PlainTextResponse, StreamingResponse + from starlette.status import HTTP_403_FORBIDDEN except: # Server dependencies are not required by the main package. pass @@ -204,6 +214,24 @@ def accumulate(self, chunk): self.messages[-1]["content"] += chunk +def authenticate_function(key): + """ + This function checks if the provided key is valid for authentication. + + Returns True if the key is valid, False otherwise. + """ + # Fetch the API key from the environment variables. If it's not set, return True. + api_key = os.getenv("INTERPRETER_API_KEY", None) + + # If the API key is not set in the environment variables, return True. + # Otherwise, check if the provided key matches the fetched API key. + # Return True if they match, False otherwise. + if api_key is None: + return True + else: + return key == api_key + + def create_router(async_interpreter): router = APIRouter() @@ -226,6 +254,7 @@ async def home(): +