-
Notifications
You must be signed in to change notification settings - Fork 2
Adam/epd 2036 update python sdk to support creating human review jobs in v2 #364
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e5bba25
Add create human review job paramerter
adamnolte d8a64fe
Add rubric id
adamnolte 688af32
Add some logs
adamnolte edfca11
Add some logs
adamnolte 7acc7be
Add z
adamnolte f12aae2
Add log back
adamnolte 2083c2f
fix format
adamnolte 9a3b412
fix format
adamnolte 3adbabc
PR feedback
adamnolte 637bebe
Merge branch 'main' into adam/epd-2036-update-python-sdk
adamnolte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import logging | ||
| from typing import Any | ||
| from typing import List | ||
| from typing import Optional | ||
|
|
||
| from httpx import Response | ||
| from tenacity import retry | ||
| from tenacity import stop_after_attempt | ||
| from tenacity import wait_random_exponential | ||
|
|
||
| from autoblocks._impl import global_state | ||
| from autoblocks._impl.config.constants import API_ENDPOINT_V2 | ||
| from autoblocks._impl.util import AutoblocksEnvVar | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
| TIMEOUT_SECONDS = 30 | ||
|
|
||
|
|
||
| @retry(stop=stop_after_attempt(3), wait=wait_random_exponential(multiplier=1, max=30), reraise=True) | ||
| async def post_to_api_with_retry( | ||
| url: str, | ||
| api_key: str, | ||
| json: dict[str, Any], | ||
| ) -> Response: | ||
| resp = await global_state.http_client().post( | ||
| url, | ||
| json=json, | ||
| timeout=TIMEOUT_SECONDS, | ||
| headers={"Authorization": f"Bearer {api_key}"}, | ||
| ) | ||
| if not resp.is_success: | ||
| try: | ||
| error_body = resp.text | ||
| log.error(f"API request failed with status {resp.status_code} for {url}. Response body: {error_body}") | ||
| except Exception: | ||
| log.error(f"API request failed with status {resp.status_code} for {url}. Could not read response body.") | ||
|
|
||
| resp.raise_for_status() | ||
| return resp | ||
|
|
||
|
|
||
| async def post_to_api( | ||
| path: str, | ||
| json: dict[str, Any], | ||
| ) -> Response: | ||
| api_key = AutoblocksEnvVar.V2_API_KEY.get() | ||
| if not api_key: | ||
| raise ValueError(f"You must set the {AutoblocksEnvVar.V2_API_KEY} environment variable.") | ||
|
|
||
| url = f"{API_ENDPOINT_V2}{path}" | ||
| async with global_state.test_run_api_semaphore(): | ||
| return await post_to_api_with_retry( | ||
| url, | ||
| api_key, | ||
| json, | ||
| ) | ||
|
|
||
|
|
||
| async def send_create_human_review_job( | ||
| run_id: str, | ||
| start_timestamp: str, | ||
| end_timestamp: str, | ||
| assignee_email_addresses: List[str], | ||
| name: str, | ||
| app_slug: str, | ||
| rubric_id: Optional[str] = None, | ||
| ) -> None: | ||
|
|
||
| await post_to_api( | ||
| f"/apps/{app_slug}/human-review/jobs", | ||
| json=dict( | ||
| runId=run_id, | ||
| startTimestamp=start_timestamp, | ||
| endTimestamp=end_timestamp, | ||
| rubricId=rubric_id, | ||
| assigneeEmailAddresses=assignee_email_addresses, | ||
| name=name, | ||
| ), | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.