Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: init pytest workflow" #243

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .github/workflows/aws-preview.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
name: Deploy Backend to Preview ECS

# on:
# workflow_run:
# workflows: ["PR Tests"]
# types:
# - completed
on:
pull_request:
branches: [ "main" ]
Expand All @@ -22,12 +17,11 @@ env:
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
actions: write

jobs:
deploy:
runs-on: ubuntu-latest
environment: Preview
environment: production
strategy:
fail-fast: true

Expand Down
66 changes: 0 additions & 66 deletions .github/workflows/pr-tests.yml

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ venv
.next/
out/

.ruff_cache/

# production
build
Expand Down
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
test:
pytest backend/tests

dev:
docker compose -f docker/docker-compose.yml build backend-core
docker compose -f docker/docker-compose.yml up --build -d

dev-ps:
docker compose -f docker/docker-compose.yml ps

dev-init:
rm -rf docker/volumes/db/data
docker compose -f docker/docker-compose.yml build backend-core
docker compose -f docker/docker-compose.yml up --build

prod:
docker compose build backend-core
docker compose -f docker-compose.yml up --build

test-type:
@if command -v python3 &>/dev/null; then \
python3 -m pyright; \
else \
python -m pyright; \
fi
13 changes: 13 additions & 0 deletions client/tests/github/pull_request_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
import json
import os

from server.event_handler.pull_request import PullRequestEventHandler

def test_event_handler():
filepath = os.path.join(os.path.dirname(__file__), 'pull_request_event.json')
with open(filepath) as ev:
event = json.load(ev)
handler = PullRequestEventHandler(payload = event, access_token="123")
result = handler.execute()
assert result["success"] == True
25 changes: 0 additions & 25 deletions docs/guides/self_hosting_aws.md
Original file line number Diff line number Diff line change
@@ -1,25 +0,0 @@
## Supabase Budget

|Resources| Instances | Pricing |
|---------|------|------|
| Supabase | 1 | $0


## Infrastructure Budget

|Resources| Instances | Pricing |
|---------|------|------|
| EC2 Container Registry (ECR) | | https://aws.amazon.com/cn/ecr/pricing/
| Route 53 | 1 | $0.53
| Secrets Manager | 1 | $0.40
| S3 | Very Few | https://aws.amazon.com/cn/s3/pricing/
| CloudFront | 2 | $0
| Lambda | 4 | https://aws.amazon.com/cn/lambda/pricing/


## LLM Budget

|Resources| Instances | Pricing |
|---------|------|------|
| OpenAI | - | https://openai.com/pricing/
| Gemini flash | - | $0
10 changes: 5 additions & 5 deletions petercat_utils/rag_helper/task.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import json
from typing import Optional
from github import Github

import boto3

from .git_doc_task import GitDocTask
from .git_issue_task import GitIssueTask
from .git_task import GitTask

from ..utils.env import get_env_variable
from ..data_class import TaskStatus, TaskType
from ..db.client.supabase import get_client

# Create SQS client
sqs = boto3.client("sqs")

from github import Github

from ..utils.env import get_env_variable
from ..data_class import TaskStatus, TaskType
from ..db.client.supabase import get_client

g = Github()

Expand Down
15 changes: 0 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,11 @@ authors = ["raoha.rh <[email protected]>"]
readme = "README.md"
packages = [{include = "petercat_utils"}]

[tool.ruff]
builtins = ["_"]

[pytest]
testpaths = ["tests"]
pythonpath = "."
consider_namespace_packages = "True"
python_files = "test_*.py"
cov="com"
cov-report=["xml","html"]
md_report = true
md_report_verbose = 0
md_report_color = "auto"

[tool.poetry.dependencies]
python = "^3.8"
langchain_community = "^0.2.11"
langchain_openai = "^0.1.20"
langchain_core = "0.2.28"
langchain = "^0.2.12"
supabase = "2.6.0"
pydantic = "2.7.0"
PyGithub = "2.3.0"
Expand Down
1 change: 0 additions & 1 deletion server/agent/bot_builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import AsyncIterator, Optional
from petercat_utils.data_class import ChatData

from agent.base import AgentBuilder
from prompts.bot_builder import generate_prompt_by_user_id
from tools import bot_builder
Expand Down
5 changes: 2 additions & 3 deletions server/agent/qa_chat.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import AsyncIterator, Optional
from petercat_utils import get_client
from petercat_utils.data_class import ChatData

from agent.base import AgentBuilder
from prompts.bot_template import generate_prompt_by_repo_name
from petercat_utils import get_client
from petercat_utils.data_class import ChatData
from tools import issue, sourcecode, knowledge, git_info


Expand Down
9 changes: 4 additions & 5 deletions server/auth/get_user_info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Annotated
from fastapi import Cookie
from fastapi import Cookie, HTTPException
import httpx
import secrets
import random
Expand All @@ -8,8 +8,7 @@
from .get_oauth_token import get_oauth_token
from petercat_utils import get_client, get_env_variable

def random_str(N):
return ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(N))
random_str = lambda N: ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(N))

AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN")

Expand Down Expand Up @@ -71,7 +70,7 @@ async def get_user_id(petercat_user_token: Annotated[str | None, Cookie()] = Non
user_info = await getUserInfoByToken(petercat_user_token)
return user_info['id']

except Exception:
except Exception as e:
return None

async def get_user_access_token(petercat_user_token: Annotated[str | None, Cookie()] = None):
Expand All @@ -84,5 +83,5 @@ async def get_user_access_token(petercat_user_token: Annotated[str | None, Cooki
access_token = await getUserAccessToken(user_id=user_info['id'])
print(f"get_user_access_token: user_info={user_info}, access_token={access_token}")
return access_token
except Exception:
except Exception as e:
return None
1 change: 0 additions & 1 deletion server/bot/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from petercat_utils import get_client
from petercat_utils.data_class import RAGGitDocConfig
from petercat_utils import git_doc_task

from prompts.bot_template import generate_prompt_by_repo_name

g = Github()
Expand Down
7 changes: 4 additions & 3 deletions server/dao/authorizationDAO.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from supabase.client import Client

from petercat_utils.db.client.supabase import get_client

import json
from dao.BaseDAO import BaseDAO
from models.authorization import Authorization
from supabase.client import Client, create_client

from petercat_utils.db.client.supabase import get_client

class AuthorizationDAO(BaseDAO):
client: Client
Expand Down
3 changes: 1 addition & 2 deletions server/event_handler/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
from typing import Any
from github import Github, Auth
from github import GithubException
from agent.qa_chat import agent_chat

from petercat_utils.data_class import ChatData, Message, TextContentBlock

from agent.qa_chat import agent_chat


class DiscussionEventHandler:
event: Any
Expand Down
3 changes: 1 addition & 2 deletions server/event_handler/issue.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Any
from github import Github, Auth
from github import GithubException
from agent.qa_chat import agent_chat

from petercat_utils.data_class import ChatData, Message, TextContentBlock

from agent.qa_chat import agent_chat


class IssueEventHandler:
event: Any
Expand Down
13 changes: 7 additions & 6 deletions server/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os

import uvicorn
from fastapi import FastAPI
from starlette.middleware.sessions import SessionMiddleware
from fastapi.middleware.cors import CORSMiddleware
Expand All @@ -8,7 +10,6 @@

# Import fastapi routers
from routers import bot, health_checker, github, rag, auth, chat, task

AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN")
API_AUDIENCE = get_env_variable("API_IDENTIFIER")
CLIENT_ID = get_env_variable("AUTH0_CLIENT_ID")
Expand Down Expand Up @@ -49,8 +50,8 @@
app.include_router(task.router)


# if __name__ == "__main__":
# 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")))
if __name__ == "__main__":
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")))
2 changes: 1 addition & 1 deletion server/models/authorization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
import json
from pydantic import BaseModel, field_serializer
from typing import Dict
from typing import Any, Dict

class Authorization(BaseModel):
token: str
Expand Down
6 changes: 1 addition & 5 deletions server/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[pytest]
testpaths = tests
rootdir=server
consider_namespace_packages = True
python_files = test_*.py
cov=com
cov-report=xml,html
python_files = test_*.py
5 changes: 3 additions & 2 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ python-dotenv==1.0.0
openai
mangum
langserve
langchain_community>=0.2.11
langchain>=0.2.12
langchain_community
langchain
langchain-openai
PyGithub
GitPython
python-multipart
Expand Down
Empty file removed server/routers/__init__.py
Empty file.
5 changes: 3 additions & 2 deletions server/routers/auth.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Annotated
from fastapi import APIRouter, Cookie, Request, HTTPException, status, Response

from fastapi.responses import RedirectResponse
import httpx
from petercat_utils import get_client, get_env_variable

from auth.get_user_info import generateAnonymousUser, getAnonymousUserInfoByToken, getUserInfoByToken
from petercat_utils import get_client, get_env_variable
from auth.get_user_info import generateAnonymousUser, getAnonymousUserInfoByToken, getUserAccessToken, getUserInfoByToken

AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN")

Expand Down
Loading