from langchain.output_parsers import ResponseSchema
from langchain.output_parsers import StructuredOutputParser
response_schemas = [
ResponseSchema(name="product_name", description="Answer the name of the product."),
ResponseSchema(name="satisfaction", description="Answer if the buyer is Satisfied or Unsatisfied."),
ResponseSchema(name="reason", description="Answer the reason why the buyer is satisfied or unsatisfied.")
]
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()
template = """
You are a review checker specialist. You main goal is to extract worth information from any review that is sent to you.
From the following review {review}, extract the following information:
{format_instructions}
"""
prompt = PromptTemplate(
template=template,
input_variables=["review"],
partial_variables={"format_instructions": format_instructions}
)
model = OpenAI(temperature=0)
_input = prompt.format_prompt(review=review)
output = model(_input.to_string())
output_json = output_parser.parse(output)
output_json