github-haystack 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. github_haystack-1.0.0.dist-info/METADATA +45 -0
  2. github_haystack-1.0.0.dist-info/RECORD +26 -0
  3. github_haystack-1.0.0.dist-info/WHEEL +4 -0
  4. github_haystack-1.0.0.dist-info/licenses/LICENSE.txt +73 -0
  5. haystack_integrations/components/connectors/github/__init__.py +19 -0
  6. haystack_integrations/components/connectors/github/file_editor.py +303 -0
  7. haystack_integrations/components/connectors/github/issue_commenter.py +161 -0
  8. haystack_integrations/components/connectors/github/issue_viewer.py +216 -0
  9. haystack_integrations/components/connectors/github/pr_creator.py +277 -0
  10. haystack_integrations/components/connectors/github/repo_forker.py +306 -0
  11. haystack_integrations/components/connectors/github/repo_viewer.py +272 -0
  12. haystack_integrations/prompts/github/__init__.py +22 -0
  13. haystack_integrations/prompts/github/context_prompt.py +176 -0
  14. haystack_integrations/prompts/github/file_editor_prompt.py +122 -0
  15. haystack_integrations/prompts/github/issue_commenter_prompt.py +21 -0
  16. haystack_integrations/prompts/github/issue_viewer_prompt.py +25 -0
  17. haystack_integrations/prompts/github/pr_creator_prompt.py +83 -0
  18. haystack_integrations/prompts/github/repo_viewer_prompt.py +81 -0
  19. haystack_integrations/prompts/github/system_prompt.py +63 -0
  20. haystack_integrations/tools/github/__init__.py +16 -0
  21. haystack_integrations/tools/github/file_editor_tool.py +128 -0
  22. haystack_integrations/tools/github/issue_commenter_tool.py +123 -0
  23. haystack_integrations/tools/github/issue_viewer_tool.py +123 -0
  24. haystack_integrations/tools/github/pr_creator_tool.py +117 -0
  25. haystack_integrations/tools/github/repo_viewer_tool.py +138 -0
  26. haystack_integrations/tools/github/utils.py +73 -0
@@ -0,0 +1,73 @@
1
+ # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ from typing import Any, Callable, Dict, List, Union
6
+
7
+ from haystack import Document
8
+ from haystack.utils.callable_serialization import deserialize_callable, serialize_callable
9
+
10
+
11
+ def message_handler(documents: List[Document], max_length: int = 150_000) -> str:
12
+ """
13
+ Handles the tool output before conversion to ChatMessage.
14
+
15
+ :param documents: List of Document objects
16
+ :param max_length: Maximum number of characters of the result string
17
+ :returns:
18
+ String representation of the documents.
19
+ """
20
+ result_str = ""
21
+ for document in documents:
22
+ if document.meta["type"] in ["file", "dir", "error"]:
23
+ result_str += document.content + "\n"
24
+ else:
25
+ result_str += f"File Content for {document.meta['path']}\n\n"
26
+ result_str += document.content
27
+
28
+ if len(result_str) > max_length:
29
+ result_str = result_str[:max_length] + "...(large file can't be fully displayed)"
30
+
31
+ return result_str
32
+
33
+
34
+ def serialize_handlers(
35
+ serialized: Dict[str, Any],
36
+ outputs_to_state: Dict[str, Dict[str, Union[str, Callable]]],
37
+ outputs_to_string: Dict[str, Union[str, Callable[[Any], str]]],
38
+ ) -> None:
39
+ """
40
+ Serializes callable handlers in outputs_to_state and outputs_to_string.
41
+
42
+ :param serialized: The dictionary to update with serialized handlers
43
+ :param outputs_to_state: Dictionary containing state output configurations
44
+ :param outputs_to_string: Dictionary containing string output configuration
45
+ """
46
+ if outputs_to_state is not None:
47
+ serialized_outputs = {}
48
+ for key, config in outputs_to_state.items():
49
+ serialized_config = config.copy()
50
+ if "handler" in config:
51
+ serialized_config["handler"] = serialize_callable(config["handler"])
52
+ serialized_outputs[key] = serialized_config
53
+ serialized["outputs_to_state"] = serialized_outputs
54
+
55
+ if outputs_to_string is not None and "handler" in outputs_to_string:
56
+ serialized_string = outputs_to_string.copy()
57
+ serialized_string["handler"] = serialize_callable(outputs_to_string["handler"])
58
+ serialized["outputs_to_string"] = serialized_string
59
+
60
+
61
+ def deserialize_handlers(data: Dict[str, Any]) -> None:
62
+ """
63
+ Deserializes callable handlers in outputs_to_state and outputs_to_string.
64
+
65
+ :param data: The dictionary containing serialized handlers to deserialize
66
+ """
67
+ if data.get("outputs_to_state"):
68
+ for config in data["outputs_to_state"].values():
69
+ if "handler" in config:
70
+ config["handler"] = deserialize_callable(config["handler"])
71
+
72
+ if "outputs_to_string" in data and data["outputs_to_string"] and "handler" in data["outputs_to_string"]:
73
+ data["outputs_to_string"]["handler"] = deserialize_callable(data["outputs_to_string"]["handler"])