From 58603c1490ec595186e796d5824d7909e5274d0a Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Sun, 18 Aug 2024 11:22:38 +0800 Subject: [PATCH 1/5] feat: must login --- package.json | 2 +- pyproject.toml | 2 +- server/tools/issue.py | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e299aa83..c54523bb 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "client:server": "concurrently \"yarn run server\" \"yarn run client\"", "lui:server": "concurrently \"yarn run server\" \"yarn run lui\"", "build:docker": "docker build -t petercat .", - "build:pip": "rm -rf dist && python3 -m build", + "build:pypi": "rm -rf dist && python3 -m build", "publish:test": "python3 -m twine upload --repository petercat-utils dist/* ", "publish:pypi": "python3 -m twine upload --repository pypi dist/* " }, diff --git a/pyproject.toml b/pyproject.toml index 488bb04b..c2e69eee 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "petercat_utils" -version = "0.1.21" +version = "0.1.22" description = "" authors = ["raoha.rh "] readme = "README.md" diff --git a/server/tools/issue.py b/server/tools/issue.py index 3e37c7f5..09ea3878 100644 --- a/server/tools/issue.py +++ b/server/tools/issue.py @@ -3,14 +3,11 @@ from github import Auth, Github from langchain.tools import tool -DEFAULT_REPO_NAME = "ant-design/ant-design" - +from tools.helper import need_github_login -def factory(access_token: str): - print(f"issue_factory: {access_token}") - auth = Auth.Token(token=access_token) - g = Github(auth=auth) +DEFAULT_REPO_NAME = "ant-design/ant-design" +def factory(access_token: Optional[str]): @tool def create_issue(repo_name, title, body): """ @@ -20,6 +17,11 @@ def create_issue(repo_name, title, body): :param title: The title of the issue to be created :param body: The content of the issue to be created """ + + if access_token is None: + return need_github_login + auth = Auth.Token(token=access_token) + g = Github(auth=auth) try: # Get the repository object repo = g.get_repo(repo_name) @@ -49,6 +51,7 @@ def get_issues( :param sort: The sorting method, e.g: created, updated, comments :param order: The order of the sorting, e.g: asc, desc """ + g = Github() try: # Obtain the repository object repo = g.get_repo(repo_name) @@ -86,6 +89,7 @@ def search_issues( :param order: The order of the sorting, e.g: asc, desc :param state: The state of the issue, e.g: open, closed, all """ + g = Github() try: search_query = f"{keyword} in:title,body,comments repo:{repo_name}" # Retrieve a list of open issues from the repository @@ -103,6 +107,7 @@ def search_issues( except Exception as e: print(f"An error occurred: {e}") return json.dumps([]) + return { "create_issue": create_issue, "get_issues": get_issues, From 961c1825d87fbef2eb112ba60640e63afebcde53 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Sun, 18 Aug 2024 11:27:01 +0800 Subject: [PATCH 2/5] feat: must login --- server/tools/helper.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 server/tools/helper.py diff --git a/server/tools/helper.py b/server/tools/helper.py new file mode 100644 index 00000000..4576b296 --- /dev/null +++ b/server/tools/helper.py @@ -0,0 +1,6 @@ + +from langchain.tools import tool + +@tool +def need_github_login(): + return "用户必须先使用 GitHub 登录才能使用此功能" \ No newline at end of file From 415e104c65fa1de2eb7d40cb1dfc20547e53e4af Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Sun, 18 Aug 2024 11:37:31 +0800 Subject: [PATCH 3/5] feat: add link --- .github/workflows/aws-preview.yml | 21 +++++++++++++++++++++ server/tools/helper.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/aws-preview.yml b/.github/workflows/aws-preview.yml index ae16db6d..4c48da53 100644 --- a/.github/workflows/aws-preview.yml +++ b/.github/workflows/aws-preview.yml @@ -28,6 +28,27 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + - name: Set up Python + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + + - name: Build a binary wheel and a source tarball + run: python3 -m build + + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: diff --git a/server/tools/helper.py b/server/tools/helper.py index 4576b296..d808eff6 100644 --- a/server/tools/helper.py +++ b/server/tools/helper.py @@ -3,4 +3,4 @@ @tool def need_github_login(): - return "用户必须先使用 GitHub 登录才能使用此功能" \ No newline at end of file + return "你必须先使用 GitHub 登录才能使用此功能。[去登录](https://api.petercat.chat/api/auth/login)" \ No newline at end of file From 8ad8bbec0fcaa13b158f79504a23555c80b0f35b Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Sun, 18 Aug 2024 11:41:13 +0800 Subject: [PATCH 4/5] feat: add link --- .github/workflows/aws-preview.yml | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/.github/workflows/aws-preview.yml b/.github/workflows/aws-preview.yml index 4c48da53..c144f78d 100644 --- a/.github/workflows/aws-preview.yml +++ b/.github/workflows/aws-preview.yml @@ -4,9 +4,13 @@ on: push: branches: ["main"] paths: - - "server/**" + - server/** pull_request: branches: [ "main" ] + paths: + - server/** + - petercat_utils/** + - subscriber/** env: AWS_REGION: ap-northeast-1 @@ -28,27 +32,6 @@ jobs: - name: Checkout uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 - - name: Set up Python - - uses: actions/setup-python@v5 - with: - python-version: "3.x" - - - name: Install pypa/build - run: >- - python3 -m - pip install - build - --user - - - name: Build a binary wheel and a source tarball - run: python3 -m build - - - name: Store the distribution packages - uses: actions/upload-artifact@v3 - with: - name: python-package-distributions - path: dist/ - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: From d950c457076b26e93b9cabef63df941aca7e6859 Mon Sep 17 00:00:00 2001 From: "raoha.rh" Date: Sun, 18 Aug 2024 12:00:20 +0800 Subject: [PATCH 5/5] feat: add link --- server/auth/get_user_info.py | 2 ++ server/tools/helper.py | 8 ++++---- server/tools/issue.py | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/server/auth/get_user_info.py b/server/auth/get_user_info.py index bf8045f8..b0171ddc 100644 --- a/server/auth/get_user_info.py +++ b/server/auth/get_user_info.py @@ -64,6 +64,8 @@ async def getAnonymousUserInfoByToken(token: str): return rows.data[0] if (len(rows.data) > 0) else None async def get_user_access_token(petercat_user_token: Annotated[str | None, Cookie()] = None): + if petercat_user_token is None: + return None user_info = await getUserInfoByToken(petercat_user_token) access_token = await getUserAccessToken(user_id=user_info['id']) print(f"get_user_access_token: user_info={user_info}, access_token={access_token}") diff --git a/server/tools/helper.py b/server/tools/helper.py index d808eff6..286bf93a 100644 --- a/server/tools/helper.py +++ b/server/tools/helper.py @@ -1,6 +1,6 @@ +import json -from langchain.tools import tool - -@tool def need_github_login(): - return "你必须先使用 GitHub 登录才能使用此功能。[去登录](https://api.petercat.chat/api/auth/login)" \ No newline at end of file + return json.dumps({ + "error_info": "你必须先使用 GitHub 登录 petercat 才能使用此功能。 [登录地址](https://api.petercat.chat/api/auth/login)" + }) \ No newline at end of file diff --git a/server/tools/issue.py b/server/tools/issue.py index 09ea3878..4e44e09a 100644 --- a/server/tools/issue.py +++ b/server/tools/issue.py @@ -11,7 +11,9 @@ def factory(access_token: Optional[str]): @tool def create_issue(repo_name, title, body): """ - Create an issue in the specified GitHub repository. + Create an issue in the specified GitHub repository.If an error occurs during processing, + If user not login, it will return error mesesage and login url + Please invite user to login if got error :param repo_name: The name of the repository, e.g., "ant-design/ant-design" :param title: The title of the issue to be created @@ -19,7 +21,7 @@ def create_issue(repo_name, title, body): """ if access_token is None: - return need_github_login + return need_github_login() auth = Auth.Token(token=access_token) g = Github(auth=auth) try: