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

DynamicPrompt class creation #49

Merged
merged 8 commits into from
Nov 5, 2022
Merged

DynamicPrompt class creation #49

merged 8 commits into from
Nov 5, 2022

Conversation

sjwhitmore
Copy link
Contributor

Checking that this structure looks generally ok -- going to sub in logic where the TODO comment is then add a test.

langchain/prompt.py Outdated Show resolved Hide resolved
langchain/prompt.py Outdated Show resolved Hide resolved
langchain/prompt.py Show resolved Hide resolved
@sjwhitmore
Copy link
Contributor Author

messed up the git state a bit initially but think i fixed it with the branch force push

@sjwhitmore
Copy link
Contributor Author

also added callable for returning length attribute of prompt

@sjwhitmore sjwhitmore changed the title WIP: DynamicPrompt class creation (todo actually make it dynamic) DynamicPrompt class creation Nov 4, 2022
langchain/prompt.py Outdated Show resolved Hide resolved


class DynamicPrompt(BaseModel, BasePrompt):
r"""Schema to represent a dynamic prompt for an LLM.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the r for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah i forgot the linter told me to do this
./langchain/prompt.py:133:1: D301 Use r""" if any backslashes in a docstring

langchain/prompt.py Outdated Show resolved Hide resolved
langchain/prompt.py Outdated Show resolved Hide resolved
langchain/prompt.py Outdated Show resolved Hide resolved
langchain/prompt.py Outdated Show resolved Hide resolved
tests/unit_tests/test_dynamic_prompt.py Outdated Show resolved Hide resolved
super super super super long, this will affect the example right?"""
test_short_question = "Short question?"

assert dynamic_prompt.format(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comments here as above. maybe could do a helper function to factor out common stuff?


def test_dynamic_prompt_trims_examples() -> None:
"""Test dynamic prompt can be successfully constructed from examples."""
longer_template = """Test Prompt:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a complete nit but i hate how this looks visually lol. i ran into this on prev prs - can we either put the prompt outside the test function OR do something like

    shortest_template = (
"Test Prompt:\n"
"Question: {question}\n"
Answer:"
)

or is there a better way to do it? to be clear the part i dont like is the weird indent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i agree! reformatted

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

Successfully merging this pull request may close these issues.

2 participants