Created
November 4, 2023 08:39
-
-
Save rfeers/fa129e4a258bdbc4880707738a2b7025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment