refac: small fixes

This commit is contained in:
ogabrielluiz 2023-03-07 14:22:41 -03:00
commit 0e5078b5f5
2 changed files with 6 additions and 3 deletions

View file

@ -1,3 +1,4 @@
from typing import Any, Dict
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
from langchain import agents, chains, llms, prompts from langchain import agents, chains, llms, prompts
from langchain.agents.load_tools import ( from langchain.agents.load_tools import (
@ -131,11 +132,13 @@ def get_tool(name: str):
elif tool_type in _EXTRA_OPTIONAL_TOOLS: elif tool_type in _EXTRA_OPTIONAL_TOOLS:
_, extra_keys = _EXTRA_OPTIONAL_TOOLS[tool_type] _, extra_keys = _EXTRA_OPTIONAL_TOOLS[tool_type]
params = extra_keys params = extra_keys
else:
params = []
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
} } # type: Dict[str, Any]
template["_type"] = tool_type template["_type"] = tool_type
return { return {

View file

@ -113,8 +113,8 @@ def get_default_factory(module: str, function: str):
pattern = r"<function (\w+)>" pattern = r"<function (\w+)>"
if match := re.search(pattern, function): if match := re.search(pattern, function):
module = importlib.import_module(module) imported_module = importlib.import_module(module)
return getattr(module, match[1])() return getattr(imported_module, match[1])()
return None return None