Facebook
From Syed Anas Shah, 8 Months ago, written in Python.
This paste is a reply to Re: Python Developer from Syed Anas Shah - go back
Embed
Viewing differences between Re: Python Developer and Re: Re: Python Developer
import openai

def generate_tech_product_review(product_name, generate_product_review(product_name, product_notes):
    openai.api_key = 'YOUR_OPENAI_API_KEY'  

    introduction = f"Introducing the {product_name} – A Game Changer in the Tech World!\n\n"
    heading = f"

{product_name} Review

\n\n"
    
    # HTML formatting for product notes
    product_notes_html = "\n".join([f"
  • {note}
  • " for note in product_notes.split('\n') if note.strip()])
        product_notes_section = f"

    Product Notes:

    \n
      \n{product_notes_html}\n
    \n\n"

        prompt = f"Generate a captivating review for the {product_name}:\n\nReview:"
        prompt = introduction + heading + product_notes_section + prompt

        response = openai.Completion.create(
            engine="text-davinci-003",  # We can use other engines like gpt-3.5-turbo or gpt-4
            prompt=prompt,
            max_tokens=800  # Adjust the length as needed
        )

        review = response.choices[0].text.strip()
        
        # HTML formatting
        html_content = f"""
        <html>
        <head>
            <title>{product_name} Review</title>
        </head>
        <body>
            {heading}
            

    {introduction}


            

    {review}


        </body>
        </html>
        """
        
        return html_content