Coverage for haystack/components/generators/chat/types/protocol.py: 100%

4 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-21 13:53 +0000

1# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai> 

2# 

3# SPDX-License-Identifier: Apache-2.0 

4 

5from typing import Any, Protocol 

6 

7from haystack.dataclasses import ChatMessage 

8 

9 

10class ChatGenerator(Protocol): 

11 """ 

12 Protocol for Chat Generators. 

13 

14 This protocol defines the minimal interface that Chat Generators must implement. 

15 Chat Generators are components that process a list of `ChatMessage` objects as input and generate 

16 responses using a Language Model. They return a dictionary. 

17 """ 

18 

19 def run(self, messages: list[ChatMessage]) -> dict[str, Any]: 

20 """ 

21 Generate messages using the underlying Language Model. 

22 

23 Implementing classes may accept additional optional parameters in their run method. 

24 For example: `def run (self, messages: list[ChatMessage], param_a="default", param_b="another_default")`. 

25 

26 :param messages: 

27 A list of ChatMessage instances representing the input messages. 

28 :returns: 

29 A dictionary. 

30 """ 

31 ...