repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | from dotenv import load_dotenv |
| #2 | from fastapi import Body, FastAPI, responses |
| #3 | from modal import Image, Secret, Stub, asgi_app |
| #4 | |
| #5 | from embedchain import App |
| #6 | |
| #7 | load_dotenv(".env") |
| #8 | |
| #9 | image = Image.debian_slim().pip_install( |
| #10 | "embedchain", |
| #11 | "lanchain_community==0.2.6", |
| #12 | "youtube-transcript-api==0.6.1", |
| #13 | "pytube==15.0.0", |
| #14 | "beautifulsoup4==4.12.3", |
| #15 | "slack-sdk==3.21.3", |
| #16 | "huggingface_hub==0.23.0", |
| #17 | "gitpython==3.1.38", |
| #18 | "yt_dlp==2023.11.14", |
| #19 | "PyGithub==1.59.1", |
| #20 | "feedparser==6.0.10", |
| #21 | "newspaper3k==0.2.8", |
| #22 | "listparser==0.19", |
| #23 | ) |
| #24 | |
| #25 | stub = Stub( |
| #26 | name="embedchain-app", |
| #27 | image=image, |
| #28 | secrets=[Secret.from_dotenv(".env")], |
| #29 | ) |
| #30 | |
| #31 | web_app = FastAPI() |
| #32 | embedchain_app = App(name="embedchain-modal-app") |
| #33 | |
| #34 | |
| #35 | @web_app.post("/add") |
| #36 | async def add( |
| #37 | source: str = Body(..., description="Source to be added"), |
| #38 | data_type: str | None = Body(None, description="Type of the data source"), |
| #39 | ): |
| #40 | """ |
| #41 | Adds a new source to the EmbedChain app. |
| #42 | Expects a JSON with a "source" and "data_type" key. |
| #43 | "data_type" is optional. |
| #44 | """ |
| #45 | if source and data_type: |
| #46 | embedchain_app.add(source, data_type) |
| #47 | elif source: |
| #48 | embedchain_app.add(source) |
| #49 | else: |
| #50 | return {"message": "No source provided."} |
| #51 | return {"message": f"Source '{source}' added successfully."} |
| #52 | |
| #53 | |
| #54 | @web_app.post("/query") |
| #55 | async def query(question: str = Body(..., description="Question to be answered")): |
| #56 | """ |
| #57 | Handles a query to the EmbedChain app. |
| #58 | Expects a JSON with a "question" key. |
| #59 | """ |
| #60 | if not question: |
| #61 | return {"message": "No question provided."} |
| #62 | answer = embedchain_app.query(question) |
| #63 | return {"answer": answer} |
| #64 | |
| #65 | |
| #66 | @web_app.get("/chat") |
| #67 | async def chat(question: str = Body(..., description="Question to be answered")): |
| #68 | """ |
| #69 | Handles a chat request to the EmbedChain app. |
| #70 | Expects a JSON with a "question" key. |
| #71 | """ |
| #72 | if not question: |
| #73 | return {"message": "No question provided."} |
| #74 | response = embedchain_app.chat(question) |
| #75 | return {"response": response} |
| #76 | |
| #77 | |
| #78 | @web_app.get("/") |
| #79 | async def root(): |
| #80 | return responses.RedirectResponse(url="/docs") |
| #81 | |
| #82 | |
| #83 | @stub.function(image=image) |
| #84 | @asgi_app() |
| #85 | def fastapi_app(): |
| #86 | return web_app |
| #87 |