feat: adding mock endpoints for testing
GET endpoints to provide data to the frontend #3
This commit is contained in:
parent
c5c5230520
commit
75d1a003dc
2 changed files with 53 additions and 0 deletions
37
src/endpoints.py
Normal file
37
src/endpoints.py
Normal file
|
|
@ -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"}
|
||||||
16
src/main.py
Normal file
16
src/main.py
Normal file
|
|
@ -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)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue