Skip to content

Commit

Permalink
[prompty] load_flow(source=path/to/prompty) is callable (#3015)
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
lalala123123 authored Apr 25, 2024
1 parent 935176f commit 39c80d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
path = Path(path)
# prompty folder path
code = Path(code)
self._core_prompty = CorePrompty(path=path, **kwargs)
super().__init__(code=code, path=path, data=data, content_hash=None, **kwargs)

@property
Expand All @@ -52,6 +53,9 @@ def _load(cls, path: Path, raise_error=True, **kwargs):
)
return cls(path=path, code=path.parent, data=data, **kwargs)

def __call__(self, *args, **kwargs):
return self._core_prompty(*args, **kwargs)

# endregion overrides

# region SchemaValidatableMixin
Expand Down
10 changes: 10 additions & 0 deletions src/promptflow-devkit/tests/sdk_cli_test/e2etests/test_prompty.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from openai.types.chat import ChatCompletion

from promptflow._sdk._pf_client import PFClient
from promptflow.client import load_flow
from promptflow.core import AsyncPrompty, Flow, Prompty
from promptflow.core._errors import (
InvalidConnectionError,
Expand All @@ -19,6 +20,7 @@
)
from promptflow.core._model_configuration import AzureOpenAIModelConfiguration
from promptflow.core._prompty_utils import convert_model_configuration_to_connection
from promptflow.exceptions import UserErrorException

TEST_ROOT = PROMPTFLOW_ROOT / "tests"
DATA_DIR = TEST_ROOT / "test_configs/datas"
Expand Down Expand Up @@ -171,6 +173,14 @@ def test_prompty_callable(self, pf: PFClient):
Prompty.load(source=f"{PROMPTY_DIR}/prompty_example.prompty", model=model_dict)
assert "Cannot configure model config and connection" in ex.value.message

prompty = load_flow(source=f"{PROMPTY_DIR}/prompty_example.prompty")
result = prompty(question="what is the result of 1+1?")
assert "2" in result

with pytest.raises(UserErrorException) as ex:
prompty("what is the result of 1+1?")
assert "Prompty can only be called with keyword arguments." in ex.value.message

def test_prompty_async_call(self):
async_prompty = AsyncPrompty.load(source=f"{PROMPTY_DIR}/prompty_example.prompty")
with pytest.raises(MissingRequiredInputError) as e:
Expand Down

0 comments on commit 39c80d6

Please sign in to comment.