mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
partners[lint]: run pyupgrade to get code in line with 3.9 standards (#30781)
Using `pyupgrade` to get all `partners` code up to 3.9 standards (mostly, fixing old `typing` imports).
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import json
|
||||
from typing import (
|
||||
Any,
|
||||
Dict,
|
||||
List,
|
||||
Union,
|
||||
)
|
||||
|
||||
@@ -44,7 +42,7 @@ TOOL_PARAMETER_FORMAT = """<parameter>
|
||||
</parameter>"""
|
||||
|
||||
|
||||
def _get_type(parameter: Dict[str, Any]) -> str:
|
||||
def _get_type(parameter: dict[str, Any]) -> str:
|
||||
if "type" in parameter:
|
||||
return parameter["type"]
|
||||
if "anyOf" in parameter:
|
||||
@@ -54,9 +52,9 @@ def _get_type(parameter: Dict[str, Any]) -> str:
|
||||
return json.dumps(parameter)
|
||||
|
||||
|
||||
def get_system_message(tools: List[Dict]) -> str:
|
||||
def get_system_message(tools: list[dict]) -> str:
|
||||
"""Generate a system message that describes the available tools."""
|
||||
tools_data: List[Dict] = [
|
||||
tools_data: list[dict] = [
|
||||
{
|
||||
"tool_name": tool["name"],
|
||||
"tool_description": tool["description"],
|
||||
@@ -86,13 +84,13 @@ def get_system_message(tools: List[Dict]) -> str:
|
||||
return SYSTEM_PROMPT_FORMAT.format(formatted_tools=tools_formatted)
|
||||
|
||||
|
||||
def _xml_to_dict(t: Any) -> Union[str, Dict[str, Any]]:
|
||||
def _xml_to_dict(t: Any) -> Union[str, dict[str, Any]]:
|
||||
# Base case: If the element has no children, return its text or an empty string.
|
||||
if len(t) == 0:
|
||||
return t.text or ""
|
||||
|
||||
# Recursive case: The element has children. Convert them into a dictionary.
|
||||
d: Dict[str, Any] = {}
|
||||
d: dict[str, Any] = {}
|
||||
for child in t:
|
||||
if child.tag not in d:
|
||||
d[child.tag] = _xml_to_dict(child)
|
||||
@@ -104,7 +102,7 @@ def _xml_to_dict(t: Any) -> Union[str, Dict[str, Any]]:
|
||||
return d
|
||||
|
||||
|
||||
def _xml_to_function_call(invoke: Any, tools: List[Dict]) -> Dict[str, Any]:
|
||||
def _xml_to_function_call(invoke: Any, tools: list[dict]) -> dict[str, Any]:
|
||||
name = invoke.find("tool_name").text
|
||||
arguments = _xml_to_dict(invoke.find("parameters"))
|
||||
|
||||
@@ -135,7 +133,7 @@ def _xml_to_function_call(invoke: Any, tools: List[Dict]) -> Dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _xml_to_tool_calls(elem: Any, tools: List[Dict]) -> List[Dict[str, Any]]:
|
||||
def _xml_to_tool_calls(elem: Any, tools: list[dict]) -> list[dict[str, Any]]:
|
||||
"""
|
||||
Convert an XML element and its children into a dictionary of dictionaries.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user