diff --git a/src/endpoints.py b/src/endpoints.py new file mode 100644 index 000000000..d2d027e20 --- /dev/null +++ b/src/endpoints.py @@ -0,0 +1,37 @@ +from fastapi import APIRouter, FastAPI +from langchain import OpenAI +from langchain.agents import initialize_agent +from interface import ( + DictableChain, + DictableConversationalAgent, + DictableMemory, + DictableTool, +) + +# build router +router = APIRouter() +AGENT_TYPE = "conversational-react-description" +# define endpoints -> /chain, /agent, /memory, /prompt +# return a dict +@router.get("/chain") +def get_chain(): + llm = OpenAI(temperature=0) + chain = DictableChain(llm=llm) + return chain.to_dict() + + +@router.get("/agent") +def get_agent(): + tools = [DictableTool(name="test", description="test", func=lambda x: x)] + llm = OpenAI(temperature=0) + return initialize_agent(llm=llm, tools=tools, memory=DictableMemory()).__dict__ + + +@router.get("/memory") +def get_memory(): + return DictableMemory().to_dict() + + +@router.get("/prompt") +def get_prompt(): + return {"template": "template", "input_variables": "input_variables"} diff --git a/src/main.py b/src/main.py new file mode 100644 index 000000000..a8e95df49 --- /dev/null +++ b/src/main.py @@ -0,0 +1,16 @@ +from fastapi import FastAPI +from endpoints import router + + +def create_app(): + """Create the FastAPI app and include the router.""" + app = FastAPI() + app.include_router(router) + return app + + +if __name__ == "__main__": + import uvicorn + + app = create_app() + uvicorn.run(app)