Skip to content

Commit

Permalink
Merge pull request #87 from ant-xuexiao/refactor/and-add-github-callback
Browse files Browse the repository at this point in the history
refactor: router and add github callback urls
  • Loading branch information
xingwanying authored Apr 15, 2024
2 parents e01922e + 4990399 commit 23497f4
Show file tree
Hide file tree
Showing 17 changed files with 656 additions and 284 deletions.
2 changes: 1 addition & 1 deletion .aws/petercat-preview.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ region = "ap-northeast-1"
confirm_changeset = true
capabilities = "CAPABILITY_IAM"
disable_rollback = true
image_repositories = ["FastAPIFunction=654654285942.dkr.ecr.ap-northeast-1.amazonaws.com/petercatapipreview49199518/fastapifunctionead79d0drepo", "SQSSubscriptionFunction=654654285942.dkr.ecr.ap-northeast-1.amazonaws.com/petercatapipreview49199518/sqssubscriptionfunctiona2fc8b7drepo"]
image_repositories = ["FastAPIFunction=654654285942.dkr.ecr.ap-northeast-1.amazonaws.com/petercatapipreview49199518/fastapifunctionead79d0drepo"]
2 changes: 1 addition & 1 deletion .aws/petercat-prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ region = "ap-northeast-1"
confirm_changeset = true
capabilities = "CAPABILITY_IAM"
disable_rollback = true
image_repositories = ["FastAPIFunction=654654285942.dkr.ecr.ap-northeast-1.amazonaws.com/samapp7427b055/fastapifunctionead79d0drepo", "SQSSubscriptionFunction=654654285942.dkr.ecr.ap-northeast-1.amazonaws.com/samapp7427b055/sqssubscriptionfunctiona2fc8b7drepo"]
image_repositories = ["FastAPIFunction=654654285942.dkr.ecr.ap-northeast-1.amazonaws.com/samapp7427b055/fastapifunctionead79d0drepo"]
103 changes: 3 additions & 100 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,106 +3,9 @@
# YOU MUST CHANGE THESE BEFORE GOING INTO PRODUCTION
############

POSTGRES_PASSWORD=your-super-secret-and-long-postgres-password
JWT_SECRET=your-super-secret-jwt-token-with-at-least-32-characters-long
ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJhbm9uIiwKICAgICJpc3MiOiAic3VwYWJhc2UtZGVtbyIsCiAgICAiaWF0IjogMTY0MTc2OTIwMCwKICAgICJleHAiOiAxNzk5NTM1NjAwCn0.dc_X5iR_VP_qT0zsiyj_I_OZ2T9FtRU2BBNWN8Bu4GE
SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q
DASHBOARD_USERNAME=supabase
DASHBOARD_PASSWORD=this_password_is_insecure_and_should_be_updated

############
# Database - You can change these to any PostgreSQL database that has logical replication enabled.
############

POSTGRES_HOST=db
POSTGRES_DB=postgres
POSTGRES_PORT=5432
# default user is postgres

############
# API Proxy - Configuration for the Kong Reverse proxy.
############

KONG_HTTP_PORT=8000
KONG_HTTPS_PORT=8443


############
# API - Configuration for PostgREST.
############

PGRST_DB_SCHEMAS=public,storage,graphql_public


############
# Auth - Configuration for the GoTrue authentication server.
############

## General
SITE_URL=http://localhost:3000
ADDITIONAL_REDIRECT_URLS=
JWT_EXPIRY=3600
DISABLE_SIGNUP=false
API_EXTERNAL_URL=http://localhost:8000

## Mailer Config
MAILER_URLPATHS_CONFIRMATION="/auth/v1/verify"
MAILER_URLPATHS_INVITE="/auth/v1/verify"
MAILER_URLPATHS_RECOVERY="/auth/v1/verify"
MAILER_URLPATHS_EMAIL_CHANGE="/auth/v1/verify"

## Email auth
ENABLE_EMAIL_SIGNUP=true
ENABLE_EMAIL_AUTOCONFIRM=false
SMTP_ADMIN_EMAIL=[email protected]
SMTP_HOST=supabase-mail
SMTP_PORT=2500
SMTP_USER=fake_mail_user
SMTP_PASS=fake_mail_password
SMTP_SENDER_NAME=fake_sender

## Phone auth
ENABLE_PHONE_SIGNUP=true
ENABLE_PHONE_AUTOCONFIRM=true


############
# Studio - Configuration for the Dashboard
############

STUDIO_DEFAULT_ORGANIZATION=Default Organization
STUDIO_DEFAULT_PROJECT=Default Project

STUDIO_PORT=3000
# replace if you intend to use Studio outside of localhost
SUPABASE_PUBLIC_URL=http://localhost:8000

# Enable webp support
IMGPROXY_ENABLE_WEBP_DETECTION=true

############
# Functions - Configuration for Functions
############
# NOTE: VERIFY_JWT applies to all functions. Per-function VERIFY_JWT is not supported yet.
FUNCTIONS_VERIFY_JWT=false

