Skip to content

Commit

Permalink
Using token Cache to reduce token get calls (#3491)
Browse files Browse the repository at this point in the history
# Description

Please add an informative description that covers that changes made by
the pull request and link all relevant issues.

# All Promptflow Contribution checklist:
- [ ] **The pull request does not introduce [breaking changes].**
- [ ] **CHANGELOG is updated for new features, bug fixes or other
significant changes.**
- [ ] **I have read the [contribution guidelines](../CONTRIBUTING.md).**
- [ ] **Create an issue and link to the pull request to get dedicated
review from promptflow team. Learn more: [suggested
workflow](../CONTRIBUTING.md#suggested-workflow).**

## General Guidelines and Best Practices
- [ ] Title of the pull request is clear and informative.
- [ ] There are a small number of commits, each of which have an
informative message. This means that previously merged commits do not
appear in the history of the PR. For more information on cleaning up the
commits in your PR, [see this
page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).

### Testing Guidelines
- [ ] Pull request includes test coverage for the included changes.
  • Loading branch information
singankit authored Jul 2, 2024
1 parent 8fb8cbe commit e16aa03
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/promptflow-evals/promptflow/evals/evaluate/_eval_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def get_metrics_url(self):
def _get_token(self):
# We have to use lazy import because promptflow.azure
# is an optional dependency.
return self._ml_client._credential.get_token(EvalRun._SCOPE)
from promptflow.azure._utils._token_cache import ArmTokenCache
return ArmTokenCache().get_token(self._ml_client._credential)

def request_with_retry(
self, url: str, method: str, json_dict: Dict[str, Any], headers: Optional[Dict[str, str]] = None
Expand All @@ -270,7 +271,7 @@ def request_with_retry(
if headers is None:
headers = {}
headers["User-Agent"] = f"promptflow/{VERSION}"
headers["Authorization"] = f"Bearer {self._get_token().token}"
headers["Authorization"] = f"Bearer {self._get_token()}"
retry = Retry(
total=EvalRun._MAX_RETRIES,
connect=EvalRun._MAX_RETRIES,
Expand Down

0 comments on commit e16aa03

Please sign in to comment.