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 fastapi import FastAPI, responses |
| #2 | from pydantic import BaseModel |
| #3 | |
| #4 | from embedchain import App |
| #5 | |
| #6 | app = FastAPI(title="Embedchain FastAPI App") |
| #7 | embedchain_app = App() |
| #8 | |
| #9 | |
| #10 | class SourceModel(BaseModel): |
| #11 | source: str |
| #12 | |
| #13 | |
| #14 | class QuestionModel(BaseModel): |
| #15 | question: str |
| #16 | |
| #17 | |
| #18 | @app.post("/add") |
| #19 | async def add_source(source_model: SourceModel): |
| #20 | """ |
| #21 | Adds a new source to the EmbedChain app. |
| #22 | Expects a JSON with a "source" key. |
| #23 | """ |
| #24 | source = source_model.source |
| #25 | embedchain_app.add(source) |
| #26 | return {"message": f"Source '{source}' added successfully."} |
| #27 | |
| #28 | |
| #29 | @app.post("/query") |
| #30 | async def handle_query(question_model: QuestionModel): |
| #31 | """ |
| #32 | Handles a query to the EmbedChain app. |
| #33 | Expects a JSON with a "question" key. |
| #34 | """ |
| #35 | question = question_model.question |
| #36 | answer = embedchain_app.query(question) |
| #37 | return {"answer": answer} |
| #38 | |
| #39 | |
| #40 | @app.post("/chat") |
| #41 | async def handle_chat(question_model: QuestionModel): |
| #42 | """ |
| #43 | Handles a chat request to the EmbedChain app. |
| #44 | Expects a JSON with a "question" key. |
| #45 | """ |
| #46 | question = question_model.question |
| #47 | response = embedchain_app.chat(question) |
| #48 | return {"response": response} |
| #49 | |
| #50 | |
| #51 | @app.get("/") |
| #52 | async def root(): |
| #53 | return responses.RedirectResponse(url="/docs") |
| #54 |