Skip to content

Commit

Permalink
Add user agent to prompty standalone execution (#3475)
Browse files Browse the repository at this point in the history
# Description

Add capability to pass extra headers when using prompty

# 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 Jun 28, 2024
1 parent ea1dd04 commit 4e7f1ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/promptflow-core/promptflow/core/_prompty_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def convert_prompt_template(template, inputs, api):
def prepare_open_ai_request_params(model_config, template, connection):
params = copy.copy(model_config.parameters)
if isinstance(connection, AzureOpenAIConnection):
params["extra_headers"] = {"ms-azure-ai-promptflow-called-from": "promptflow-core"}
params.setdefault("extra_headers", {}).update({"ms-azure-ai-promptflow-called-from": "promptflow-core"})
params["model"] = model_config._model

if model_config.api == "completion":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

from promptflow.client import load_flow
from promptflow.core import AzureOpenAIModelConfiguration
try:
from ..._user_agent import USER_AGENT
except ImportError:
USER_AGENT = None


class RelevanceEvaluator:
Expand Down Expand Up @@ -44,7 +48,13 @@ def __init__(self, model_config: AzureOpenAIModelConfiguration):
if model_config.api_version is None:
model_config.api_version = "2024-02-15-preview"

prompty_model_config = {"configuration": model_config}
prompty_model_config = {
"configuration": model_config,
}

prompty_model_config.update({"parameters": {"extra_headers": {"x-ms-user-agent": USER_AGENT}}})\
if USER_AGENT and isinstance(model_config, AzureOpenAIModelConfiguration) else None

current_dir = os.path.dirname(__file__)
prompty_path = os.path.join(current_dir, "relevance.prompty")
self._flow = load_flow(source=prompty_path, model=prompty_model_config)
Expand Down

0 comments on commit 4e7f1ff

Please sign in to comment.