Skip to content

Commit

Permalink
Merge branch 'dev' into f/retry-policy-improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
creatorrr authored Oct 5, 2024
2 parents d7acef1 + 8033549 commit 3f11519
Show file tree
Hide file tree
Showing 104 changed files with 14,130 additions and 346 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/bandit-security-check-python-agents-api.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
name: Bandit security check python agents-api
run-name: ${{ github.actor }} is checking the security of the code

on:
pull_request:
branches:
- main
- dev
paths:
- 'agents-api/**'
push:
paths:
- 'agents-api/**'

jobs:
bandit_check:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Lint and typecheck agents-api
run-name: ${{ github.actor }} is linting and typechecking the code
name: Lint agents-api
run-name: ${{ github.actor }} is linting the code

# TODO: Fix CI github actions
# SCRUM-26

on: [pull_request]
on:
pull_request:
paths:
- 'agents-api/**'
push:
paths:
- 'agents-api/**'

jobs:
Lint-And-Format:
Expand Down Expand Up @@ -33,35 +36,17 @@ jobs:
restore-keys: |
${{ runner.os }}-agents-api-poetry-
- name: Cache pytype
uses: actions/cache@v4
with:
path: agents-api/.pytype
key: ${{ runner.os }}-agents-api-pytype-
restore-keys: |
${{ runner.os }}-agents-api-pytype-
- name: Install dependencies
run: |
cd agents-api
poetry install
- name: Typecheck
run: |
cd agents-api
poetry run poe typecheck
- name: Lint and format
run: |
cd agents-api
poetry run poe format
poetry run poe lint
- name: Run tests
run: |
cd agents-api
poetry run poe test
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "refactor: Lint agents-api (CI)"
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/test-agents-api-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test agents-api
run-name: ${{ github.actor }} is testing the code

on:
pull_request:
paths:
- 'agents-api/**'
push:
paths:
- 'agents-api/**'

jobs:
Test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install and configure Poetry
uses: snok/install-poetry@v1

- name: Configure Poetry to use .venv
run: |
cd agents-api
poetry config virtualenvs.in-project true
- name: Cache Poetry virtualenv
uses: actions/cache@v4
with:
path: agents-api/.venv
key: ${{ runner.os }}-agents-api-poetry-${{ hashFiles('agents-api/poetry.lock') }}
restore-keys: |
${{ runner.os }}-agents-api-poetry-
- name: Install dependencies
run: |
cd agents-api
poetry install
- name: Run tests
run: |
cd agents-api
poetry run poe test --fail-limit 1
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
59 changes: 59 additions & 0 deletions .github/workflows/typecheck-agents-api-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Typecheck agents-api
run-name: ${{ github.actor }} is typechecking the code

on:
pull_request:
paths:
- 'agents-api/**'
push:
paths:
- 'agents-api/**'

jobs:
Typecheck:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install and configure Poetry
uses: snok/install-poetry@v1

- name: Configure Poetry to use .venv
run: |
cd agents-api
poetry config virtualenvs.in-project true
- name: Cache Poetry virtualenv
uses: actions/cache@v4
with:
path: agents-api/.venv
key: ${{ runner.os }}-agents-api-poetry-${{ hashFiles('agents-api/poetry.lock') }}
restore-keys: |
${{ runner.os }}-agents-api-poetry-
- name: Cache pytype
uses: actions/cache@v4
with:
path: agents-api/.pytype
key: ${{ runner.os }}-agents-api-pytype-${{ github.base_ref }}
restore-keys: |
${{ runner.os }}-agents-api-pytype-
- name: Install dependencies
run: |
cd agents-api
poetry install
- name: Typecheck
run: |
cd agents-api
poetry run poe typecheck
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
60 changes: 60 additions & 0 deletions agents-api/agents_api/activities/excecute_api_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from typing import Annotated, Any, Optional, TypedDict, Union

import httpx
from beartype import beartype
from pydantic import Field
from temporalio import activity

from ..autogen.openapi_model import ApiCallDef

# from ..clients import integrations
from ..common.protocol.tasks import StepContext
from ..env import testing

# from ..models.tools import get_tool_args_from_metadata


class RequestArgs(TypedDict):
content: Optional[str]
data: Optional[dict[str, Any]]
json_: Optional[dict[str, Any]]
cookies: Optional[dict[str, str]]
params: Optional[Union[str, dict[str, Any]]]


@beartype
async def execute_api_call(
api_call: ApiCallDef,
request_args: RequestArgs,
) -> Any:
try:
async with httpx.AsyncClient() as client:
response = await client.request(
method=api_call.method,
url=str(api_call.url),
headers=api_call.headers,
follow_redirects=api_call.follow_redirects,
**request_args,
)

response_dict = {
"status_code": response.status_code,
"headers": dict(response.headers),
"content": response.content,
"json": response.json(),
}

return response_dict

except BaseException as e:
if activity.in_activity():
activity.logger.error(f"Error in execute_api_call: {e}")

raise


mock_execute_api_call = execute_api_call

execute_api_call = activity.defn(name="execute_api_call")(
execute_api_call if not testing else mock_execute_api_call
)
Loading

0 comments on commit 3f11519

Please sign in to comment.