From 05d583b367af41099cccbab902fc057b589303e6 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 23 Apr 2024 14:41:19 +0800 Subject: [PATCH 1/2] refactor: try to speedup bootstrap ; --- server/rag/retrieval.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/rag/retrieval.py b/server/rag/retrieval.py index ed9a8ee3..1709d83c 100644 --- a/server/rag/retrieval.py +++ b/server/rag/retrieval.py @@ -1,13 +1,9 @@ import json -import boto3 from langchain_openai import OpenAIEmbeddings -from langchain_text_splitters import CharacterTextSplitter from langchain_community.vectorstores import SupabaseVectorStore from db.supabase.client import get_client from data_class import S3Config from uilts.env import get_env_variable -from langchain_community.document_loaders import S3DirectoryLoader - supabase_url = get_env_variable("SUPABASE_URL") supabase_key = get_env_variable("SUPABASE_SERVICE_KEY") @@ -39,6 +35,9 @@ def init_retriever(): def add_knowledge(config: S3Config): + from langchain_community.document_loaders import S3DirectoryLoader + from langchain_text_splitters import CharacterTextSplitter + try: loader = S3DirectoryLoader(config.s3_bucket, prefix=config.file_path) documents = loader.load() From 6f68590ce12fcd29770b9af6f41e93f749437939 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Tue, 23 Apr 2024 15:00:58 +0800 Subject: [PATCH 2/2] remove cors middlewares --- server/main.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/server/main.py b/server/main.py index 5478f52d..4e1e2ca4 100644 --- a/server/main.py +++ b/server/main.py @@ -3,7 +3,6 @@ import uvicorn from fastapi import FastAPI from fastapi.responses import StreamingResponse -from fastapi.middleware.cors import CORSMiddleware from agent import stream @@ -22,28 +21,16 @@ description="Agent Chat APIs" ) -app.add_middleware( - CORSMiddleware, - allow_origins=["*"], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], - expose_headers=["*"], -) - app.include_router(health_checker.router) app.include_router(github.router) app.include_router(rag.router) app.include_router(bot.router) - @app.post("/api/chat/stream", response_class=StreamingResponse) def run_agent_chat(input_data: ChatData): result = stream.agent_chat(input_data, open_api_key) return StreamingResponse(result, media_type="text/event-stream") - - if __name__ == "__main__": if is_dev: uvicorn.run("main:app", host="0.0.0.0", port=int(os.environ.get("PORT", "8080")), reload=True)