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

feat(prompts): The first argument of add_few_shot should be an input model, not a string #60

Closed
ludwiktrammer opened this issue Oct 3, 2024 · 0 comments · Fixed by #67
Assignees
Labels
core Changes to the core package feature New feature or request
Milestone

Comments

@ludwiktrammer
Copy link
Collaborator

ludwiktrammer commented Oct 3, 2024

Currently add_few_shots takes two strings - an arbitrary user message and an arbitrary assistant response to the message.

Instead, the first argument should be of type InputT (i.e., the should be an instance of the pythantic model used to render the prompts). The user message should be then automatically rendered using the user message defined in the prompt class (MyPrompt.user_message) and the input data given as the argument to add_few_shots. This will ensure that the user prompt given in the few-shot examples and the final user prompt are synchronized.

Additionally, the add_few_shots might be able to take both instances of InputT and raw strings - it would use strings directly but when given instances of InputT it would first compile them to strings.

For example, given this pydantic model and prompt:

class WelcomePromptInput(pydantic.BaseModel):
    name: str

class WelcomePrompt(Prompt[WelcomingPromptInput, str]):
    system_prompt = "You are an agent that welcomes the user by name"
    user_prompt = "user's name is {{ name }}"

instead of writing this:

prompt = WelcomePrompt(WelcomePromptInput(name="John"))
prompt.add_few_shot("user's name is Marcin", "Welcome Marcin!")
prompt.add_few_shot("user's name is Beatrice", "Hello Beatrice!")
prompt.add_few_shot("user's name is Alice", "Good Morning Alice!")

you would write:

prompt = WelcomePrompt(WelcomePromptInput(name="John"))
prompt.add_few_shot(WelcomePromptInput(name="Marcin"), "Welcome Marcin!")
prompt.add_few_shot(WelcomePromptInput(name="Beatrice"), "Hello Beatrice!")
prompt.add_few_shot("user's name is Alice", "Good Morning Alice!")

(Note that in reality the prompts might be much longer and more complicated and the values my come from external source like a database)

@ludwiktrammer ludwiktrammer converted this from a draft issue Oct 3, 2024
@ludwiktrammer ludwiktrammer added this to the Ragbits 0.3 milestone Oct 7, 2024
@ludwiktrammer ludwiktrammer linked a pull request Oct 7, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from In Progress to Done in ragbits Oct 8, 2024
@mhordynski mhordynski modified the milestones: Ragbits 0.3, Ragbits 0.2 Oct 10, 2024
@micpst micpst added feature New feature or request core Changes to the core package labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Changes to the core package feature New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants