Skip to content

Commit 29f614e

Browse files
GitHub tool (#931)
* TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation - temporary commit * TLK-2709 - Github Tool Implementation - temporary commit * TLK-2709 - Github Tool Implementation - temporary commit * TLK-2709 - Github Tool Implementation - temporary commit * TLK-2709 - Github Tool Implementation - temporary commit * TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation + small fixes * TLK-2709 - Github Tool Implementation format * TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation * TLK-2709 - Github Tool Implementation review fixes * TLK-2709 - Github Tool Implementation review fixes * TLK-2709 - Github Tool Implementation review fixes
1 parent 083a0af commit 29f614e

File tree

22 files changed

+653
-236
lines changed

22 files changed

+653
-236
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Toolkit is a deployable all-in-one RAG application that enables users to quickly
1515
- [How to setup Google Drive](/docs/custom_tool_guides/google_drive.md)
1616
- [How to setup Gmail](/docs/custom_tool_guides/gmail.md)
1717
- [How to setup Slack Tool](/docs/custom_tool_guides/slack.md)
18+
- [How to setup Github Tool](/docs/custom_tool_guides/github.md)
1819
- [How to setup Google Text-to-Speech](/docs/text_to_speech.md)
1920
- [How to add authentication](/docs/auth_guide.md)
2021
- [How to deploy toolkit services](/docs/service_deployments.md)

docs/custom_tool_guides/github.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Github Tool Setup
2+
3+
To set up the Github tool you will need a Github application. Follow the steps below to set it up:
4+
5+
## 1. Create a Github App
6+
7+
Head to the [Github Settings](https://github.com/settings/apps) and create a new app.
8+
Specify App [permissions](https://docs.github.com/rest/overview/permissions-required-for-github-apps), Callback URL (for local setup - http://localhost:8000/v1/tool/auth).
9+
Uncheck the `Webhook->Active` option. After creating the app, you will see the `General` section. Copy the `Client ID`, generate and copy `Client Secret` values.
10+
That will be used for the environment variables specified below.
11+
This tool also support OAuth Apps. See the [documentation](https://docs.github.com/en/apps/oauth-apps) for more information.
12+
13+
## 2. Set Up Environment Variables
14+
Set the configuration in the `configuration.yaml`
15+
```yaml
16+
github:
17+
default_repos:
18+
- repo1
19+
- repo2
20+
user_scopes:
21+
- public_repo
22+
- read:org
23+
```
24+
25+
Then set the following secrets variables. You can either set the below values in your `secrets.yaml` file:
26+
```yaml
27+
github:
28+
client_id: <your_client_id from step 1>
29+
client_secret: <your_client_secret from step 1>
30+
```
31+
or update your `.env` configuration to contain:
32+
```dotenv
33+
GITHUB_CLIENT_ID=<your_client_id from step 1>
34+
GITHUB_CLIENT_SECRET=<your_client_secret from step 1>
35+
GITHUB_DEFAULT_REPOS=["repo1","repo2"]
36+
GITHUB_USER_SCOPES=["public_repo","read:org"]
37+
```
38+
Please note if the default repos are not set, the tool will process over all user repos.
39+
40+
## 3. Run the Backend and Frontend
41+
42+
run next command to start the backend and frontend:
43+
44+
```bash
45+
make dev
46+
```
47+
48+
## 4. Troubleshooting
49+
50+
If you encounter any issues with OAuth, please check the following [link](https://api.Github.com/authentication/oauth-v2#errors)

poetry.lock

Lines changed: 54 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ llama-index-embeddings-cohere = "^0.2.1"
5959
google-cloud-texttospeech = "^2.18.0"
6060
slack-sdk = "^3.33.1"
6161
onnxruntime = "1.19.2"
62+
pygithub = "^2.5.0"
6263

6364
[tool.poetry.group.dev]
6465
optional = true

src/backend/config/configuration.template.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ tools:
3737
slack:
3838
user_scopes:
3939
- search:read
40+
github:
41+
user_scopes:
42+
- public_repo
43+
default_repos:
44+
- cohere-ai/cohere-toolkit
45+
- EugeneLightsOn/cohere-toolkit
4046
# To disable the use of the tools preamble, set it to false
4147
use_tools_preamble: true
4248
feature_flags:

src/backend/config/secrets.template.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ tools:
3737
gmail:
3838
client_id:
3939
client_secret:
40+
github:
41+
client_id:
42+
client_secret:
4043
auth:
4144
secret_key:
4245
google_oauth:

src/backend/config/settings.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,38 @@ class SlackSettings(BaseSettings, BaseModel):
191191
default=None,
192192
validation_alias=AliasChoices("SLACK_CLIENT_SECRET", "client_secret"),
193193
)
194-
user_scopes: Optional[str] = Field(
194+
user_scopes: Optional[List[str]] = Field(
195195
default=None,
196196
validation_alias=AliasChoices(
197197
"SLACK_USER_SCOPES", "scopes"
198198
),
199199
)
200200

201201

202+
class GithubSettings(BaseSettings, BaseModel):
203+
model_config = SETTINGS_CONFIG
204+
client_id: Optional[str] = Field(
205+
default=None,
206+
validation_alias=AliasChoices("GITHUB_CLIENT_ID", "client_id"),
207+
)
208+
client_secret: Optional[str] = Field(
209+
default=None,
210+
validation_alias=AliasChoices("GITHUB_CLIENT_SECRET", "client_secret"),
211+
)
212+
user_scopes: Optional[List[str]] = Field(
213+
default=None,
214+
validation_alias=AliasChoices(
215+
"GITHUB_USER_SCOPES", "user_scopes"
216+
),
217+
)
218+
default_repos: Optional[List[str]] = Field(
219+
default=None,
220+
validation_alias=AliasChoices(
221+
"GITHUB_DEFAULT_REPOS", "default_repos"
222+
),
223+
)
224+
225+
202226
class TavilyWebSearchSettings(BaseSettings, BaseModel):
203227
model_config = SETTINGS_CONFIG
204228
api_key: Optional[str] = Field(
@@ -272,6 +296,9 @@ class ToolSettings(BaseSettings, BaseModel):
272296
slack: Optional[SlackSettings] = Field(
273297
default=SlackSettings()
274298
)
299+
github: Optional[GithubSettings] = Field(
300+
default=GithubSettings()
301+
)
275302
gmail: Optional[GmailSettings] = Field(
276303
default=GmailSettings()
277304
)

src/backend/config/tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
TavilyWebSearch,
1919
WebScrapeTool,
2020
)
21+
from backend.tools.github.tool import GithubTool
2122

2223
logger = LoggerFactory().get_logger()
2324

@@ -38,6 +39,7 @@ class Tool(Enum):
3839
Hybrid_Web_Search = HybridWebSearch
3940
Slack = SlackTool
4041
Gmail = GmailTool
42+
Github = GithubTool
4143

4244

4345
def get_available_tools() -> dict[str, ToolDefinition]:

src/backend/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ def create_app() -> FastAPI:
8383
# Dynamically set router dependencies
8484
# These values must be set in config/routers.py
8585
dependencies_type = "default"
86+
settings = Settings()
8687
if is_authentication_enabled():
8788
# Required to save temporary OAuth state in session
88-
auth_secret = Settings().get('auth.secret_key')
89+
auth_secret = settings.get('auth.secret_key')
8990
app.add_middleware(SessionMiddleware, secret_key=auth_secret)
9091
dependencies_type = "auth"
9192
for router in routers:

src/backend/tests/unit/tools/test_lang_chain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def test_wiki_retriever_no_docs() -> None:
7272
):
7373
result = await retriever.call({"query": query}, ctx)
7474

75-
assert result == ToolError(type=ToolErrorCode.OTHER, success=False, text='No results found.', details='No results found for the given params.')
75+
assert result == [ToolError(type=ToolErrorCode.OTHER, success=False, text='No results found.', details='No results found for the given params.').model_dump()]
7676

7777

7878

@@ -156,4 +156,4 @@ async def test_vector_db_retriever_no_docs() -> None:
156156
mock_db.as_retriever().get_relevant_documents.return_value = mock_docs
157157
result = await retriever.call({"query": query}, ctx)
158158

159-
assert result == ToolError(type=ToolErrorCode.OTHER, success=False, text='No results found.', details='No results found for the given params.')
159+
assert result == [ToolError(type=ToolErrorCode.OTHER, success=False, text='No results found.', details='No results found for the given params.').model_dump()]

0 commit comments

Comments
 (0)