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

Use Pydantic to suggest and enforce response format #61

Closed
rlouf opened this issue Apr 20, 2023 · 0 comments · Fixed by #66
Closed

Use Pydantic to suggest and enforce response format #61

rlouf opened this issue Apr 20, 2023 · 0 comments · Fixed by #66

Comments

@rlouf
Copy link
Member

rlouf commented Apr 20, 2023

AutoGPT's and BabyAGI's prompts contain instructions regarding the expected output format, but then use custom parsing code for the response. I suggest to let the user define the expected response format with Pydantic, and build the prompt directly from the Pydantic schema.

So the following instruction:

{
    "thoughts":
    {
        "text": "thought",
        "reasoning": "reasoning",
        "plan": "- short bulleted\n- list that conveys\n- long-term plan",
        "criticism": "constructive self-criticism",
        "speak": "thoughts summary to say to user"
    },
}

Could be passed by first defining and decorating the following schema:

import outlines.text as text
from pydantic import BaseModel, Field

@text.response
class Thoughts(BaseModel):
    text: str = Field(description="thought")
    reasoning: str = Field(description="reasoning")
    plan: str = Field(description="short bulleted list that conveys")
    criticism: str = Field(description="constructive self-criticism"
    speak: str = Field(description="thoughts summary to say to users")

So we can do:

import outlines.text as text

@text.prompt
def prompt(schema):
    """RESPONSE FORMAT:
    
     {{schema.description}}
    """

prompt(Thoughts)

And on an LLM response:

answer = Thoughts.parse(llm(query))
@rlouf rlouf closed this as completed Apr 24, 2023
@rlouf rlouf linked a pull request Apr 24, 2023 that will close this issue
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 a pull request may close this issue.

1 participant