mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-15 07:36:08 +00:00
add test
This commit is contained in:
parent
a3799b2caf
commit
06f240b328
@ -1,5 +1,6 @@
|
||||
"""Unit tests for ChatOllamaV1."""
|
||||
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, patch
|
||||
@ -23,6 +24,7 @@ from langchain_ollama._compat import (
|
||||
)
|
||||
from langchain_ollama.chat_models_v1 import (
|
||||
ChatOllamaV1,
|
||||
_parse_arguments_from_tool_call,
|
||||
_parse_json_string,
|
||||
)
|
||||
|
||||
@ -280,6 +282,24 @@ def test_parse_json_string_skip_returns_input_on_failure() -> None:
|
||||
assert result == malformed_string
|
||||
|
||||
|
||||
def test__parse_arguments_from_tool_call() -> None:
|
||||
"""Test that string arguments are preserved as strings in tool call parsing.
|
||||
|
||||
This test verifies the fix for PR #30154 which addressed an issue where
|
||||
string-typed tool arguments (like IDs or long strings) were being incorrectly
|
||||
processed. The parser should preserve string values as strings rather than
|
||||
attempting to parse them as JSON when they're already valid string arguments.
|
||||
|
||||
The test uses a long string ID to ensure string arguments maintain their
|
||||
original type after parsing, which is critical for tools expecting string inputs.
|
||||
"""
|
||||
raw_response = '{"model":"sample-model","message":{"role":"assistant","content":"","tool_calls":[{"function":{"name":"get_profile_details","arguments":{"arg_1":"12345678901234567890123456"}}}]},"done":false}' # noqa: E501
|
||||
raw_tool_calls = json.loads(raw_response)["message"]["tool_calls"]
|
||||
response = _parse_arguments_from_tool_call(raw_tool_calls[0])
|
||||
assert response is not None
|
||||
assert isinstance(response["arg_1"], str)
|
||||
|
||||
|
||||
def test_load_response_with_empty_content_is_skipped(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user