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

Add non-docstring alternative for prompts #1338

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Quexington
Copy link

@Quexington Quexington commented Dec 14, 2024

Not sure if there's any appetite for this but I figured after diving into it I might as well float it out there.

This PR adds a way to define a prompt that does not exclude the possibility of adding a docstring. It seems reasonable enough to assume that users of the library might want to provide docstrings for their arguments to the prompt that is not itself a part of the prompt.

@outlines.prompt
def my_complicated_prompt(complicated_argument: str):
  """
  This is a prompt that utilized this cool technique you can read about here:
  https://some.website
  
  Parameters
  ----------
  complicated_argument : 
      this argument will help the model to do x, y, z and should fit within these parameters
      for maximum effectiveness
  """
  
  _ = "The actual prompt is here: {{complicated_argument}}"

In addition, making special use of a dunder attribute seems like it could be good to avoid (granted that the suggested parsing of bytecode doesn't seem much more agreeable).

I considered another name for the variable like TEMPLATE but was stopped in my tracks by flake8 who understandably gave me an F841 unused variable warning. Obviously not something you'd want to pass down to library consumers so _ it is.

Worth noting this doesn't actually fix automatic doc generation like with pydoc because that looks at the after-the-prompt-wrapper instance of the Prompt class and gives less than helpful information. Actually, after using functools.update_wrapper, the docstring actually can be made to be helpful for these tools.

@Quexington Quexington marked this pull request as draft December 14, 2024 04:48
@Quexington Quexington marked this pull request as ready for review December 15, 2024 23:23
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.

1 participant