Skip to content

Commit

Permalink
chore: update the lock (#226)
Browse files Browse the repository at this point in the history
LGTM
  • Loading branch information
MadratJerry authored Aug 18, 2024
2 parents aa86650 + bcddfaa commit 462da7a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 54 deletions.
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"lottie-react": "^2.4.0",
"next": "14.0.1",
"openai": "^4.24.7",
"petercat-lui": "0.1.8",
"petercat-lui": "0.1.9",
"postcss": "8.4.27",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
8 changes: 4 additions & 4 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11824,10 +11824,10 @@ pbkdf2@^3.0.3, pbkdf2@^3.1.2:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

[email protected].8:
version "0.1.8"
resolved "https://registry.npmjs.org/petercat-lui/-/petercat-lui-0.1.8.tgz#6ce68e95211419b13f3e4168f7ef13745cddaaa4"
integrity sha512-QtFmLRj047mb4PNlqHvOYCs7GVBQHdTmJRWts3gRGj0rRJjhV2WnXSiXF87u9mP/ujhZ1BiLbPGkWel0VsDDTA==
[email protected].9:
version "0.1.9"
resolved "https://registry.npmjs.org/petercat-lui/-/petercat-lui-0.1.9.tgz#0829e066eafb43479da865e52b9347d4f5fc486d"
integrity sha512-USU87SNG/sQPWh/nLyp8zcXnw+wrl5Tx1CqyG5V9X8OjiJcoATqj3tGDfupxrCABtC0OM3q6Z6nBEZefImB50A==
dependencies:
"@ant-design/icons" "^5.3.5"
"@ant-design/pro-chat" "^1.9.0"
Expand Down
2 changes: 1 addition & 1 deletion lui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "petercat-lui",
"version": "0.1.8",
"version": "0.1.9",
"description": "A react library developed with dumi",
"module": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
28 changes: 15 additions & 13 deletions lui/src/Chat/components/ChatItemRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ const ChatItemRender: FC<IProps> = ({
: 'flex-row-reverse ant-pro-chat-list-item-right'
} ant-pro-chat-list-item ant-pro-chat-list-item-message-content gap-[12px] p-[16px] chat_item_container`}
>
<div
className="ant-avatar ant-avatar-circle ant-avatar-image w-[40px] h-[40px] rounded-full overflow-hidden animate-fade-in-left"
style={{
backgroundColor: `${
avatar?.props?.avatar?.backgroundColor ?? '#FAE4CB'
}`,
}}
>
<img
src={avatar?.props?.avatar?.avatar}
alt={avatar?.props?.avatar?.title}
/>
</div>
{direction === 'start' && (
<div
className="ant-avatar ant-avatar-circle ant-avatar-image w-[40px] h-[40px] rounded-full overflow-hidden animate-fade-in-left"
style={{
backgroundColor: `${
avatar?.props?.avatar?.backgroundColor ?? '#FAE4CB'
}`,
}}
>
<img
src={avatar?.props?.avatar?.avatar}
alt={avatar?.props?.avatar?.title}
/>
</div>
)}
<div className="ant-pro-chat-list-item-message-container">
{title}
{content}
Expand Down
52 changes: 18 additions & 34 deletions server/event_handler/discussion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import requests
from typing import Any
from github import Github, Auth
Expand All @@ -7,7 +6,8 @@

from petercat_utils.data_class import ChatData, Message, TextContentBlock

class DiscussionEventHandler():

class DiscussionEventHandler:
event: Any
auth: Auth.AppAuth
installation_id: int
Expand All @@ -20,12 +20,12 @@ def __init__(self, payload: Any, auth: Auth.AppAuth, installation_id: int) -> No
self.installation_id = installation_id
self.g: Github = Github(auth=auth)
self.graph_url = "https://api.github.com/graphql"

async def get_discussion_id(self, owner: str, repo: str, discussion_number: int):
access_token= self.auth.token
access_token = self.auth.token
headers = {
"Authorization": f"Bearer {access_token}",
"Accept": "application/vnd.github.v3+json"
"Accept": "application/vnd.github.v3+json",
}
query = """
query($owner: String!, $repo: String!, $discussionNumber: Int!) {
Expand All @@ -39,27 +39,23 @@ async def get_discussion_id(self, owner: str, repo: str, discussion_number: int)
variables = {
"owner": owner,
"repo": repo,
"discussionNumber": discussion_number
}
json_data={
"query": query,
"variables": variables
"discussionNumber": discussion_number,
}
json_data = {"query": query, "variables": variables}
response = requests.post(self.graph_url, headers=headers, json=json_data)

if response.status_code == 200:
print("获取讨论成功!")
return response.json()['data']['repository']['discussion']['id']
return response.json()["data"]["repository"]["discussion"]["id"]
else:
print(f"出现错误:{response.status_code}")
print(response.json())


async def create_discussion_comment(self, discussion_id: int, comment_body: str):
access_token= self.auth.token
access_token = self.auth.token
headers = {
"Authorization": f"Bearer {access_token}",
"Accept": "application/vnd.github.v3+json"
"Accept": "application/vnd.github.v3+json",
}
query = """
mutation($discussionId: ID!, $body: String!) {
Expand All @@ -72,15 +68,9 @@ async def create_discussion_comment(self, discussion_id: int, comment_body: str)
}
}
"""
variables = {
"discussionId": discussion_id,
"body": comment_body
}

json_data={
"query": query,
"variables": variables
}
variables = {"discussionId": discussion_id, "body": comment_body}

json_data = {"query": query, "variables": variables}
response = requests.post(self.graph_url, headers=headers, json=json_data)

if response.status_code == 200:
Expand All @@ -90,25 +80,21 @@ async def create_discussion_comment(self, discussion_id: int, comment_body: str)
print(response.json())

async def handle_discussion_event(self, action: str):
owner = self.event['organization']["login"]
repo = self.event['repository']["name"]
owner = self.event["organization"]["login"]
repo = self.event["repository"]["name"]
discussion = self.event["discussion"]
discussion_content = f"{discussion['title']}: {discussion['body']}"
text_block = TextContentBlock(
type="text",
text=discussion_content
)
text_block = TextContentBlock(type="text", text=discussion_content)
discussion_number = discussion["number"]
message = Message(role="user", content=[text_block])

analysis_result = await agent_chat(ChatData(messages=[message]))
discussion_id = await self.get_discussion_id(owner, repo, discussion_number)
await self.create_discussion_comment(discussion_id, analysis_result['output'])
await self.create_discussion_comment(discussion_id, analysis_result["output"])


async def execute(self):
try:
action = self.event['action']
action = self.event["action"]
if action in ["opened", "reopened"]:
await self.handle_discussion_event(action)
return {"success": True}
Expand All @@ -119,5 +105,3 @@ async def execute(self):
except GithubException as e:
print(f"处理 GitHub 请求时出错: {e}")
return {"success": False, "error": str(e)}


2 changes: 1 addition & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ fastapi_auth0
requests
pytest
httpx
petercat_utils>=0.1.26
petercat_utils

0 comments on commit 462da7a

Please sign in to comment.