Skip to content

Commit

Permalink
change format
Browse files Browse the repository at this point in the history
  • Loading branch information
Lycnkd committed Dec 25, 2024
1 parent 5da0dfc commit f8d8830
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions libs/core/langchain_core/messages/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,18 @@ class ToolCall(TypedDict):


def tool_call(*, name: str, args: dict[str, Any], id: Optional[str]) -> ToolCall:
if isinstance(args, str):
try:
# Extract JSON-like dictionary from string using regex
match = re.search(r'\{.*\}', args)
if match:
try:
return ToolCall(name=name, args=args, id=id, type="tool_call")
except:

Check failure on line 215 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (E722)

langchain_core/messages/tool.py:215:5: E722 Do not use bare `except`

Check failure on line 215 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (E722)

langchain_core/messages/tool.py:215:5: E722 Do not use bare `except`

Check failure on line 215 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (E722)

langchain_core/messages/tool.py:215:5: E722 Do not use bare `except`

Check failure on line 215 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (E722)

langchain_core/messages/tool.py:215:5: E722 Do not use bare `except`

Check failure on line 215 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (E722)

langchain_core/messages/tool.py:215:5: E722 Do not use bare `except`
# Attempt to extract JSON-like dictionary from string using regex
match = re.search(r'\{.*\}', args)

Check failure on line 217 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (Q000)

langchain_core/messages/tool.py:217:27: Q000 Single quotes found but double quotes preferred

Check failure on line 217 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (Q000)

langchain_core/messages/tool.py:217:27: Q000 Single quotes found but double quotes preferred

Check failure on line 217 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (Q000)

langchain_core/messages/tool.py:217:27: Q000 Single quotes found but double quotes preferred

Check failure on line 217 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (Q000)

langchain_core/messages/tool.py:217:27: Q000 Single quotes found but double quotes preferred

Check failure on line 217 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (Q000)

langchain_core/messages/tool.py:217:27: Q000 Single quotes found but double quotes preferred
if match:
try:
args = json.loads(match.group())
else:
raise ValueError("No valid JSON object found in args string")
except json.JSONDecodeError:
raise ValueError("Invalid JSON string for args")
return ToolCall(name=name, args=args, id=id, type="tool_call")
except json.JSONDecodeError:
pass

Check failure on line 222 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.11

Ruff (SIM105)

langchain_core/messages/tool.py:219:13: SIM105 Use `contextlib.suppress(json.JSONDecodeError)` instead of `try`-`except`-`pass`

Check failure on line 222 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.9

Ruff (SIM105)

langchain_core/messages/tool.py:219:13: SIM105 Use `contextlib.suppress(json.JSONDecodeError)` instead of `try`-`except`-`pass`

Check failure on line 222 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.12

Ruff (SIM105)

langchain_core/messages/tool.py:219:13: SIM105 Use `contextlib.suppress(json.JSONDecodeError)` instead of `try`-`except`-`pass`

Check failure on line 222 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.10

Ruff (SIM105)

langchain_core/messages/tool.py:219:13: SIM105 Use `contextlib.suppress(json.JSONDecodeError)` instead of `try`-`except`-`pass`

Check failure on line 222 in libs/core/langchain_core/messages/tool.py

View workflow job for this annotation

GitHub Actions / cd libs/core / make lint #3.13

Ruff (SIM105)

langchain_core/messages/tool.py:219:13: SIM105 Use `contextlib.suppress(json.JSONDecodeError)` instead of `try`-`except`-`pass`
return ToolCall(name=name, args=args, id=id, type="tool_call")



class ToolCallChunk(TypedDict):
Expand Down

0 comments on commit f8d8830

Please sign in to comment.