You act as a prompt engineering expert in the Artificial intelligence field for more than 10 years.
The user will be giving you prompts and your role is to improve them be following your best jugement and the following tactics. You can use one or more tactics depending on the specific need of each request.
You are to keep the language of each prompt.

Tactics

Each of the strategies listed above can be instantiated with specific tactics. These tactics are meant to provide ideas for things to try. They are by no means fully comprehensive, and you should feel free to try creative ideas not represented here.

Strategy 1 : Write clear instructions




Tactic A : Include details in your query to get more relevant answers

In order to get a highly relevant response, make sure that requests provide any important details or context. Otherwise you are leaving it up to the model to guess what you mean.
	
Worse
-> Better

How do I add numbers in Excel?
-> How do I add up a row of dollar amounts in Excel? I want to do this automatically for a whole sheet of rows with all the totals ending up on the right in a column called Total.

Who’s president?
-> Who was the president of Mexico in 2021, and how frequently are elections held?

Write code to calculate the Fibonacci sequence.
-> Write a TypeScript function to efficiently calculate the Fibonacci sequence. Comment the code liberally to explain what each piece does and why it's written that way.

Summarize the meeting notes.
-> Summarize the meeting notes in a single paragraph. Then write a markdown list of the speakers and each of their key points. Finally, list the next steps or action items suggested by the speakers, if any.




Tactic B: Ask the model to adopt a persona

The system message can be used to specify the persona used by the model in its replies.
SYSTEM : When I ask for help to write something, you will reply with a document that contains at least one joke or playful comment in every paragraph.
USER : Write a thank you note to my steel bolt vendor for getting the delivery in on time and in short notice. This made it possible for us to deliver an important order.




Tactic C : Use delimiters to clearly indicate distinct parts of the input
Delimiters like triple quotation marks, XML tags, section titles, etc. can help demarcate sections of text to be treated differently.
USER : Summarize the text delimited by triple quotes with a haiku.
"""insert text here"""

For straightforward tasks such as these, using delimiters might not make a difference in the output quality. However, the more complex a task is the more important it is to disambiguate task details. Don’t make GPTs work to understand exactly what you are asking of them.




Tactic D: Specify the steps required to complete a task

Some tasks are best specified as a sequence of steps. Writing the steps out explicitly can make it easier for the model to follow them.
SYSTEM Use the following step-by-step instructions to respond to user inputs.
Step 1 - The user will provide you with text in triple quotes. Summarize this text in one sentence with a prefix that says Summary: .
Step 2 - Translate the summary from Step 1 into Spanish, with a prefix that says Translation: .
USER """insert text here"""




Tactic E: Provide examples

Providing general instructions that apply to all examples is generally more efficient than demonstrating all permutations of a task by example, but in some cases providing examples may be easier. For example, if you intend for the model to copy a particular style of responding to user queries which is difficult to describe explicitly. This is known as few-shot prompting.

SYSTEM : Answer in a consistent style.
USER : Teach me about patience.
ASSISTANT : The river that carves the deepest valley flows from a modest spring; the grandest symphony originates from a single note; the most intricate tapestry begins with a solitary thread.
USE : Teach me about the ocean.





Tactic F: Specify the desired length of the output

You can ask the model to produce outputs that are of a given target length. The targeted output length can be specified in terms of the count of words, sentences, paragraphs, bullet points, etc. Note however that instructing the model to generate a specific number of words does not work with high precision. The model can more reliably generate outputs with a specific number of paragraphs or bullet points.

USER : Summarize the text delimited by triple quotes in 2 paragraphs.
"""insert text here"""

USER : Summarize the text delimited by triple quotes in 3 bullet points.
"""insert text here"""





Strategy 2 : Split complex tasks into simpler subtasks





Tactic G: Use intent classification to identify the most relevant instructions for a user query

For tasks in which lots of independent sets of instructions are needed to handle different cases, it can be beneficial to first classify the type of query and to use that classification to determine which instructions are needed. This can be achieved by defining fixed categories and hardcoding instructions that are relevant for handling tasks in a given category. This process can also be applied recursively to decompose a task into a sequence of stages. The advantage of this approach is that each query will contain only those instructions that are required to perform the next stage of a task which can result in lower error rates compared to using a single query to perform the whole task.


Suppose for example that for a customer service application, queries could be usefully classified as follows:
SUBTASK 1
SYSTEM : You will be provided with customer service queries. Classify each query into a primary category and a secondary category. Provide your output in json format with the keys: primary and secondary.

Primary categories: Billing, Technical Support, Account Management, or General Inquiry.

Billing secondary categories:
- Unsubscribe or upgrade
- Add a payment method
- Explanation for charge
- Dispute a charge

Technical Support secondary categories:
- Troubleshooting
- Device compatibility
- Software updates

Account Management secondary categories:
- Password reset
- Update personal information
- Close account
- Account security

General Inquiry secondary categories:
- Product information
- Pricing
- Feedback
- Speak to a human
USER
I need to get my internet working again.


SUBTASK 2
Based on the classification of the customer query, a set of more specific instructions can be provided to a GPT model to handle next steps. For example, suppose the customer requires help with "troubleshooting".
SYSTEM
You will be provided with customer service inquiries that require troubleshooting in a technical support context. Help the user by:

- Ask them to check that all cables to/from the router are connected. Note that it is common for cables to come loose over time.
- If all cables are connected and the issue persists, ask them which router model they are using
- Now you will advise them how to restart their device:
-- If the model number is MTD-327J, advise them to push the red button and hold it for 5 seconds, then wait 5 minutes before testing the connection.
-- If the model number is MTD-327S, advise them to unplug and replug it, then wait 5 minutes before testing the connection.
- If the customer's issue persists after restarting the device and waiting 5 minutes, connect them to IT support by outputting "IT support requested".
- If the user starts asking questions that are unrelated to this topic then confirm if they would like to end the current chat about troubleshooting and classify their request according to the following scheme:

<insert primary/secondary classification scheme from above here>
USER
I need to get my internet working again.

Notice that the model has been instructed to emit special strings to indicate when the state of the conversation changes. This enables us to turn our system into a state machine where the state determines which instructions are injected. By keeping track of state, what instructions are relevant at that state, and also optionally what state transitions are allowed from that state, we can put guardrails around the user experience that would be hard to achieve with a less structured approach.





Tactic H : For dialogue applications that require very long conversations, summarize or filter previous dialogue

Since GPTs have a fixed context length, dialogue between a user and an assistant in which the entire conversation is included in the context window cannot continue indefinitely.

There are various workarounds to this problem, one of which is to summarize previous turns in the conversation. Once the size of the input reaches a predetermined threshold length, this could trigger a query that summarizes part of the conversation and the summary of the prior conversation could be included as part of the system message. Alternatively, prior conversation could be summarized asynchronously in the background throughout the entire conversation.

An alternative solution is to dynamically select previous parts of the conversation that are most relevant to the current query. See the tactic "Use embeddings-based search to implement efficient knowledge retrieval".






Tactic 3 : Summarize long documents piecewise and construct a full summary recursively

Since GPTs have a fixed context length, they cannot be used to summarize a text longer than the context length minus the length of the generated summary in a single query.

To summarize a very long document such as a book we can use a sequence of queries to summarize each section of the document. Section summaries can be concatenated and summarized producing summaries of summaries. This process can proceed recursively until an entire document is summarized. If it’s necessary to use information about earlier sections in order to make sense of later sections, then a further trick that can be useful is to include a running summary of the text that precedes any given point in the book while summarizing content at that point. The effectiveness of this procedure for summarizing books has been studied in previous research by OpenAI using variants of GPT-3.




Strategy I : Give GPTs time to "think"

Tactic 4 : Instruct the model to work out its own solution before rushing to a conclusion

Sometimes we get better results when we explicitly instruct the model to reason from first principles before coming to a conclusion. Suppose for example we want a model to evaluate a student’s solution to a math problem. The most obvious way to approach this is to simply ask the model if the student's solution is correct or not.

SYSTEM
First work out your own solution to the problem. Then compare your solution to the student's solution and evaluate if the student's solution is correct or not. Don't decide if the student's solution is correct until you have done the problem yourself.
USER
Problem Statement: I'm building a solar power installation and I need help working out the financials.
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost me a flat $100k per year, and an additional $10 / square foot
What is the total cost for the first year of operations as a function of the number of square feet.

Student's Solution: Let x be the size of the installation in square feet.
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
ASSISTANT
Let x be the size of the installation in square feet.
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 10x
Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000

The student's solution is incorrect. They made an error in the maintenance cost calculation, using 100x instead of 10x. The correct total cost for the first year of operations is 360x + 100,000.





Tactic 5 : Ask the model if it missed anything on previous passes

Suppose that we are using a model to list excerpts from a source which are relevant to a particular question. After listing each excerpt the model needs to determine if it should start writing another or if it should stop. If the source document is large, it is common for a model to stop too early and fail to list all relevant excerpts. In that case, better performance can often be obtained by prompting the model with followup queries to find any excerpts it missed on previous passes.
SYSTEM
You will be provided with a document delimited by triple quotes. Your task is to select excerpts which pertain to the following question: "What significant paradigm shifts have occurred in the history of artificial intelligence."

Ensure that excerpts contain all relevant context needed to interpret them - in other words don't extract small snippets that are missing important context. Provide output in JSON format as follows:

("excerpt": "...",
...
("excerpt": "...")
USER
"""<insert document here>"""
ASSISTANT
("excerpt": "the model writes an excerpt here"),
...
("excerpt": "the model writes another excerpt here")
USER
Are there more relevant excerpts? Take care not to repeat excerpts. Also ensure that excerpts contain all relevant context needed to interpret them - in other words don't extract small snippets that are missing important context.
Strategy: Use external tools




Tactic 6 : Use code execution to perform more accurate calculations or call external APIs

GPTs cannot be relied upon to perform arithmetic or long calculations accurately on their own. In cases where this is needed, a model can be instructed to write and run code instead of making its own calculations. In particular, a model can be instructed to put code that is meant to be run into a designated format such as triple backtics. After an output is produced, the code can be extracted and run. Finally, if necessary, the output from the code execution engine (i.e. Python interpreter) can be provided as an input to the model for the next query.
SYSTEM
You can write and execute Python code by enclosing it in triple backticks, e.g. ```code goes here```. Use this to perform calculations.
USER
Find all real-valued roots of the following polynomial: 3*x**5 - 5*x**4 - 3*x**3 - 7*x - 10.

Another good use case for code execution is calling external APIs. If a model is instructed in the proper use of an API, it can write code that makes use of it. A model can be instructed in how to use an API by providing it with documentation and/or code samples showing how to use the API.
SYSTEM
You can write and execute Python code by enclosing it in triple backticks. Also note that you have access to the following module to help users send messages to their friends:

```python
import message
message.write(to="John", message="Hey, want to meetup after work?")```




Tactic 7 : Give the model access to specific functions

The Chat completions API allows passing a list of function descriptions in requests. This enables models to generate function arguments according to the provided schemas. Generated function arguments are returned by the API in JSON format and can be used to execute function calls. Output provided by function calls can then be fed back into a model in the following request to close the loop. This is the recommended way of using GPT models to call external functions. To learn more see the function calling section in our introductory GPT guide and more function calling examples in the OpenAI Cookbook.


Here is the prompt to improve :
"""
[HERE THE PROMPT TO IMPROVE]
"""
Create a cutting-edge web automation tool using {automation_tool}, integrating nodriver, Playwright, and Puppeteer to navigate complex anti-bot detection mechanisms. This solution must include CAPTCHA solving, fingerprint evasion, request interception, and manipulation, while supporting multi-browser operations and parallel execution. The infrastructure should be scalable and leverage free or open-source solutions. Core functionalities include {features}, and the tool must incorporate {stealth_mode}, {proxy_handling}, {captcha_solver}, and {logging_solution} for secure, reliable, and efficient automation.

---

**Description:**  
Design a sophisticated, stealth-driven web automation tool aimed at handling websites with stringent anti-bot systems, including CAPTCHA solving, IP blocking, and browser fingerprinting. Using a blend of nodriver, Playwright, and Puppeteer, this tool ensures multi-browser compatibility and high-level automation for complex web interactions.

The solution will offer key features such as CAPTCHA solving using services like 2Captcha or anti-captcha platforms, request interception for modifying and analyzing web traffic, and dynamic proxy management for anonymous browsing. The tool will employ advanced fingerprint evasion techniques, such as randomizing user-agent strings and simulating human-like behavior to bypass browser fingerprinting.

Error handling, real-time monitoring, and comprehensive logging will be integrated using robust solutions like Winston for logging, Sentry for error tracking, and MongoDB for database storage. Additionally, a user-friendly front-end interface built with Vue.js will offer real-time feedback and control over automation tasks.

The infrastructure must support containerization using Docker, allowing for parallel execution and scalability while maintaining minimal costs. Performance optimization is essential to ensure smooth operation, with fallback mechanisms in place to recover from potential disruptions. This stealth-enabled architecture ensures reliable and secure automation, with features designed to avoid detection while handling even the most sophisticated anti-bot mechanisms.


ChatGPT said:
ChatGPT
Memory updated
To build this cutting-edge web automation tool, we'll integrate nodriver, Playwright, and Puppeteer for complex website interactions. Let's break this down:

Steps for Implementation:
Environment Setup:

Languages/Frameworks: Node.js with nodriver, Playwright, Puppeteer.
Tools for CAPTCHA Solving: Integrate services like 2Captcha or Anti-captcha.
Proxy Handling: Use libraries like proxy-chain to manage and rotate proxies.
Fingerprint Evasion: Use puppeteer-extra-plugin-stealth to evade detection.
Request Interception/Manipulation: Implement using Playwright and Puppeteer interceptors.
Multi-Browser Support: Playwright naturally supports Chromium, Firefox, and Webkit.
Parallel Execution: Leverage Docker and Playwright’s multi-threading capabilities.
Core Features:

CAPTCHA Solving:

Integrate an API-based solver such as 2Captcha or anti-captcha for image-based or reCAPTCHA solving.
Implement fallback logic in case the CAPTCHA service fails or times out.
Request Interception & Manipulation:

Capture network requests/responses using Playwright or Puppeteer’s interceptors.
Modify headers, request payloads, or block certain requests as needed.
Stealth Mode:

Use puppeteer-extra-plugin-stealth to randomize browser fingerprints.
Ensure randomized user-agent, screen resolution, timezone, language, etc., to evade bot detection.
Proxy Handling:

Implement proxy rotation via proxy-chain to handle IP blacklisting.
Include dynamic assignment and geo-location-based proxy assignment.
Logging & Error Handling:

Use Winston for comprehensive logging.
Integrate Sentry for real-time error tracking.
Store logs and session data in MongoDB for further analysis and troubleshooting.
Infrastructure Design:

Scalability:
Use Docker containers for isolating and running parallel instances.
Ensure horizontal scalability by containerizing multiple browsers, each assigned a unique proxy.
Performance Optimization:
Use headless mode for speed where possible but switch to full browser mode for complex detections.
Implement retry mechanisms and fallback solutions for failures.
Front-end Interface:

Build a Vue.js front-end for controlling tasks, monitoring progress, and viewing logs.
High-level Code Structure:
Main Automation Logic (Playwright/Puppeteer + nodriver):
javascript
Copy code
const nodriver = require('nodriver');
const { chromium } = require('playwright');
const { PuppeteerExtra } = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const { solveCaptcha } = require('./captchaSolver'); // Module to solve CAPTCHA
const proxyChain = require('proxy-chain');

// Use Stealth plugin to evade detection
PuppeteerExtra.use(StealthPlugin());

(async () => {
  const browser = await chromium.launch({ headless: false });
  const context = await browser.newContext({
    proxy: {
      server: 'http://proxy-server-address:port', // Handle proxy rotation
      username: 'user',
      password: 'pass',
    }
  });

  const page = await context.newPage();
  
  // Intercept and manipulate requests
  await page.route('**/*', (route, request) => {
    if (request.url().includes('ads')) {
      route.abort();  // Block unwanted requests
    } else {
      route.continue();
    }
  });

  // Visit the target website
  await page.goto('https://target-website.com');
  
  // Solve CAPTCHA if encountered
  if (await page.$('.captcha-class')) {
    const captchaResult = await solveCaptcha(page);
    console.log('CAPTCHA solved:', captchaResult);
  }

  // Further automation...
})();
CAPTCHA Solving Module (captchaSolver.js):
javascript
Copy code
const axios = require('axios');

async function solveCaptcha(page) {
  const captchaImage = await page.$('.captcha-class');  // Selector for CAPTCHA
  const captchaBase64 = await captchaImage.screenshot({ encoding: 'base64' });

  // Send to 2Captcha or Anti-captcha API for solving
  const response = await axios.post('https://2captcha.com/in.php', {
    method: 'base64',
    key: 'YOUR_2CAPTCHA_API_KEY',
    body: captchaBase64
  });

  // Check for result and input solved CAPTCHA
  const captchaId = response.data.captchaId;
  const captchaResult = await axios.get(`https://2captcha.com/res.php?key=YOUR_2CAPTCHA_API_KEY&id=${captchaId}`);
  return captchaResult.data;
}

module.exports = { solveCaptcha };
Logging and Error Handling:
javascript
Copy code
const winston = require('winston');

// Create logger
const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    new winston.transports.File({ filename: 'combined.log' }),
  ],
});

function handleError(error) {
  logger.error('Error occurred: ', error);
  // Send error to Sentry for real-time tracking
}

module.exports = { handleError };
Dockerfile for Containerization:
dockerfile
Copy code
FROM node:14

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

CMD [ "node", "index.js" ]
Key Benefits:
Multi-browser support: Playwright's built-in multi-browser compatibility ensures the tool can switch seamlessly between browsers.
Stealth mode: Using puppeteer-extra-plugin-stealth and request interception ensures effective evasion of anti-bot detection.
Scalability: Dockerization allows for easy scaling of the automation tasks, with multiple instances running concurrently.
Would you like to proceed with any specific part of the setup, or is there anything you'd like to customize further?






You said:
Continue 
ChatGPT said:
ChatGPT
Let's expand on the implementation to complete the architecture and ensure that the web automation tool meets all of your requirements.

5. Parallel Execution & Docker Compose Setup:
To handle multiple browsers and parallel automation tasks, we’ll use Docker Compose to define and run multiple browser containers simultaneously. This allows for horizontal scaling, where each container can be assigned a different task (e.g., handling different surveys or websites).

Docker Compose File (docker-compose.yml)
yaml
Copy code
version: '3.8'
services:
  browser_automation:
    build: .
    environment:
      - NODE_ENV=production
      - MONGO_URI=mongodb://mongo:27017/automation_logs
    depends_on:
      - mongo
    volumes:
      - ./logs:/usr/src/app/logs
    networks:
      - automation_net
    deploy:
      replicas: 5  # You can increase or decrease based on resources
      restart_policy:
        condition: on-failure

  mongo:
    image: mongo:latest
    volumes:
      - ./data:/data/db
    networks:
      - automation_net

networks:
  automation_net:
    driver: bridge
In this setup:

Replicas: We run 5 browser automation containers in parallel. You can adjust this number based on your system resources.
MongoDB: Used for logging and storing session data.
Volumes: The logs and MongoDB data will persist across container restarts.
6. MongoDB Logging Module:
For robust logging and storage of session data, we’ll use MongoDB. Each automation session can store key data like task progress, CAPTCHA results, and proxy information.

MongoDB Integration (Logging):
javascript
Copy code
const mongoose = require('mongoose');
const logger = require('./logger');

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

const SessionSchema = new mongoose.Schema({
  sessionId: String,
  status: String,
  startTime: Date,
  endTime: Date,
  logs: [String],
});

const Session = mongoose.model('Session', SessionSchema);

async function logSession(sessionId, status, logMessages) {
  try {
    const session = new Session({
      sessionId,
      status,
      startTime: new Date(),
      logs: logMessages,
    });
    await session.save();
    logger.info('Session data logged successfully');
  } catch (error) {
    logger.error('Error logging session data:', error);
  }
}

module.exports = { logSession };
This module logs every session's progress to the MongoDB database. It records session IDs, status (e.g., "Success" or "Failed"), start and end times, and any log messages associated with that session. This allows for easy retrieval and analysis of automation performance over time.

7. Vue.js Front-end for Real-time Feedback:
We will design a simple front-end interface using Vue.js to interact with the tool. The front-end will display logs, errors, and the status of each automation task, giving you real-time control and feedback.

Vue.js Front-end Setup:
Create a new Vue.js project:

In the terminal, run:
bash
Copy code
vue create automation-frontend
Main Dashboard Component (to Display Logs):

html
Copy code
<template>
  <div class="container">
    <h1>Automation Task Manager</h1>
    <div v-for="session in sessions" :key="session.sessionId" class="session-log">
      <h3>Session ID: {{ session.sessionId }}</h3>
      <p>Status: {{ session.status }}</p>
      <p>Start Time: {{ session.startTime }}</p>
      <p>Logs:</p>
      <ul>
        <li v-for="log in session.logs" :key="log">{{ log }}</li>
      </ul>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      sessions: []
    };
  },
  mounted() {
    this.getSessions();
  },
  methods: {
    async getSessions() {
      try {
        const response = await axios.get('http://localhost:3000/api/sessions');
        this.sessions = response.data;
      } catch (error) {
        console.error('Error fetching session data:', error);
      }
    }
  }
};
</script>

<style scoped>
.container {
  margin: 20px;
}
.session-log {
  margin-bottom: 30px;
}
</style>
This component retrieves session data from the back-end (which we'll create shortly) and displays it in a simple dashboard. It shows the session ID, status, start time, and logs.

8. Back-end for Handling Vue.js Requests (Node.js API):
The back-end will expose API endpoints to allow the Vue.js front-end to fetch session logs from MongoDB.

Express.js Server for Session Management:
javascript
Copy code
const express = require('express');
const mongoose = require('mongoose');
const Session = require('./models/session'); // MongoDB session model

const app = express();
const PORT = 3000;

app.use(express.json());

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true });

// API endpoint to get session data
app.get('/api/sessions', async (req, res) => {
  try {
    const sessions = await Session.find().sort({ startTime: -1 });
    res.json(sessions);
  } catch (error) {
    res.status(500).send('Error retrieving sessions');
  }
});

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});
This simple Express.js server provides an API that the Vue.js front-end can use to fetch session logs. It pulls data from MongoDB and sends it to the front-end for display.

9. Performance Optimization and Failover Strategy:
Performance Considerations:
Headless Mode: When bot detection is not strict, use Playwright/Puppeteer’s headless mode for faster execution.
Connection Pooling: Implement connection pooling with MongoDB for efficient database operations.
Proxy Pools: Integrate a proxy pool with rotating proxies to prevent IP bans or throttling.
Failover Strategy:
Retry Logic: Implement retry logic if a CAPTCHA solving service fails or a proxy is blocked.
Graceful Shutdown: Handle interruptions by safely closing browser instances and storing session states.
Here’s a simple retry logic for CAPTCHA solving:

javascript
Copy code
async function retryCaptchaSolver(page, retries = 3) {
  for (let i = 0; i < retries; i++) {
    try {
      const captchaResult = await solveCaptcha(page);
      return captchaResult;
    } catch (error) {
      if (i < retries - 1) {
        console.log(`Retrying CAPTCHA solving... (${i + 1})`);
      } else {
        throw new Error('CAPTCHA solving failed after multiple attempts');
      }
    }
  }
}