Skip to content

Commit

Permalink
Merge pull request #593 from airtai/dev
Browse files Browse the repository at this point in the history
Add PRs #580, #582 and #585
  • Loading branch information
davorrunje committed Apr 2, 2024
2 parents bc061f7 + 6e35fe5 commit 9a841c5
Show file tree
Hide file tree
Showing 28 changed files with 1,808 additions and 1,989 deletions.
113 changes: 67 additions & 46 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ jobs:

test:
runs-on: ubuntu-latest
strategy:
matrix:
pytest-marks: ["openai", "not openai"]
fail-fast: false
services:
postgres:
image: postgres:13
Expand Down Expand Up @@ -67,7 +71,7 @@ jobs:
- name: Create client secrets file
run: echo '{"web":{"client_id":"dummy.apps.googleusercontent.com","project_id":"dummy-id","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"dummy-secret","redirect_uris":["http://localhost:9000/login/callback"]}}' > client_secret.json
- name: Test
run: pytest tests/ci/
run: pytest tests/ci/ -m "${{ matrix.pytest-marks }}"

docker_build_push:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -102,50 +106,67 @@ jobs:
if: github.ref_name == 'main' || github.ref_name == 'dev'
run: docker push ghcr.io/$GITHUB_REPOSITORY --all-tags

# https://github.com/marketplace/actions/alls-green#why
check: # This job does nothing and is only used for the branch protection
if: github.event.pull_request.draft == false

needs:
- test
- static_analysis
- docker_build_push

runs-on: ubuntu-latest

steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1 # nosemgrep
with:
jobs: ${{ toJSON(needs) }}

deploy:
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
needs: [static_analysis, test, docker_build_push]
if: github.ref_name == 'main' || github.ref_name == 'dev'
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DEVELOPER_TOKEN: ${{ secrets.DEVELOPER_TOKEN }}
PORT: ${{ vars.PORT }}
runs-on: ubuntu-22.04
defaults:
run:
shell: bash
needs: [check]
if: github.ref_name == 'main' || github.ref_name == 'dev'
env:
GITHUB_USERNAME: ${{ github.actor }}
GITHUB_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DEVELOPER_TOKEN: ${{ secrets.DEVELOPER_TOKEN }}
PORT: ${{ vars.PORT }}

DOMAIN: ${{ github.ref_name == 'main' && vars.PROD_DOMAIN || vars.STAGING_DOMAIN }}
REDIRECT_DOMAIN: ${{ github.ref_name == 'main' && vars.PROD_REDIRECT_DOMAIN || vars.STAGING_REDIRECT_DOMAIN }}
CLIENT_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_CLIENT_SECRET || secrets.STAGING_CLIENT_SECRET }}
DATABASE_URL: ${{ github.ref_name == 'main' && secrets.PROD_DATABASE_URL || secrets.STAGING_DATABASE_URL }}
REACT_APP_API_URL: ${{ github.ref_name == 'main' && secrets.PROD_REACT_APP_API_URL || secrets.STAGING_REACT_APP_API_URL }}
AZURE_API_VERSION: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_API_VERSION || secrets.STAGING_AZURE_API_VERSION }}
AZURE_API_ENDPOINT: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_API_ENDPOINT || secrets.STAGING_AZURE_API_ENDPOINT }}
AZURE_GPT4_MODEL: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_GPT4_MODEL || secrets.STAGING_AZURE_GPT4_MODEL }}
AZURE_GPT35_MODEL: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_GPT35_MODEL || secrets.STAGING_AZURE_GPT35_MODEL }}
AZURE_OPENAI_API_KEY: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_OPENAI_API_KEY || secrets.STAGING_AZURE_OPENAI_API_KEY }}
INFOBIP_API_KEY: ${{ github.ref_name == 'main' && secrets.PROD_INFOBIP_API_KEY || secrets.STAGING_INFOBIP_API_KEY }}
INFOBIP_BASE_URL: ${{ github.ref_name == 'main' && secrets.PROD_INFOBIP_BASE_URL || secrets.STAGING_INFOBIP_BASE_URL }}
SSH_KEY: ${{ github.ref_name == 'main' && secrets.PROD_SSH_KEY || secrets.STAGING_SSH_KEY }}
steps:
- uses: actions/checkout@v3 # Don't change it to cheackout@v4. V4 is not working with container image.
# This is to fix GIT not liking owner of the checkout dir - https://github.com/actions/runner/issues/2033#issuecomment-1204205989
- run: chown -R $(id -u):$(id -g) $PWD

- run: if [[ $GITHUB_REF_NAME == "main" ]]; then echo "TAG=latest" >> $GITHUB_ENV ; else echo "TAG=dev" >> $GITHUB_ENV ; fi;

- run: echo "PATH=$PATH:/github/home/.local/bin" >> $GITHUB_ENV
- run: 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- run: eval $(ssh-agent -s)
- run: mkdir -p ~/.ssh
- run: chmod 700 ~/.ssh
- run: ssh-keyscan "$DOMAIN" >> ~/.ssh/known_hosts
- run: chmod 644 ~/.ssh/known_hosts
- run: echo "$SSH_KEY" | base64 --decode > key.pem
- run: chmod 600 key.pem

- run: ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$DOMAIN" "docker images"
- run: bash scripts/deploy.sh

- run: rm key.pem
DOMAIN: ${{ github.ref_name == 'main' && vars.PROD_DOMAIN || vars.STAGING_DOMAIN }}
REDIRECT_DOMAIN: ${{ github.ref_name == 'main' && vars.PROD_REDIRECT_DOMAIN || vars.STAGING_REDIRECT_DOMAIN }}
CLIENT_SECRET: ${{ github.ref_name == 'main' && secrets.PROD_CLIENT_SECRET || secrets.STAGING_CLIENT_SECRET }}
DATABASE_URL: ${{ github.ref_name == 'main' && secrets.PROD_DATABASE_URL || secrets.STAGING_DATABASE_URL }}
REACT_APP_API_URL: ${{ github.ref_name == 'main' && secrets.PROD_REACT_APP_API_URL || secrets.STAGING_REACT_APP_API_URL }}
AZURE_API_VERSION: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_API_VERSION || secrets.STAGING_AZURE_API_VERSION }}
AZURE_API_ENDPOINT: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_API_ENDPOINT || secrets.STAGING_AZURE_API_ENDPOINT }}
AZURE_GPT4_MODEL: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_GPT4_MODEL || secrets.STAGING_AZURE_GPT4_MODEL }}
AZURE_GPT35_MODEL: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_GPT35_MODEL || secrets.STAGING_AZURE_GPT35_MODEL }}
AZURE_OPENAI_API_KEY: ${{ github.ref_name == 'main' && secrets.PROD_AZURE_OPENAI_API_KEY || secrets.STAGING_AZURE_OPENAI_API_KEY }}
INFOBIP_API_KEY: ${{ github.ref_name == 'main' && secrets.PROD_INFOBIP_API_KEY || secrets.STAGING_INFOBIP_API_KEY }}
INFOBIP_BASE_URL: ${{ github.ref_name == 'main' && secrets.PROD_INFOBIP_BASE_URL || secrets.STAGING_INFOBIP_BASE_URL }}
SSH_KEY: ${{ github.ref_name == 'main' && secrets.PROD_SSH_KEY || secrets.STAGING_SSH_KEY }}
steps:
- uses: actions/checkout@v3 # Don't change it to cheackout@v4. V4 is not working with container image.
# This is to fix GIT not liking owner of the checkout dir - https://github.com/actions/runner/issues/2033#issuecomment-1204205989
- run: chown -R $(id -u):$(id -g) $PWD

- run: if [[ $GITHUB_REF_NAME == "main" ]]; then echo "TAG=latest" >> $GITHUB_ENV ; else echo "TAG=dev" >> $GITHUB_ENV ; fi;

- run: echo "PATH=$PATH:/github/home/.local/bin" >> $GITHUB_ENV
- run: 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )'
- run: eval $(ssh-agent -s)
- run: mkdir -p ~/.ssh
- run: chmod 700 ~/.ssh
- run: ssh-keyscan "$DOMAIN" >> ~/.ssh/known_hosts
- run: chmod 644 ~/.ssh/known_hosts
- run: echo "$SSH_KEY" | base64 --decode > key.pem
- run: chmod 600 key.pem

- run: ssh -o StrictHostKeyChecking=no -i key.pem azureuser@"$DOMAIN" "docker images"
- run: bash scripts/deploy.sh

- run: rm key.pem
8 changes: 4 additions & 4 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,23 @@
"filename": ".github/workflows/pipeline.yml",
"hashed_secret": "afc848c316af1a89d49826c5ae9d00ed769415f3",
"is_verified": false,
"line_number": 41,
"line_number": 45,
"is_secret": false
},
{
"type": "Secret Keyword",
"filename": ".github/workflows/pipeline.yml",
"hashed_secret": "48ca756d77c7d21242d537bb15aed63b5acd5edd",
"is_verified": false,
"line_number": 47,
"line_number": 51,
"is_secret": false
},
{
"type": "Basic Auth Credentials",
"filename": ".github/workflows/pipeline.yml",
"hashed_secret": "afc848c316af1a89d49826c5ae9d00ed769415f3",
"is_verified": false,
"line_number": 49,
"line_number": 53,
"is_secret": false
}
],
Expand All @@ -157,5 +157,5 @@
}
]
},
"generated_at": "2024-03-25T11:19:29Z"
"generated_at": "2024-03-29T06:02:55Z"
}
22 changes: 13 additions & 9 deletions captn/captn_agents/backend/teams/_campaign_creation_team.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Any, Callable, Dict, List, Optional, Tuple

from ..tools._campaign_creation_team_tools import (
add_create_ad_group_with_ad_and_keywords_to_agent,
)
from ..tools._campaign_creation_team_tools import create_campaign_creation_team_toolbox
from ..tools._function_configs import (
ask_client_for_permission_config,
change_google_account_config,
Expand Down Expand Up @@ -109,13 +107,19 @@ def __init__(
self._create_initial_message()

def _add_tools(self) -> None:
self.toolbox = create_campaign_creation_team_toolbox(
user_id=self.user_id,
conv_id=self.conv_id,
clients_question_answer_list=self.clients_question_answer_list,
)
for agent in self.members:
add_create_ad_group_with_ad_and_keywords_to_agent(
agent=agent,
user_id=self.user_id,
conv_id=self.conv_id,
clients_question_answer_list=self.clients_question_answer_list,
)
self.toolbox.add_to_agent(agent, agent)
# add_create_ad_group_with_ad_and_keywords_to_agent(
# agent=agent,
# user_id=self.user_id,
# conv_id=self.conv_id,
# clients_question_answer_list=self.clients_question_answer_list,
# )

@staticmethod
def _is_termination_msg(x: Dict[str, Optional[str]]) -> bool:
Expand Down
20 changes: 12 additions & 8 deletions captn/captn_agents/backend/teams/_daily_analysis_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ def get_ad_groups_report(
keywords=keywords,
ad_group_ads=ad_group_ads,
)
campaign_ad_groups_dict[ad_group_result["campaign"]["id"]][
ad_group.id
] = ad_group
campaign_ad_groups_dict[ad_group_result["campaign"]["id"]][ad_group.id] = (
ad_group
)

return campaign_ad_groups_dict

Expand Down Expand Up @@ -311,9 +311,9 @@ def get_daily_ad_group_ads_report(
cost_micros=ad_group_ad_result["metrics"]["costMicros"],
),
)
ad_group_ads_dict[ad_group_ad_result["adGroup"]["id"]][
ad_group_ad.id
] = ad_group_ad
ad_group_ads_dict[ad_group_ad_result["adGroup"]["id"]][ad_group_ad.id] = (
ad_group_ad
)

return ad_group_ads_dict

Expand All @@ -338,7 +338,9 @@ def compare_reports(
_calculate_update_metrics(campaign_id, campaign, report_yesterday) # type: ignore
for ad_group_id, ad_group in campaign.ad_groups.items():
_calculate_update_metrics(
ad_group_id, ad_group, report_yesterday[campaign_id].ad_groups # type: ignore
ad_group_id,
ad_group,
report_yesterday[campaign_id].ad_groups, # type: ignore
)
for keyword_id, keyword in ad_group.keywords.items():
_calculate_update_metrics(
Expand Down Expand Up @@ -379,7 +381,9 @@ def get_daily_report_for_customer(
customer_ids=[customer_id],
query=query,
)
currency = ast.literal_eval(query_result)[customer_id][0]["customer"]["currencyCode"] # type: ignore
currency = ast.literal_eval(query_result)[customer_id][0]["customer"][
"currencyCode"
] # type: ignore
return DailyCustomerReports2(
customer_id=customer_id, currency=currency, campaigns=compared_campaigns_report
)
Expand Down
Loading

0 comments on commit 9a841c5

Please sign in to comment.