huggingface: fix tool argument serialization in _convert_TGI_message_to_LC_message (#26075)

Currently `_convert_TGI_message_to_LC_message` replaces `'` in the tool
arguments, so an argument like "It's" will be converted to `It"s` and
could cause a json parser to fail.

---------

Signed-off-by: Wang, Yi A <yi.a.wang@intel.com>
Co-authored-by: Erick Friis <erick@langchain.dev>
Co-authored-by: Vadym Barda <vadym@langchain.dev>
This commit is contained in:
Wang, Yi
2024-12-12 10:34:32 +08:00
committed by GitHub
parent 5a31792bf1
commit d834c6b618
2 changed files with 23 additions and 4 deletions

View File

@@ -66,7 +66,7 @@ def test_convert_message_to_chat_message(
TGI_MESSAGE(
role="assistant",
content="",
tool_calls=[{"function": {"arguments": "'function string'"}}],
tool_calls=[{"function": {"arguments": "function string"}}],
),
AIMessage(
content="",
@@ -75,6 +75,23 @@ def test_convert_message_to_chat_message(
},
),
),
(
TGI_MESSAGE(
role="assistant",
content="",
tool_calls=[
{"function": {"arguments": {"answer": "function's string"}}}
],
),
AIMessage(
content="",
additional_kwargs={
"tool_calls": [
{"function": {"arguments": '{"answer": "function\'s string"}'}}
]
},
),
),
],
)
def test_convert_TGI_message_to_LC_message(