mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 07:42:40 +00:00
Fix linting errors in tool_usage.py
- Remove unnecessary variable assignments before return statements - Convert loop to list comprehension for better performance - Addresses RET504 and PERF401 linting errors Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -130,8 +130,7 @@ class ToolUsage:
|
|||||||
and tool.name == self._i18n.tools("add_image")["name"] # type: ignore
|
and tool.name == self._i18n.tools("add_image")["name"] # type: ignore
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
result = self._use(tool_string=tool_string, tool=tool, calling=calling)
|
return self._use(tool_string=tool_string, tool=tool, calling=calling)
|
||||||
return result
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error = getattr(e, "message", str(e))
|
error = getattr(e, "message", str(e))
|
||||||
@@ -159,8 +158,7 @@ class ToolUsage:
|
|||||||
tool_name=tool.name,
|
tool_name=tool.name,
|
||||||
attempts=self._run_attempts,
|
attempts=self._run_attempts,
|
||||||
)
|
)
|
||||||
result = self._format_result(result=result) # type: ignore # "_format_result" of "ToolUsage" does not return a value (it only ever returns None)
|
return self._format_result(result=result) # type: ignore # "_format_result" of "ToolUsage" does not return a value (it only ever returns None)
|
||||||
return result # type: ignore # Fix the return type of this function
|
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if self.task:
|
if self.task:
|
||||||
@@ -207,8 +205,7 @@ class ToolUsage:
|
|||||||
try:
|
try:
|
||||||
result = usage_limit_error
|
result = usage_limit_error
|
||||||
self._telemetry.tool_usage_error(llm=self.function_calling_llm)
|
self._telemetry.tool_usage_error(llm=self.function_calling_llm)
|
||||||
result = self._format_result(result=result)
|
return self._format_result(result=result)
|
||||||
return result
|
|
||||||
except Exception:
|
except Exception:
|
||||||
if self.task:
|
if self.task:
|
||||||
self.task.increment_tools_errors()
|
self.task.increment_tools_errors()
|
||||||
@@ -431,9 +428,7 @@ class ToolUsage:
|
|||||||
|
|
||||||
def _render(self) -> str:
|
def _render(self) -> str:
|
||||||
"""Render the tool name and description in plain text."""
|
"""Render the tool name and description in plain text."""
|
||||||
descriptions = []
|
descriptions = [tool.description for tool in self.tools]
|
||||||
for tool in self.tools:
|
|
||||||
descriptions.append(tool.description)
|
|
||||||
return "\n--\n".join(descriptions)
|
return "\n--\n".join(descriptions)
|
||||||
|
|
||||||
def _function_calling(
|
def _function_calling(
|
||||||
|
|||||||
Reference in New Issue
Block a user