Skip to content

Instantly share code, notes, and snippets.

@rfeers
Created November 4, 2023 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfeers/f5de49435e55110e3689963232e6ac67 to your computer and use it in GitHub Desktop.
Save rfeers/f5de49435e55110e3689963232e6ac67 to your computer and use it in GitHub Desktop.
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)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment