review = """ | |
I bought last week the latest Samsung washing machine. | |
The product is too expensive for what it is. | |
I won't recommend it to anyone. | |
""" | |
from langchain.llms import OpenAI | |
from langchain import PromptTemplate | |
llm = OpenAI(model_name="text-davinci-003") | |
template = """ | |
For any new review that is sent to you, extract the following information: | |
Product: What product is the buyer reviewing?\ | |
Answer the name of the product. If this information is not found, output unknown. | |
Reason why: Why's the buyer satisfied or unsatisfied? | |
Answer the main reason why. Answer unknown if you do not find the info. | |
Satisfied: Is the buyer satisfied with the product? \ | |
Answer True if yes, False if not or unknown. | |
Format the output as JSON with the following keys: | |
Product | |
Satisfaction | |
Reason | |
review: {review} | |
""" | |
prompt = PromptTemplate( | |
input_variables=["review"], | |
template=template, | |
) | |
final_prompt = prompt.format(review=review ) | |
print(f"LLM Output: {llm(final_prompt)}") |