code: def mock_chat_completion_chunk():
      """
      Mock the OpenAI API completion chunk response and reuse it for tests
      """
  
      class MockStream(Stream[ChatCompletionChunk]):
          def __init__(
              self, mock_chunk: ChatCompletionChunk, *args, **kwargs
          ):
              super().__init__(*args, **kwargs)
              self.mock_chunk = mock_chunk
  
          def __stream__(self) -> Iterator[ChatCompletionChunk]:
              # Yielding only one ChatCompletionChunk object
              yield self.mock_chunk
  
      with patch(
          "openai.resources.chat.completions.Completions.create"
      ) as mock_chat_completion_create:
          completion = ChatCompletionChunk(
              id="foo",
              model="gpt-4",
              object="chat.completion.chunk",
              choices=[
                  Choice(
                      finish_reason="stop",
                      logprobs=None,
                      index=0,
                      delta=ChoiceDelta(
                          content="Hello", role="assistant"
                      ),
                  )
              ],
              created=int(datetime.now().timestamp()),
              usage={
                  "prompt_tokens": 57,
                  "completion_tokens": 40,
                  "total_tokens": 97,
              },
          )
          mock_chat_completion_create.return_value = MockStream(
              completion, cast_to=None, response=None, client=None
          )
          yield mock_chat_completion_create
  
file_path: haystack/test/components/generators/conftest.py
imports: from datetime import datetime
  from typing import Iterator
  from unittest.mock import patch, MagicMock
  import pytest
  from openai import Stream
  from openai.types.chat import ChatCompletionChunk
  from openai.types.chat.chat_completion_chunk import ChoiceDelta, Choice
label_desc: Use image node_id 2 for calling a global function with example usage: mock_chat_completion_chunk() without return types