Skip to content

Commit 55bcae8

Browse files
add GitHub integration page (#329)
* add GitHub integration page * add github logo * remove unused imports * Apply suggestions from code review Co-authored-by: Bilge Yücel <bilge.yucel@deepset.ai> * type: Tool Integration * move repo_viewer_tool in example code --------- Co-authored-by: Bilge Yücel <bilge.yucel@deepset.ai>
1 parent c924679 commit 55bcae8

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

integrations/github.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
layout: integration
3+
name: github
4+
description: Interact with GitHub repositories, issues, and pull requests within Haystack
5+
authors:
6+
- name: deepset
7+
socials:
8+
github: deepset-ai
9+
twitter: deepset_ai
10+
linkedin: https://www.linkedin.com/company/deepset-ai/
11+
pypi: https://pypi.org/project/github-haystack
12+
repo: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github
13+
type: Tool Integration
14+
report_issue: https://github.com/deepset-ai/haystack-core-integrations/issues
15+
logo: /logos/github.png
16+
version: Haystack 2.0
17+
toc: true
18+
---
19+
20+
### **Table of Contents**
21+
22+
- [Overview](#overview)
23+
- [Installation](#installation)
24+
- [Usage](#usage)
25+
26+
## Overview
27+
28+
The GitHub integration for Haystack provides a set of components and tools to interact with GitHub repositories, issues, and pull requests. It enables you to view repository contents, manage issues, create pull requests, and more within your Haystack agents and pipelines.
29+
30+
31+
Some of the components and tools in this integration require GitHub authentication with a personal access token.
32+
For example, authentication is required to post a comment on GitHub, fork a repository, or open a pull request. You can create a (fine-graind personal access token)[https://github.com/settings/personal-access-tokens] or a [classic personal access token](https://github.com/settings/tokens) on GitHub and then expose it via an environment variable called `GITHUB_API_KEY`.
33+
34+
35+
## Installation
36+
37+
Install the GitHub integration with pip:
38+
39+
```bash
40+
pip install github-haystack
41+
```
42+
43+
## Usage
44+
45+
This integration comes with several components and tools:
46+
47+
### Components
48+
- `GitHubIssueViewer`: View issues and their details
49+
- `GitHubIssueCommenter`: Add comments to issues
50+
- `GitHubRepoViewer`: View repository contents and metadata
51+
- `GitHubRepoForker`: Fork repositories
52+
- `GitHubFileEditor`: Edit files in repositories
53+
- `GitHubPRCreator`: Create pull requests
54+
55+
### Tools
56+
- `GitHubIssueViewerTool`: View issues
57+
- `GitHubIssueCommenterTool`: Comment on issues
58+
- `GitHubRepoViewerTool`: View repository contents
59+
- `GitHubFileEditorTool`: Edit repository files
60+
- `GitHubPRCreatorTool`: Create pull requests
61+
62+
### Example Usage
63+
64+
```python
65+
from typing import List
66+
67+
from haystack import Pipeline
68+
from haystack.components.agents import Agent
69+
from haystack.components.builders import ChatPromptBuilder
70+
from haystack.dataclasses import ChatMessage, Document
71+
from haystack.tools.from_function import tool
72+
73+
from haystack_integrations.components.connectors.github import GitHubIssueViewer
74+
from haystack_integrations.components.generators.anthropic import AnthropicChatGenerator
75+
from haystack_integrations.prompts.github import SYSTEM_PROMPT
76+
from haystack_integrations.tools.github import GitHubRepoViewerTool
77+
78+
@tool
79+
def create_comment(comment: str) -> str:
80+
"""
81+
Use this to create a Github comment once you finished your exploration.
82+
"""
83+
# A mockup tool to showcase how Agent uses tools. You should use `GitHubIssueCommenterTool` instead of this one to write comments on GitHub.
84+
return comment
85+
86+
repo_viewer_tool = GitHubRepoViewerTool()
87+
88+
chat_generator = AnthropicChatGenerator(model="claude-3-5-sonnet-latest", generation_kwargs={"max_tokens": 8000})
89+
90+
agent = Agent(
91+
chat_generator=chat_generator,
92+
system_prompt=SYSTEM_PROMPT,
93+
tools=[repo_viewer_tool, create_comment],
94+
exit_conditions=["create_comment"],
95+
state_schema={"documents": {"type": List[Document]}},
96+
)
97+
98+
issue_template = """
99+
Issue from: {{ url }}
100+
{% for document in documents %}
101+
{% if loop.index == 1 %}
102+
**Title: {{ document.meta.title }}**
103+
{% endif %}
104+
<issue-comment>
105+
{{document.content}}
106+
</issue-comment>
107+
{% endfor %}
108+
"""
109+
110+
issue_builder = ChatPromptBuilder(template=[ChatMessage.from_user(issue_template)], required_variables="*")
111+
112+
issue_fetcher = GitHubIssueViewer()
113+
114+
pipeline = Pipeline()
115+
116+
pipeline.add_component("issue_fetcher", issue_fetcher)
117+
pipeline.add_component("issue_builder", issue_builder)
118+
pipeline.add_component("agent", agent)
119+
120+
pipeline.connect("issue_fetcher.documents", "issue_builder.documents")
121+
pipeline.connect("issue_builder.prompt", "agent.messages")
122+
123+
issue_url = "https://github.com/<owner>/<repo>/issues/1268"
124+
125+
result = pipeline.run({"url": issue_url})
126+
print(result["agent"]["last_message"].tool_call_result.result)
127+
```

logos/github.png

6.24 KB
Loading

0 commit comments

Comments
 (0)