Skip to content

Commit 19bc5c3

Browse files
author
yingying
committed
fix: source code
1 parent bcc1db1 commit 19bc5c3

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

server/tools/sourcecode.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
from github import Github
33
from github.ContentFile import ContentFile
44
from langchain.tools import tool
5+
import json
56

67
DEFAULT_REPO_NAME = "ant-design/ant-design"
78

89
g = Github()
910

11+
1012
@tool
1113
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,
1517
) -> List[ContentFile]:
1618
"""
1719
Searches for code files on GitHub that contain the given keyword.
@@ -23,13 +25,19 @@ def search_code(
2325
:return: A list of ContentFile objects representing the matching code files.
2426
"""
2527
try:
26-
query = f'repo:{repo_name} {keyword}'
27-
28+
query = f"repo:{repo_name} {keyword}"
29+
2830
# Perform the search for code files containing the keyword
2931
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)
3241
except Exception as e:
3342
print(f"An error occurred: {e}")
3443
return None
35-

0 commit comments

Comments
 (0)