code: def test_generate_text_with_streaming_callback(
      self,
      mock_check_valid_model,
      mock_auto_tokenizer,
      mock_text_generation,
      chat_messages,
  ):
      streaming_call_count = 0
  
      # Define the streaming callback function
      def streaming_callback_fn(chunk: StreamingChunk):
          nonlocal streaming_call_count
          streaming_call_count += 1
          assert isinstance(chunk, StreamingChunk)
  
      # Create an instance of HuggingFaceRemoteGenerator
      generator = HuggingFaceTGIChatGenerator(
          streaming_callback=streaming_callback_fn
      )
      generator.warm_up()
  
      # Create a fake streamed response
      # self needed here, don't remove
      def mock_iter(self):
          yield TextGenerationStreamResponse(
              generated_text=None,
              token=Token(
                  id=1,
                  text="I'm fine, thanks.",
                  logprob=0.0,
                  special=False,
              ),
          )
          yield TextGenerationStreamResponse(
              generated_text=None,
              token=Token(
                  id=1, text="Ok bye", logprob=0.0, special=False
              ),
              details=StreamDetails(
                  finish_reason=FinishReason.Length, generated_tokens=5
              ),
          )
  
      mock_response = Mock(**{"__iter__": mock_iter})
      mock_text_generation.return_value = mock_response
  
      # Generate text response with streaming callback
      response = generator.run(chat_messages)
  
      # check kwargs passed to text_generation
      _, kwargs = mock_text_generation.call_args
      assert kwargs == {
          "details": True,
          "stop_sequences": [],
          "stream": True,
      }
  
      # Assert that the streaming callback was called twice
      assert streaming_call_count == 2
  
      # Assert that the response contains the generated replies
      assert "replies" in response
      assert isinstance(response["replies"], list)
      assert len(response["replies"]) > 0
      assert [
          isinstance(reply, ChatMessage)
          for reply in response["replies"]
      ]
  
imports: from unittest.mock import patch, MagicMock, Mock
  import pytest
  from huggingface_hub.inference._text_generation import TextGenerationStreamResponse, Token, StreamDetails, FinishReason
  from huggingface_hub.utils import RepositoryNotFoundError
  from haystack.components.generators.chat import HuggingFaceTGIChatGenerator
  from haystack.dataclasses import StreamingChunk, ChatMessage
label_desc: Use image node_id 14 for calling the TestHuggingFaceTGIChatGenerator obj's underlying member method code with example usage: obj.test_generate_text_with_streaming_callback(mock_check_valid_model, mock_auto_tokenizer, mock_text_generation, chat_messages) without return types