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
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

View file

@ -34,4 +34,4 @@ app = create_app()
if __name__ == "__main__":
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
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("/")
def get_all():
# tools = list.list_tools()
return {
"chains": {chain: signature.chain(chain) for chain in list.list_chains()},
"agents": {agent: signature.agent(agent) for agent in list.list_agents()},
@ -49,30 +56,12 @@ def get_all():
}
@router.post("/load")
def get_load(data: dict[str, str]) -> str:
return "Hello Otávio!"
@router.post("/predict")
def get_load(data: dict[str, str]):
a = get_type_list()
# Build json
# @router.get("/chain")
# def get_chain():
# llm = OpenAI(temperature=0)
# chain = DictableChain(llm=llm)
# return chain.to_dict()
# if type in a["prompts"]:
# @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"}
return a

View file

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

View file

@ -157,15 +157,25 @@ def format_dict(d):
# Show if required
value["show"] = bool(
(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
)
# Add multline
if key in ["suffix", "prefix", "template", "examples"]:
value["multline"] = True
else:
value["multline"] = False
# Replace default value with actual value
if _type in ["str", "bool"]:
value["value"] = value.get("default", "")
if "default" in value:
value.pop("default")
# if _type in ["str", "bool"]:
# value["value"] = value.get("default", "")
# if "default" in value:
# value.pop("default")
if "default" in value:
value["value"] = value["default"]
value.pop("default")
# Filter out keys that should not be shown
return (