Add support for documentation content exceeding token limits (#1670)

* - Add support for documentation content exceeding token limits via two phase operation:
1. Ask LLM to rank headings which are most likely to contain an answer to a user question
2. Provide the corresponding files for the LLM to search for an answer.

- Refactor of help_docs to make the code more readable
- For the purpose of getting canonical path: git providers to use default branch and not the PR's source branch.
- Refactor of token counting and making it clear on when an estimate factor will be used.

* Code review changes:
1. Correctly handle exception during retry_with_fallback_models (to allow fallback model to run in case of failure)
2. Better naming for default_branch in bitbucket cloud provider
This commit is contained in:
sharoneyal
2025-04-03 11:51:26 +03:00
committed by GitHub
parent ceaca3e621
commit 14971c4f5f
9 changed files with 505 additions and 187 deletions

View File

@ -92,7 +92,7 @@ class BitbucketProvider(GitProvider):
return ("", "")
workspace_name, project_name = repo_path.split('/')
else:
desired_branch = self.get_pr_branch()
desired_branch = self.get_repo_default_branch()
parsed_pr_url = urlparse(self.pr_url)
scheme_and_netloc = parsed_pr_url.scheme + "://" + parsed_pr_url.netloc
workspace_name, project_name = (self.workspace_slug, self.repo_slug)
@ -470,6 +470,16 @@ class BitbucketProvider(GitProvider):
def get_pr_branch(self):
return self.pr.source_branch
# This function attempts to get the default branch of the repository. As a fallback, uses the PR destination branch.
# Note: Must be running from a PR context.
def get_repo_default_branch(self):
try:
url_repo = f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/"
response_repo = requests.request("GET", url_repo, headers=self.headers).json()
return response_repo['mainbranch']['name']
except:
return self.pr.destination_branch
def get_pr_owner_id(self) -> str | None:
return self.workspace_slug