Skip to content

Commit

Permalink
Merge pull request #374 from gitautoai/wes
Browse files Browse the repository at this point in the history
Fix an 404 error: 'Not Found' in get_workflow_run_logs() AND fix an 400 error: 'This model's maximum context length has been exceeded.' in chat_with_ai()
  • Loading branch information
hiroshinishio authored Nov 17, 2024
2 parents fe5e8c4 + cb6477f commit 9a259a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_env_var(name: str) -> str:
OPENAI_FINAL_STATUSES = ["cancelled", "completed", "expired", "failed"]
OPENAI_MAX_ARRAY_LENGTH = 32 # https://community.openai.com/t/assistant-threads-create-400-messages-array-too-long/754574/1
OPENAI_MAX_STRING_LENGTH = 256000 # https://community.openai.com/t/assistant-threads-create-400-messages-array-too-long/754574/5
OPENAI_MAX_CONTEXT_TOKENS = 128000 # https://gitauto-ai.sentry.io/issues/5582421515/events/9a09416e714c4a66bf1bd86916702be2/?project=4506865231200256&referrer=issue_details.related_trace_issue
OPENAI_MAX_CONTEXT_TOKENS = 120000 # Secured 8,000 as a buffer. https://gitauto-ai.sentry.io/issues/5582421515/events/9a09416e714c4a66bf1bd86916702be2/?project=4506865231200256&referrer=issue_details.related_trace_issue
OPENAI_MAX_RETRIES = 3
OPENAI_MAX_TOOL_OUTPUTS_SIZE = 512 * 1024 # in bytes
OPENAI_MAX_TOKENS = 4096
Expand Down
14 changes: 12 additions & 2 deletions services/check_run_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Local imports
import json
from config import (
EMAIL_LINK,
GITHUB_APP_USER_NAME,
STRIPE_PRODUCT_ID_FREE,
SUPABASE_URL,
Expand Down Expand Up @@ -155,11 +156,20 @@ def handle_check_run(payload: CheckRunCompletedPayload) -> None:
# Get the error log from the workflow run
comment_body = "Checking out the error log from the workflow run..."
update_comment(body=comment_body, base_args=base_args, p=20)
error_log: str | None = get_workflow_run_logs(
error_log: str | int | None = get_workflow_run_logs(
owner=owner_name, repo=repo_name, run_id=workflow_run_id, token=token
)
if error_log == 404:
permission_url = (
f"https://github.com/organizations/{owner_name}/settings/installations/{installation_id}/permissions/update"
if owner_type == "Organization"
else f"https://github.com/settings/installations/{installation_id}/permissions/update"
)
comment_body = f"Approve permission(s) to allow GitAuto to access the check run logs here: {permission_url}"
return update_comment(body=comment_body, base_args=base_args)
if error_log is None:
return
comment_body = f"I couldn't find the error log. Contact {EMAIL_LINK} if the issue persists."
return update_comment(body=comment_body, base_args=base_args)

# Plan how to fix the error
comment_body = "Planning how to fix the error..."
Expand Down
2 changes: 2 additions & 0 deletions services/github/actions_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def get_workflow_run_logs(owner: str, repo: str, run_id: int, token: str):
url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/actions/runs/{run_id}/logs"
headers = create_headers(media_type="", token=token)
response = requests.get(url=url, headers=headers, timeout=TIMEOUT)
if response.status_code == 404 and "Not Found" in response.text:
return response.status_code
response.raise_for_status()

# Get the failed step file name
Expand Down

0 comments on commit 9a259a3

Please sign in to comment.