feat: add template
This commit is contained in:
parent
4bb76ed218
commit
95e99899cc
2 changed files with 89 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from endpoints import router as endpoints_router
|
from endpoints import router as endpoints_router
|
||||||
from list import router as list_router
|
from list import router as list_router
|
||||||
|
from templates import router as templates_router
|
||||||
|
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
|
|
@ -8,6 +9,7 @@ def create_app():
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
app.include_router(endpoints_router)
|
app.include_router(endpoints_router)
|
||||||
app.include_router(list_router)
|
app.include_router(list_router)
|
||||||
|
app.include_router(templates_router)
|
||||||
return app
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
87
src/templates.py
Normal file
87
src/templates.py
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
from langchain import chains
|
||||||
|
from langchain import agents
|
||||||
|
from langchain import prompts
|
||||||
|
from langchain import llms
|
||||||
|
from langchain import utilities
|
||||||
|
from langchain.chains.conversation import memory
|
||||||
|
|
||||||
|
|
||||||
|
# build router
|
||||||
|
router = APIRouter(
|
||||||
|
prefix="/templates",
|
||||||
|
tags=["templates"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/chain")
|
||||||
|
def chain(name: str):
|
||||||
|
# Raise error if name is not in chains
|
||||||
|
if name not in chains.__all__:
|
||||||
|
raise Exception(f"Prompt {name} not found.")
|
||||||
|
_class = getattr(chains, name)
|
||||||
|
return {
|
||||||
|
name: {name: value for (name, value) in value.__repr_args__() if name != "name"}
|
||||||
|
for name, value in _class.__dict__["__fields__"].items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/agent")
|
||||||
|
def agent(name: str):
|
||||||
|
# Raise error if name is not in agents
|
||||||
|
if name not in agents.__all__:
|
||||||
|
raise Exception(f"Prompt {name} not found.")
|
||||||
|
_class = getattr(agents, name)
|
||||||
|
return {
|
||||||
|
name: {name: value for (name, value) in value.__repr_args__() if name != "name"}
|
||||||
|
for name, value in _class.__dict__["__fields__"].items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/prompt")
|
||||||
|
def prompt(name: str):
|
||||||
|
# Raise error if name is not in prompts
|
||||||
|
if name not in prompts.__all__:
|
||||||
|
raise Exception(f"Prompt {name} not found.")
|
||||||
|
_class = getattr(prompts, name)
|
||||||
|
return {
|
||||||
|
name: {name: value for (name, value) in value.__repr_args__() if name != "name"}
|
||||||
|
for name, value in _class.__dict__["__fields__"].items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/llm")
|
||||||
|
def llm(name: str):
|
||||||
|
# Raise error if name is not in llms
|
||||||
|
if name not in llms.__all__:
|
||||||
|
raise Exception(f"Prompt {name} not found.")
|
||||||
|
_class = getattr(llms, name)
|
||||||
|
return {
|
||||||
|
name: {name: value for (name, value) in value.__repr_args__() if name != "name"}
|
||||||
|
for name, value in _class.__dict__["__fields__"].items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/utility")
|
||||||
|
def utility(name: str):
|
||||||
|
# Raise error if name is not in utilities
|
||||||
|
if name not in utilities.__all__:
|
||||||
|
raise Exception(f"Prompt {name} not found.")
|
||||||
|
_class = getattr(utilities, name)
|
||||||
|
return {
|
||||||
|
name: {name: value for (name, value) in value.__repr_args__() if name != "name"}
|
||||||
|
for name, value in _class.__dict__["__fields__"].items()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/memory")
|
||||||
|
def memory(name: str):
|
||||||
|
# Raise error if name is not in memory
|
||||||
|
if name not in memory.__all__:
|
||||||
|
raise Exception(f"Prompt {name} not found.")
|
||||||
|
_class = getattr(memory, name)
|
||||||
|
return {
|
||||||
|
name: {name: value for (name, value) in value.__repr_args__() if name != "name"}
|
||||||
|
for name, value in _class.__dict__["__fields__"].items()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue