harrison/prompt_examples
Harrison Chase 2 years ago
parent eb54c0b847
commit 71cd6523a4

@ -35,6 +35,7 @@ class LLMMathExample(BaseExample):
question: str
answer: str
@property
def formatted(self) -> str:
return f"Question: {self.question}\n\n{self.answer}"

@ -12,6 +12,7 @@ class ReActExample(BaseExample):
question: str
answer: str
@property
def formatted(self) -> str:
return f"Question: {self.question}\n{self.answer}"

@ -12,6 +12,7 @@ class SelfAskWithSearchExample(BaseExample):
question: str
answer: str
@property
def formatted(self) -> str:
return f"Question: {self.question}\n{self.answer}"

@ -6,8 +6,8 @@ from pydantic import BaseModel
class BaseExample(BaseModel, ABC):
"""Base class for examples."""
@abstractmethod
@property
@abstractmethod
def formatted(self) -> str:
"""Returns a formatted example as a string."""
@ -16,6 +16,7 @@ class SimpleExample(BaseExample):
text: str
@property
def formatted(self) -> str:
return self.text

@ -116,7 +116,8 @@ class DynamicPrompt(BaseModel, BasePrompt):
)
return values
@root_validator()
# Needs to be pre=True to convert to the right type.
@root_validator(pre=True)
def convert_examples(cls, values: Dict) -> Dict:
values["examples"] = convert_to_examples(values["examples"])
return values

@ -51,8 +51,8 @@ Question: {question}
Answer:"""
input_variables = ["question"]
example_separator = "\n\n"
prefix = """Test Prompt:\n\n"""
suffix = """\n\nQuestion: {question}\nAnswer:"""
prefix = """Test Prompt:"""
suffix = """Question: {question}\nAnswer:"""
examples = [
"""Question: who are you?\nAnswer: foo""",
"""Question: what are you?\nAnswer: bar""",

Loading…
Cancel
Save