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