############
# Logs - Configuration for Logflare
# Please refer to https://supabase.com/docs/reference/self-hosting-analytics/introduction
############

LOGFLARE_LOGGER_BACKEND_API_KEY=your-super-secret-and-long-logflare-key

# Change vector.toml sinks to reflect this change
LOGFLARE_API_KEY=your-super-secret-and-long-logflare-key

# Docker socket location - this value will differ depending on your OS
DOCKER_SOCKET_LOCATION=/var/run/docker.sock

# Google Cloud Project details
GOOGLE_PROJECT_ID=GOOGLE_PROJECT_ID
GOOGLE_PROJECT_NUMBER=GOOGLE_PROJECT_NUMBER


#TAVILY_API_KEY
TAVILY_API_KEY=TAVILY_API_KEY

GITHUB_APP_CLIENT_ID=Iv1.c2e88b429e541264
GITHUB_APP_CLIENT_SECRET=xxx
9 changes: 9 additions & 0 deletions server/db/supabase/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from supabase.client import Client, create_client
from uilts.env import get_env_variable

supabase_url = get_env_variable("SUPABASE_URL")
supabase_key = get_env_variable("SUPABASE_SERVICE_KEY")

def get_client():
supabase: Client = create_client(supabase_url, supabase_key)
return supabase
27 changes: 27 additions & 0 deletions server/event_handler/pull_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

from typing import Any, Dict, Union
from typing_extensions import NotRequired, TypedDict
from github import GithubObject, PullRequest, Repository, Organization, Installation, PullRequestComment
from github import Github, Auth

class PullRequestEventHandler():
event: Any
auth: Auth.AppAuth
g: Github

def __init__(self, payload, auth: Auth.AppAuth) -> None:
self.event = payload
self.auth = auth
self.g = Github(auth=auth)

def execute(self):
match self.event['action']:
case 'opened':
repo = self.g.get_repo(self.event['repository']["full_name"])
pr = repo.get_pull(self.event["pull_request"]["number"])
comment = pr.create_issue_comment("This is a comment from PeterCat")

print(repo, pr, comment)
return { "success": True }
case _:
return { "success": True }
31 changes: 13 additions & 18 deletions server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
from fastapi.middleware.cors import CORSMiddleware

from agent import stream

from uilts.env import get_env_variable
from data_class import ChatData, ExecuteMessage
from message_queue.queue_wrapper import delete_messages, get_queue, receive_messages, send_message, unpack_message
from data_class import ChatData

# Import fastapi routers
from routers import health_checker, github

open_api_key = get_env_variable("OPENAI_API_KEY")
sqs_queue_name = get_env_variable("PETERCAT_EX_SQS")
is_dev = bool(get_env_variable("IS_DEV"))

app = FastAPI(
title="Bo-meta Server",
version="1.0",
description="Agent Chat APIs"
)
)

app.add_middleware(
CORSMiddleware,
Expand All @@ -28,19 +31,8 @@
expose_headers=["*"],
)

@app.get("/")
def read_root():
return {"Hello": "World"}

@app.post("/api/message")
def send_sqs_message(message: ExecuteMessage):
queue = get_queue(sqs_queue_name)
return send_message(queue=queue, message=message)

@app.get("/api/message/receive")
def receive_sqs_message():
queue = get_queue(sqs_queue_name)
return StreamingResponse(receive_messages(queue), media_type="text/event-stream")
app.include_router(health_checker.router)
app.include_router(github.router)


@app.post("/api/chat/stream", response_class=StreamingResponse)
Expand All @@ -59,4 +51,7 @@ def search_knowledge(query: str):
return data

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8080")))
if is_dev:
uvicorn.run("main:app", host="0.0.0.0", port=int(os.environ.get("PORT", "8080")), reload=True)
else:
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8080")))
102 changes: 0 additions & 102 deletions server/message_queue/queue_wrapper.py

This file was deleted.

6 changes: 2 additions & 4 deletions server/rag/retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from langchain_openai import OpenAIEmbeddings
from langchain_text_splitters import CharacterTextSplitter
from langchain_community.vectorstores import SupabaseVectorStore
from supabase.client import Client, create_client
from db.supabase.client import get_client
from uilts.env import get_env_variable

supabase_url = get_env_variable("SUPABASE_URL")
Expand All @@ -13,8 +13,6 @@
query_name="match_antd_knowledge"
chunk_size=500

supabase: Client = create_client(supabase_url, supabase_key)

def convert_document_to_dict(document):
return {
'page_content': document.page_content,
Expand All @@ -26,7 +24,7 @@ def init_retriever():
embeddings = OpenAIEmbeddings()
db = SupabaseVectorStore(
embedding=embeddings,
client=supabase,
client=get_client(),
table_name=table_name,
query_name=query_name,
chunk_size=chunk_size,
Expand Down
4 changes: 3 additions & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ python-multipart
httpx[socks]
load_dotenv
supabase
boto3>=1.26.79
boto3>=1.34.84
pyjwt>=2.4.0
pydantic>=2.7.0
Loading

0 comments on commit 23497f4

Please sign in to comment.