Skip to content

Commit

Permalink
Merge pull request #94 from ant-xuexiao/refactor/try-to-speed-up-boot…
Browse files Browse the repository at this point in the history
…strap

[WIP] refactor: try to speed up bootstrap
  • Loading branch information
RaoHai authored Apr 23, 2024
2 parents d9ba5a9 + 6f68590 commit ea45180
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
13 changes: 0 additions & 13 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions server/rag/retrieval.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ea45180

Please sign in to comment.