From dd42c7342fbbb3e1712ed7c6b13c87373c9faae9 Mon Sep 17 00:00:00 2001 From: Yifei Wang <1277495324@qq.com> Date: Fri, 31 Jan 2025 14:42:21 -0800 Subject: [PATCH] Added more comments for function calling. --- nexa/gguf/nexa_inference_text.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nexa/gguf/nexa_inference_text.py b/nexa/gguf/nexa_inference_text.py index 7cac1e56..eb18d686 100644 --- a/nexa/gguf/nexa_inference_text.py +++ b/nexa/gguf/nexa_inference_text.py @@ -419,6 +419,10 @@ def process_output(output): for item in output: if "function" in item and isinstance(item["function"], dict): try: + # llama-cpp-python's `create_chat_completion` produces incorrectly parsed output when only + # `messages` and `tools` are provided. Specifically, the function name is mistakenly treated + # as an argument, while the `function.name` field is an empty string. + # The following code corrects this issue. function_data = json.loads(item["function"]["arguments"]) function_name = function_data.get("function", "") function_args = {k: v for k, v in function_data.items() if k not in ['type', 'function']}