Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for both str and Path when executing a prompt #158

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtime/prompty/prompty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def execute(
>>> inputs = {"name": "John Doe"}
>>> result = prompty.execute("prompts/basic.prompty", inputs=inputs)
"""
if isinstance(prompt, str):
if isinstance(prompt, (str, Path)):
path = Path(prompt)
if not path.is_absolute():
# get caller's path (take into account trace frame)
Expand Down Expand Up @@ -571,7 +571,7 @@ async def execute_async(
>>> inputs = {"name": "John Doe"}
>>> result = await prompty.execute_async("prompts/basic.prompty", inputs=inputs)
"""
if isinstance(prompt, str):
if isinstance(prompt, (str, Path)):
path = Path(prompt)
if not path.is_absolute():
# get caller's path (take into account trace frame)
Expand Down
16 changes: 14 additions & 2 deletions runtime/prompty/tests/test_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import pytest
import prompty
from prompty.invoker import InvokerFactory
from pathlib import Path
from typing import Union

from tests.fake_azure_executor import FakeAzureExecutor
from tests.fake_serverless_executor import FakeServerlessExecutor
Expand Down Expand Up @@ -36,9 +38,14 @@ def fake_azure_executor():
"prompts/groundedness.prompty",
"prompts/faithfulness.prompty",
"prompts/embedding.prompty",
Path("prompts/basic.prompty"),
Path("prompts/context.prompty"),
Path("prompts/groundedness.prompty"),
Path("prompts/faithfulness.prompty"),
Path("prompts/embedding.prompty"),
],
)
def test_basic_execution(prompt: str):
def test_basic_execution(prompt: Union[str, Path]):
result = prompty.execute(prompt)
print(result)

Expand All @@ -52,9 +59,14 @@ def test_basic_execution(prompt: str):
"prompts/groundedness.prompty",
"prompts/faithfulness.prompty",
"prompts/embedding.prompty",
Path("prompts/basic.prompty"),
Path("prompts/context.prompty"),
Path("prompts/groundedness.prompty"),
Path("prompts/faithfulness.prompty"),
Path("prompts/embedding.prompty"),
],
)
async def test_basic_execution_async(prompt: str):
async def test_basic_execution_async(prompt: Union[str, Path]):
result = await prompty.execute_async(prompt)
print(result)

Expand Down