File tree Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Expand file tree Collapse file tree 1 file changed +16
-8
lines changed Original file line number Diff line number Diff line change 2
2
from github import Github
3
3
from github .ContentFile import ContentFile
4
4
from langchain .tools import tool
5
+ import json
5
6
6
7
DEFAULT_REPO_NAME = "ant-design/ant-design"
7
8
8
9
g = Github ()
9
10
11
+
10
12
@tool
11
13
def search_code (
12
- keyword : str ,
13
- repo_name : Optional [str ] = DEFAULT_REPO_NAME ,
14
- max_num : Optional [int ] = 5 ,
14
+ keyword : str ,
15
+ repo_name : Optional [str ] = DEFAULT_REPO_NAME ,
16
+ max_num : Optional [int ] = 5 ,
15
17
) -> List [ContentFile ]:
16
18
"""
17
19
Searches for code files on GitHub that contain the given keyword.
@@ -23,13 +25,19 @@ def search_code(
23
25
:return: A list of ContentFile objects representing the matching code files.
24
26
"""
25
27
try :
26
- query = f' repo:{ repo_name } { keyword } '
27
-
28
+ query = f" repo:{ repo_name } { keyword } "
29
+
28
30
# Perform the search for code files containing the keyword
29
31
code_files = g .search_code (query = query )[:max_num ]
30
-
31
- return code_files
32
+ code_list = [
33
+ {
34
+ "content" : file .content ,
35
+ "html_url" : file .html_url ,
36
+ "text_matches" : file .text_matches ,
37
+ }
38
+ for file in code_files
39
+ ]
40
+ return json .dumps (code_list )
32
41
except Exception as e :
33
42
print (f"An error occurred: { e } " )
34
43
return None
35
-
You can’t perform that action at this time.
0 commit comments