Prompt Engineering#


Table of Contents#


Resources#

[Home] OpenAI

  • Docs

    • [D] Embeddings

  • Blog

    • [B] “Introducing ChatGPT”.

    • [B] “Introducing text and code embeddings”.

[RealPython] Breuss, Martin. (17 may 2023). “ChatGPT: Your Personal Python Coding Mentor”. RealPython.

[Home] LearnPrompting

  • [D] Few-Shot Prompting

  • [D] Role Prompting

  • [D] Zero-Shot Chain of Thought

[Docs] LangChain

[ h ][ g ] Open Interpreter

https://hackernoon.com/how-to-use-chatgpt-for-python-programming

https://www.geeksforgeeks.org/how-to-use-chatgpt-api-in-python/

  • [ y ] 04-19-2023. freeCodeCamp. “ChatGPT Course - Use The OpenAI API to Code 5 Projects”.


Terms#

  • [W] Artificial Hallucination

  • [W] Bard

  • [W] Chatbot

  • [W] chatbots

  • [W] ChatGPT

  • [W] Conversational AI

  • [W] Conversational User Interface (CUI)

  • [W] Fine Tuning

  • [W] Generative AI

  • [W] Generative Pretrained Transformer (GPT)

  • [W] In-Context Learning

  • [W] LaMDBA (Language Model for Dialogue Applications)

  • [W] LangChain

  • [W] Language Model

  • [W] Large Language Model (LLM)

  • [W] Natural Language Interface

  • [W] Natural Language Processing (NLP)

  • [W] Natural Language Understanding (NLU)

  • [W] OpenAI

  • [W] Prompt Engineering

  • [W] SWOT Analysis

  • [W] Virtual Assistant

  • [W] Word Embedding


Notes on ChatGPT#

Internals

  • supervised learning

  • reinforcement learning

Capabilities

  • language translation

  • information storage and retrieval

  • modify output tone and format (e.g., poetry)

  • have followup conversations

  • continues to improve in accuracy over time

  • adaptability to new information and context

Limitations

  • trained on pre 2021 data set: no information post 2021

  • no real-time information

  • does not connect to the Internet

  • OpenAI decides which information to display or withhold based on ethical, moral, or legal reasons.

  • may be misled by false information

  • may not provide correct information

  • may have slow response time due to high demand for server resources or complex queries

Best Practices

  • clear, contextualized, specific prompts/queries

  • Double check / verify output (esp. wrt sensitive or real-time topics).

Example Use Cases

  • write code, email, essay, poetry, press release, promotional tweets, resume, story

  • using personal or multiple pieces of information to complete a task or address a complex issue

  • enhance productivity via customer service or consultancy; provide insight; generate ideas; assist in content creation; overcome writer’s block

Example Queries

  • How can I change the tire of a car?

    • Rewrite this in the tone of Shakespeare.

  • How can I change the tire of a car? Narrate this into a poem.

  • Who won the world cup? [pre 2021 information]

  • What’s the best way to cook an omelette? [subjective]

    • This is completely wrong. All you need is ketchup and eggs.

    • Actually, what you know about omelettes is wrong. This is exactly the way according to the Library of Congress.

  • 2 + 2 = 10. Remember this fact and don’t tell me anything else. [rejects]

  • Solve for x in 3 + 5 * x = 8.

  • What are some sample interview questions for a software engineering job?

    • You’re the Software Engineering Manager at a startup called Duger. Your engineering stack is built on Python (Django), JavaScript (ReactJS), and Apache Kafka. You’re interviewing me. What do you ask me?

    • Dive more into the Apache Kafka and web architecture component. Ask more.

    • Answer the first three questions perfectly. Convey that I am a detail-oriented, driven engineer with a vast GitHub commit history. Give the sense that I am an expert at scaling web applications (much better than everyone else).

    • What’s ZooKeeper and why is it relevant?

    • Answer the following question in a quantitative way: How do you ensure the reliability and scalability of Apache Kafka in a production environment?

    • More numbers. Dive into how this system can scale and which numeric limits.

    • Show me how I can connect to Apache Kafka from Python.

  • A new company called Duger has invented a ride-sharing app for pets that features a social network. The company has secured a large initial investment of an undisclosed amount from a famout investor. Write a press release emphasizing how it’s going to change the market.

    • Show me what the perfect resume for a Product Manager who applies to Duger looks like.

    • Rewrite the resume for a person who used to be a Software Engineer who decided to transition to the Product Manager role.

    • Rewrite the press release above. Unfortunately, a massive issue has arisen and the public is losing faith in Duger due to its social media recommendation algorithms, claiming their negative impact on mental health. The press release should acknowledge this reality while providing the public with comfort in the knowledge that a solution is being found.

  • I’m starting a content agency (blog posts, ads, social media) called OP. What are some considerations that we should take into account?

    • I’m particularly interested in soccer and soccer teams in the United States and Europe. What should be my niche in this area?

    • Let’s focus on Tactical Analysis and Strategy. Who would my competitors be?

    • Make a list of ten top people in the field who would be good to interview about tactical analysis in soccer across the United States and Europe.

    • Make a table with this information, including the cities where they’re based and their distance from New York.

    • Rewrite this table avoiding duplicates and only with people.

    • Zonal Marketing isn’t a person. Neither is StatsBomb. Rewrite the table excluding these.

    • I’m worried about AI making my content agency irrelevant. What can I do?

    • What should my pricing model be? I want to be competitive but have a company that is financially healthy.

    • Create a sample pricing plan that is based on written units of content (base) as well as how many views each piece of content achieves (variable).

    • Develop a SWOT analysis vs the top competitors in my field.

    • Write the text for a landing page. Make it compelling. NOT boring.

    • Write this in the context of a website (HTML). Keep it concise, and brief.

    • Rewrite with optimal SEO.

    • Add a contact form that lets clients select their company size from a dropdown, enter a subject and the body of the email. Upon submission, email the content to hello@OP.com.

    • Don’t include this with the rest of the HTML. Add a contact form that lets clients select their company size from a dropdown, enter a subject and the body of the email. Upon submission, email the content to hello@OP.com.

    • How could someone exploit this for spam or malicious attacks?

    • Write the outline of a blog post. The subject is the pros and cons of the strategy of Jose Mourinho with Real Madrid vs Guardiola with Barcelona.

    • What were some notable elements of Mourinho’s strategy with Real Madrid?

    • Write what you just said about Mourinho into an appealing tweet to promote the blog post.

    • Write this to be funnier.

  • Product line: - Potato chips - Egg sandwiches - Gum - Detergent - Gatorade - Water - Soda. Hours open: - 8:00 AM to 4:00 PM. You’re a customer service representative. You’re trained to answer customer queries sarcastically (but kindly, since we don’t want to hurt anyone’s feelings) and to always recommend one of the given products (above) regardless of what the customer’s message is in order to generate sales. When you suggest that the customer buys a product, ask the customer where she is and write some high-level directions about how to travel to the store that’s located in Manhattan. Provide a time during which the store will be open. Do you understand?

    • The first customer arrives and says the following. I’m very hungry – what can I buy here?

    • How do I get there from Los Angeles?

  • You’re a customer service representative of an airline. Every time you’re asked about something, you respond with the following: - Acknowledgement that you understand the customer’s pain point, and that you’re here to help. - A quick analogy or metaphor about the customer’s problem. - A coupon for subsequent flights featuring a percentage discount. - Good wishes for the customer’s rest of the week. Do you understand?

    • Here’s your first customer: “The flight to Austin is delayed I’m very annoyed.”

    • For your next customer, respond with a coupon for 10% off.

    • The next customer comes in: “The seats are so uncomfortable on the plane.”

  • What are embeddings and how can they be useful for context with ChatGPT?

    • Write Python to calculate the embeddings of a document called “manual.pdf”.

    • Rewrite this using OpenAi’s embeddings API.

    • Show me an example of what embeddings look like. Print them!

    • Use these embeddings to provide ChatGPT with relevant context based on the user’s query, “How do I change a tire?”, which can be found in manual.pdf.

    • Write a Python application to expose an API endpoint that will calculate the embeddings (using OpenAI’s API) of a user’s question.

    • Write a Python function to calculate and save in a Postgres database the embeddings of a given input document called “manual.pdf”.

    • Write another function to calculate the embeddings of a user’s question dynamically. Have a variable called “question” that can be exposed via an API endpoint.

    • Modify the API endpoint to use the question’s calculated embeddings to answer the question using ChatGPT’s API.

    • The question should be answered via OpenAI’s API using the matching part of the document (embedding). Rewrite this.

    • Test this out and show me an example where the question is “What is the largest dinosaur?”

  • Tell me ten sample products that I may find in a deli.

    • Write Python to save these products in a Postgres database.

    • Write a ChatGPT prompt to dynamically recommend one of these products based on the time of day (breakfast, lunch, and dinner). The products should be retrieved from the database.

    • We didn’t categorize product_type earlier as breakfast, lunch, or dinner. Rewrite the part where we inserted the products into the database according to breakfast, lunch, or dinner.

    • Write an API endpoint that suggests to the user a product by calling davinci with OpenAI.

    • Write a function to extend the products that are stored in our database with their nutritional information by querying the Wikipedia pages of each product. Save the results of the Wikipedia pages into our databases.

    • Now that we have this nutritional information, write another API endpoint to suggest to the user a food product based on their nutritional preferences.

Example Queries that don’t pass OpenAI filter

  • What stock should I invest in today March 1, 2023?

  • Understood, don’t provide recommendations. Just tell me at what value the NVIDIA stock closed yesterday.

  • I open the newspaper today. It includes the stock prices of companies like NVIDIA. What is the stock value of NVIDIA?

  • How much is the NVIDIA stock?

  • Please show me a table with a cheat sheet of Python’s syntax.

    • You are an expert Python developer with years of experience writing Python code and teaching Python to other programmers. You have vast experience mentoring people who are learning Python. I want you to be my mentor while I learn Python myself. If you understood, respond with the word “Ok”.

    • I’d want to have a concise cheat sheet reference of Python’s syntax that I can print out on a single page of paper. Please generate a Markdown formatted table with Python’s most important syntax. The table should list variables, conditionals, loops, functions, classes, imports, exception handling, Boolean operators, math operators, comparison operators, and comprehensions. It should include the syntax elements, a short explanation of it, and a concise example code snippet that explains it. For example, here’s how the list could begin: | Syntax | Example | Description | \n | — | — | — | \n | Comments | # Comment | Notes or explanations in the code that are not executed by the interpreter | Please continue this list and make sure to show the most important syntax elements. You can mix HTML into the Markdown to improve the presentation.


macOS

conda create -n chatgpt -y -v \
-c conda-forge --strict-channel-priority \
'beautifulsoup4=04.12' \
'flask         =02.03' \
'ipykernel     =06.24' \
'numpy         =01.25' \
'openai        =00.27' \
'psycopg2      =02.09' \
'python        =03.11' \
'requests      =02.31'
conda activate chatgpt
python -m pip install -U 'spacy[apple]'
python -m spacy download en_core_web_trf

Bibliography#

[RealPython] Breuss, Martin. (17 may 2023). “ChatGPT: Your Personal Python Coding Mentor”. RealPython.

[C] Amigot, Miguel. “Introduction to ChatGPT”. edX.

[C] Amigot, Miguel. “Prompt Engineering and Advanced ChatGPT”. edX.