Skip to content

Commit

Permalink
feat: init pytest workflow
Browse files Browse the repository at this point in the history
feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow

feat: init pytest workflow
  • Loading branch information
RaoHai committed Aug 21, 2024
1 parent 6fa72d3 commit bc3f47f
Show file tree
Hide file tree
Showing 34 changed files with 131 additions and 120 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/after-success.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: After Success

on:
workflow_run:
workflows: ["PR Tests"]
types:
- completed

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Confirm Success
run: echo "Previous workflow was successful!"
5 changes: 3 additions & 2 deletions .github/workflows/aws-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy Backend to Preview ECS

on:
workflow_run:
workflows: ["Build And Test"]
workflows: ["PR Tests"]
types:
- completed

Expand All @@ -14,11 +14,12 @@ 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: production
environment: Preview
strategy:
fail-fast: true

Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: PR Tests

on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Run a simple test
run: echo "Running tests..."
40 changes: 0 additions & 40 deletions .github/workflows/server-test.yml

This file was deleted.

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

.ruff_cache/

# production
build
Expand Down
25 changes: 0 additions & 25 deletions Makefile

This file was deleted.

25 changes: 25 additions & 0 deletions docs/guides/self_hosting_aws.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## 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,21 +1,21 @@
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

# 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

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


g = Github()

TABLE_NAME = "rag_tasks"
Expand Down
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@ 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
6 changes: 3 additions & 3 deletions server/agent/bot_builder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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
from agent.base import AgentBuilder
from prompts.bot_builder import generate_prompt_by_user_id
from tools import bot_builder


TOOL_MAPPING = {
Expand Down
6 changes: 3 additions & 3 deletions server/agent/qa_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
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 ..tools import issue, sourcecode, knowledge, git_info
from agent.base import AgentBuilder
from prompts.bot_template import generate_prompt_by_repo_name
from tools import issue, sourcecode, knowledge, git_info


def get_tools(bot_id: str, token: Optional[str]):
Expand Down
9 changes: 5 additions & 4 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, HTTPException
from fastapi import Cookie
import httpx
import secrets
import random
Expand All @@ -8,7 +8,8 @@
from .get_oauth_token import get_oauth_token
from petercat_utils import get_client, get_env_variable

random_str = lambda N: ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(N))
def random_str(N):
return ''.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 @@ -70,7 +71,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 as e:
except Exception:
return None

async def get_user_access_token(petercat_user_token: Annotated[str | None, Cookie()] = None):
Expand All @@ -83,5 +84,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 as e:
except Exception:
return None
2 changes: 1 addition & 1 deletion server/bot/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from petercat_utils.data_class import RAGGitDocConfig
from petercat_utils import git_doc_task

from ..prompts.bot_template import generate_prompt_by_repo_name
from prompts.bot_template import generate_prompt_by_repo_name

g = Github()

Expand Down
4 changes: 2 additions & 2 deletions server/dao/authorizationDAO.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from petercat_utils.db.client.supabase import get_client

from ..dao.BaseDAO import BaseDAO
from ..models.authorization import Authorization
from dao.BaseDAO import BaseDAO
from models.authorization import Authorization

class AuthorizationDAO(BaseDAO):
client: Client
Expand Down
4 changes: 2 additions & 2 deletions server/dao/repositoryConfigDAO.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from supabase.client import Client
from petercat_utils.db.client.supabase import get_client

from ..dao.BaseDAO import BaseDAO
from ..models.repository import RepositoryConfig
from dao.BaseDAO import BaseDAO
from models.repository import RepositoryConfig
class RepositoryConfigDAO(BaseDAO):
client: Client

Expand Down
2 changes: 1 addition & 1 deletion server/event_handler/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from petercat_utils.data_class import ChatData, Message, TextContentBlock

from ..agent.qa_chat import agent_chat
from agent.qa_chat import agent_chat


class DiscussionEventHandler:
Expand Down
2 changes: 1 addition & 1 deletion server/event_handler/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from petercat_utils.data_class import ChatData, Message, TextContentBlock

from ..agent.qa_chat import agent_chat
from agent.qa_chat import agent_chat


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

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


# Import fastapi routers
from .routers import bot, health_checker, github, rag, auth, chat, task
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")
Expand Down
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 Any, Dict
from typing import Dict

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

from ..auth.get_user_info import generateAnonymousUser, getAnonymousUserInfoByToken, getUserInfoByToken
from auth.get_user_info import generateAnonymousUser, getAnonymousUserInfoByToken, getUserInfoByToken

AUTH0_DOMAIN = get_env_variable("AUTH0_DOMAIN")

Expand Down
6 changes: 3 additions & 3 deletions server/routers/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from petercat_utils import get_client
from typing import Annotated, Optional

from ..auth.get_user_info import get_user_id
from ..bot.builder import bot_builder, bot_info_generator
from ..type_class.bot import BotUpdateRequest, BotCreateRequest
from auth.get_user_info import get_user_id
from bot.builder import bot_builder, bot_info_generator
from type_class.bot import BotUpdateRequest, BotCreateRequest

router = APIRouter(
prefix="/api/bot",
Expand Down
6 changes: 3 additions & 3 deletions server/routers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from fastapi.responses import StreamingResponse
from petercat_utils.data_class import ChatData

from ..agent import qa_chat, bot_builder
from ..verify.rate_limit import verify_rate_limit
from ..auth.get_user_info import get_user_access_token, get_user_id
from agent import qa_chat, bot_builder
from verify.rate_limit import verify_rate_limit
from auth.get_user_info import get_user_access_token, get_user_id


router = APIRouter(
Expand Down
Loading

0 comments on commit bc3f47f

Please sign in to comment.