refac: last changes

This commit is contained in:
Ibis Prevedello 2023-02-21 15:57:45 -03:00
commit 63ed529b77
5 changed files with 42 additions and 40 deletions

View file

@ -1,5 +1,5 @@
#! /bin/bash #! /bin/bash
poetry remove langchain poetry remove langchain
docker build -t ibiscp/expert:v0.0.11 . && docker push ibiscp/expert:v0.0.11 docker build -t ibiscp/expert:v0.0.12 . && docker push ibiscp/expert:v0.0.12
poetry add --editable ../langchain poetry add --editable ../langchain

View file

@ -34,4 +34,4 @@ app = create_app()
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) uvicorn.run(app, host="0.0.0.0", port=5003)

View file

@ -12,14 +12,21 @@ import list
# build router # build router
router = APIRouter() router = APIRouter()
AGENT_TYPE = "conversational-react-description"
# define endpoints -> /chain, /agent, /memory, /prompt
# return a dict def get_type_list():
all = get_all()
all.pop("tools")
for key, value in all.items():
all[key] = [item["template"]["_type"] for item in value.values()]
return all
@router.get("/") @router.get("/")
def get_all(): def get_all():
# tools = list.list_tools()
return { return {
"chains": {chain: signature.chain(chain) for chain in list.list_chains()}, "chains": {chain: signature.chain(chain) for chain in list.list_chains()},
"agents": {agent: signature.agent(agent) for agent in list.list_agents()}, "agents": {agent: signature.agent(agent) for agent in list.list_agents()},
@ -49,30 +56,12 @@ def get_all():
} }
@router.post("/load") @router.post("/predict")
def get_load(data: dict[str, str]) -> str: def get_load(data: dict[str, str]):
return "Hello Otávio!" a = get_type_list()
# Build json
# @router.get("/chain") # if type in a["prompts"]:
# def get_chain():
# llm = OpenAI(temperature=0)
# chain = DictableChain(llm=llm)
# return chain.to_dict()
return a
# @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"}

View file

@ -167,7 +167,7 @@ def tool(name: str):
"list": False, "list": False,
"show": True, "show": True,
"placeholder": "", "placeholder": "",
"default": "", "value": "",
}, },
"llm": {"type": "BaseLLM", "required": True, "list": False, "show": True}, "llm": {"type": "BaseLLM", "required": True, "list": False, "show": True},
} }
@ -183,11 +183,14 @@ def tool(name: str):
_, extra_keys = _EXTRA_OPTIONAL_TOOLS[name] _, extra_keys = _EXTRA_OPTIONAL_TOOLS[name]
params = extra_keys params = extra_keys
return { template = {
"template": {
param: (type_dict[param] if param == "llm" else type_dict["str"]) param: (type_dict[param] if param == "llm" else type_dict["str"])
for param in params for param in params
}, }
template["_type"] = name
return {
"template": template,
**util.get_tool_params(util.get_tools_dict(name)), **util.get_tool_params(util.get_tools_dict(name)),
"base_classes": ["Tool"], "base_classes": ["Tool"],
} }

View file

@ -157,14 +157,24 @@ def format_dict(d):
# Show if required # Show if required
value["show"] = bool( value["show"] = bool(
(value["required"] and key not in ["input_variables"]) (value["required"] and key not in ["input_variables"])
or key in ["allowed_tools", "verbose", "Memory", "memory", "prefix"] or key
in ["allowed_tools", "verbose", "Memory", "memory", "prefix", "examples"]
or "api_key" in key or "api_key" in key
) )
# Add multline
if key in ["suffix", "prefix", "template", "examples"]:
value["multline"] = True
else:
value["multline"] = False
# Replace default value with actual value # Replace default value with actual value
if _type in ["str", "bool"]: # if _type in ["str", "bool"]:
value["value"] = value.get("default", "") # value["value"] = value.get("default", "")
# if "default" in value:
# value.pop("default")
if "default" in value: if "default" in value:
value["value"] = value["default"]
value.pop("default") value.pop("default")
# Filter out keys that should not be shown # Filter out keys that should not be shown