fix prompt saving (#4987)

will add unit tests
This commit is contained in:
Davis Chase
2023-05-20 08:21:52 -07:00
committed by GitHub
parent 27e63b977a
commit 3bc0bf0079
4 changed files with 130 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ from contextlib import contextmanager
from pathlib import Path
from typing import Iterator
from langchain.output_parsers import RegexParser
from langchain.prompts.few_shot import FewShotPromptTemplate
from langchain.prompts.loading import load_prompt
from langchain.prompts.prompt import PromptTemplate
@@ -160,3 +161,24 @@ def test_loading_few_shot_prompt_example_prompt() -> None:
suffix="Input: {adjective}\nOutput:",
)
assert prompt == expected_prompt
def test_loading_with_output_parser() -> None:
with change_directory():
prompt = load_prompt("prompt_with_output_parser.json")
expected_template = """\
Given the following question and student answer, \
provide a correct answer and score the student answer.
Question: {question}
Student Answer: {student_answer}
Correct Answer:\
"""
expected_prompt = PromptTemplate(
input_variables=["question", "student_answer"],
output_parser=RegexParser(
regex="(.*?)\nScore: (.*)",
output_keys=["answer", "score"],
),
template=expected_template,
)
assert prompt == expected_prompt