diff --git a/extensions/HuggingFace/python/src/aiconfig_extension_hugging_face/local_inference/text_generation.py b/extensions/HuggingFace/python/src/aiconfig_extension_hugging_face/local_inference/text_generation.py index 3a8fec730..c87c8ca3e 100644 --- a/extensions/HuggingFace/python/src/aiconfig_extension_hugging_face/local_inference/text_generation.py +++ b/extensions/HuggingFace/python/src/aiconfig_extension_hugging_face/local_inference/text_generation.py @@ -129,9 +129,10 @@ def construct_stream_output( ) accumulated_message = "" for new_text in streamer: - accumulated_message += new_text - options.stream_callback(new_text, accumulated_message, 0) - output.data = accumulated_message + if isinstance(new_text, str): + accumulated_message += new_text + options.stream_callback(new_text, accumulated_message, 0) + output.data = accumulated_message return output diff --git a/extensions/LLama-Guard/python/python/src/aiconfig_extension_llama_guard/LLamaGuard.py b/extensions/LLama-Guard/python/python/src/aiconfig_extension_llama_guard/LLamaGuard.py index 82bca49a1..34d8233ef 100644 --- a/extensions/LLama-Guard/python/python/src/aiconfig_extension_llama_guard/LLamaGuard.py +++ b/extensions/LLama-Guard/python/python/src/aiconfig_extension_llama_guard/LLamaGuard.py @@ -245,10 +245,15 @@ async def run_inference( output_text = self.tokenizer.decode( response[0][prompt_len:], skip_special_tokens=True ) + output_data_content: str = '' + if isinstance(output_text, str): + output_data_content = output_text + else: + raise ValueError(f"Output {output_text} needs to be of type 'str' but is of type: {type(output_text)}") output = ExecuteResult( **{ "output_type": "execute_result", - "data": output_text, + "data": output_data_content, "execution_count": 0, "metadata": {}, } diff --git a/extensions/llama/python/llama.py b/extensions/llama/python/llama.py index c16d53710..fc41d6ff7 100644 --- a/extensions/llama/python/llama.py +++ b/extensions/llama/python/llama.py @@ -87,9 +87,15 @@ async def _run_inference_helper(self, model_input, options) -> List[Output]: if options: options.stream_callback(data, acc, index) print(flush=True) + + output_data_value: str = '' + if isinstance(acc, str): + output_data_value = acc + else: + raise ValueError(f"Output {acc} needs to be of type 'str' but is of type: {type(acc)}") return ExecuteResult( output_type="execute_result", - data=acc, + data=output_data_value, metadata={} ) else: