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

Passing a pathlib.Path to prompty.execute raises an AttributeError exception #157

Open
snosrap opened this issue Jan 1, 2025 · 0 comments

Comments

@snosrap
Copy link

snosrap commented Jan 1, 2025

Passing a pathlib.Path to prompty.execute raises an AttributeError exception

Steps to recreate:

from pathlib import Path

import prompty
import prompty.azure

for prompt in [
    "test.prompty",
    Path("test.prompty"),
]:
    try:
        response = prompty.execute(prompt)
        print(type(prompt), "PASS")
    except Exception as e:
        print(type(prompt), "FAIL", e)

Expected:

<class 'str'> PASS
<class 'pathlib.WindowsPath'> PASS

Observed:

<class 'str'> PASS
<class 'pathlib.WindowsPath'> FAIL 'WindowsPath' object has no attribute 'sample'

Comments

In execute and execute_async there are calls to if isinstance(prompt, str). This checks if the prompt is a path that needs to be loaded (rather than an instance of a prompty class). These checks could be changed to if isinstance(prompt, (str, os.PathLike)) to support both str and pathlib.Path parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant