Back to Prompts
Package 4 prompts

Smart Abstraction Prompts

AI prompts for smart abstraction from the LearnWithHasan AI Coding Building Blocks (Architecture).

#1 Coding Assistant

Create an AI Wrapper Function

Start here - the core pattern for AI apps From the Smart Abstraction AI Coding Building Block.

Prompt
Create a smart AI wrapper function called generate_with_ai() that tries multiple AI providers with automatic fallback.

Language: [Python, JavaScript, TypeScript, etc.]

Provider priority (try in this order):
1. [OpenAI GPT-4 / Claude / Gemini]: primary, fastest
2. [Claude / OpenAI / Gemini]: backup
3. Return a cached/default response if all fail

Requirements:
1. Try the primary provider first
2. If it fails (timeout, rate limit, error), try the backup
3. If backup fails, return a graceful fallback (cached response or helpful error message)
4. Log which provider actually handled the request
5. Add reasonable timeouts so failed providers don't hang forever

Keep it simple. I just want to understand the pattern. Show me:
- The wrapper function itself
- How to call it from my code
- How to add a new provider to the chain later

I'm learning, so explain each part simply.
#2 Coding Assistant

Smart Scraping with Fallbacks

For scraping apps that need reliability From the Smart Abstraction AI Coding Building Block.

Prompt
Create a smart scraping function that tries multiple methods with automatic fallback.

Language: [Python, JavaScript, etc.]

Fallback chain:
1. Try scraping with [BeautifulSoup/Cheerio/Puppeteer]: free, fast
2. If blocked or failed, try [ScraperAPI/Apify/Browserless]: paid but reliable
3. If all scraping fails, return cached data from previous successful scrape

Requirements:
1. The main function should just take a URL and return the data
2. All the fallback logic should be hidden inside the function
3. Log which method worked (helps with debugging and cost tracking)
4. Handle common failures: timeouts, 403 forbidden, rate limits, CAPTCHAs
5. Cache successful responses so we have a fallback for next time

This is for scraping [describe what you're scraping: product prices, articles, etc.]

Show me the pattern so I can adapt it. Explain why each fallback makes sense.

I'm learning, so keep explanations simple.
#3 Coding Assistant

Configure a Provider Priority Chain

For building flexible multi-provider systems From the Smart Abstraction AI Coding Building Block.

Prompt
Help me build a configurable provider chain for [AI generation / scraping / payments / email].

Language: [Python, JavaScript, TypeScript, etc.]

I want to:
1. Define providers in a config (name, function, priority, cost)
2. Try them in priority order
3. Track which provider succeeded
4. Optionally skip expensive providers when cheaper ones work

Example providers:
- [List your providers, e.g., OpenAI, Claude, local model]
- [Or: BeautifulSoup, ScraperAPI, cached data]
- [Or: Stripe, PayPal, manual invoice]

Requirements:
1. Easy to add/remove providers without changing core logic
2. Each provider has a timeout (don't wait forever for a dead service)
3. Configurable retry count per provider
4. Log the full chain of attempts (for debugging)
5. Return which provider worked alongside the result

Make it production-ready but explain everything simply. I want to understand the pattern so I can extend it later.
#4 Coding Assistant

Explain My Existing Wrapper

Review and improve existing wrapper code From the Smart Abstraction AI Coding Building Block.

Prompt
I have some code that wraps an external API but I'm not sure if it's doing fallbacks correctly. Please review it.

Here's my wrapper code:
[paste your wrapper function here]

Please explain:
1. What does this wrapper do? (one sentence)
2. Does it have fallback logic? If so, what's the fallback chain?
3. What happens if ALL options fail?
4. Are there any gaps? (missing timeouts, no logging, silent failures)
5. How could I add another provider to the chain?

Also suggest improvements for:
- Better error handling
- Adding retry logic
- Logging which provider worked
- Caching successful responses for emergency fallback

Assume I'm learning this pattern and explain simply.
20 views