What's Next for Prompt Engineering? PromptPerfect's Prompt as a Service!

Deploy prompts and flexible template prompts as REST API services, and integrate them into your applications with just a few clicks

Web interface for creating a Wild 'N Out style rap battle with service access options and a light blue design

Announcing a brand new feature for PromptPerfect: Prompt as a Service! Now you can host your own flexible prompts on PromptPerfect, generate variants at will, and interact with language and image models via a REST API.

PromptPerfect - Elevate Your Prompts to Perfection with AI Prompt Engineering
Optimize prompts for GPT-4, ChatGPT, StableLM, Claude, MidJourney, DALL-E, StableDiffusion, Kandinsky, and Lexica. Experience automatic prompt engineering done right. Create compelling Text and Image prompts today with our AI prompt generator.

In this post we’ll cover several use cases for Prompt as a Service - though I’m sure you can come up with some ideas yourself!

We’ll cover:

  • How to automate your tiring friendships
  • Building a SaaS (Sandwiches as a Service)
  • Generating knock-off Mona Lisas in the style of different artists

For each of these, we’ll walk through the interface and show you to access your Prompt as a Service using cURL, Python, or JavaScript.

But first, a quick video overview:

0:00
/

Now, let's dive in. Making your prompt servable is as easy as 1, 2, 3:

  1. Write your template
  2. Specify variables with [VAR] or $VAR
  3. Deploy your prompt with one click

You can also switch out your language model (or image model - keep reading for that):

By default, you’ll need a token to access your prompt, but with one click more you can make it publicly accessible:

Prompt as a Service in Action

Automating friendships for fun and profit

I've got this friend called Izzie. Well, that's not his actual name. But he always falls head over heels for some guy and asks:

"Is he into me? Do you think he's into me? He says I'm like a _____ to him"
👨🏻‍🤝‍👨🏽
Izzie isn’t his real name. Any resemblance to people living, dead or undead is purely coincidental.

I think we've all had a friend like Izzie before. Like a sickly kitten that won’t budge from sitting on your keyboard. They’re annoying, but you just feel this instinct to look after them.

But after a while, instincts be damned. That's why I'm going to use Prompt as a Service to automate away this tiring relationship. Like an automatic cat feeder for humans, if you will.

Friendship is priceless about 8 Euros with free shipping

First, we create the prompt via PromptPerfect’s Services tool. We’ll specify a [person] variable which can be switched out for mother, brother, cousin or whatever:

Is this guy into me? He says I'm like a [person] to him

Testing it gives us more or less expected results:

Right now, access is private, so you need a token to access it:

But we can make it publicly accessible for all the Izzies of the world, without the need for tokens:

You can access the service via the REST API:

curl "https://api.promptperfect.jina.ai/4TFmeCo3aSBDlC44Wik8" \\
  -H "x-api-key: token $YOUR_GENERATED_SECRET" \\
  -H "content-type: application/json" \\
  --data '{"parameters": {"person":"stalker"}}'
💡
I've disabled public access so we don’t overload our servers. There could be a lot of Izzies in the world.

That gives the output:

{"code":200,"status":20000,"data":"As an AI language model, I cannot observe the behavior or interactions between you and this person. However, based on the description you provided, it seems like he might not be into you in a romantic way. The term \\"stalker\\" typically has a negative connotation, suggesting that he might feel uncomfortable with your attention. It's important to respect his feelings and boundaries. If you're unsure about his feelings towards you, consider having an open and honest conversation with him about it."}%

That cold hard terminal output won’t make Izzie feel very cared for. If only there were a way to soften the blow.

Hey, everything goes better with Pokémon, right?

To have Pikachu (considered by many to be the most empathic of pocket monsters) break the news, we’ll need to use:

  • cURL - to access our prompt's REST API
  • jq - to pull out the data field
  • Pokemonsay - to make a Pokémon say something (like cowsay, but…Pokémon)

We’ll pipe them together into the following command:

curl "https://api.promptperfect.jina.ai/4TFmeCo3aSBDlC44Wik8" \\
  -H "x-api-key: token $YOUR_GENERATED_SECRET" \\
  -H "content-type: application/json" \\
  --data '{"parameters": {"person":"cousin-in-law"}}' | jq '.data' | pokemonsay -p pikachu

Lo and behold, Pikachu speaks:

I would render this in a code block, but Pikachu refuses to be fenced

With a little bit of code, we’ve reduced our day-to-day effort, helped a friend in need, and brought more Pikachus into this world. All in all, a good day's work!

SaaS: Sandwiches as a Service

Of course, you can easily build your own SaaS on such a service. And by SaaS I mean Sandwiches-as-a-Service.

🏳️‍🌈
In honor of Pride Month, I was going to go with Yakiniku-as-a-Service and title this post "YaaS, Queen". But yakiniku is tragically undervalued in this forsaken world.

Again, we start with a prompt, this time with a few more variables:

You are the head chef at the Sandy Witch's Sandwich Shack, the
best sandwich restaurant in the world. Can you recommend a 
[style] sandwich recipe for me? I have the following 
ingredients: [ingredients]. Please use [units] units.
🥪
This is a really basic prompt. For something better, you can optimize your prompts with PromptPerfect's Streamline function.
I assure you, "4/20 requests" is purely coincidental

PromptPerfect gives us the code to access our Prompt as a Service:

And we’ll adapt the Python snippet in sandwich.py:

#!pip install requests
import requests

url = "https://api.promptperfect.jina.ai/rGzNHnrmfw2dKci7kB8X"

headers = {
    "Content-Type": "application/json"
}

response = requests.post(url, headers=headers, json={
    "parameters": {"style":"fancy", "ingredients":"caramelized onions, gruyere cheese, truffle oil","units":"metric"}
})

print(response.json()['data'])

This gives us the recipe:

Certainly! With those delicious ingredients, I recommend
creating a Truffled Gruyere and Caramelized Onion Grilled
Cheese Sandwich. Here's the recipe:

Ingredients:
- 4 slices of sourdough bread
- 100g caramelized onions (about 1 large onion)
- 150g gruyere cheese, grated
- 2 tbsp truffle oil
- 30g unsalted butter, softened

Instructions:

1. Preheat a large non-stick skillet or griddle over
medium-low heat.

2. Divide the caramelized onions equally among two slices of
sourdough bread, spreading them evenly.

3. Divide the grated gruyere cheese equally among the other
two slices of bread, covering them generously.

4. Carefully close the sandwiches by placing the
onion-covered slices on top of the cheese-covered slices.

5. Spread a thin layer of softened butter on one side of
each sandwich.

6. Drizzle about 1/2 tablespoon of truffle oil onto each
sandwich and gently rub it into the buttered side using your
fingers or a brush.

7. Place the sandwiches buttered-side-down onto the
preheated skillet or griddle and cook for about 3-4 minutes
until golden brown and crispy.

8. While the first side is cooking, spread another thin
layer of softened butter on the top side of each sandwich
and drizzle with another 1/2 tablespoon of truffle oil.

9. Using a spatula, carefully flip each sandwich over and
cook for another 3-4 minutes until golden brown and crispy
on both sides, and the cheese is melted inside.

10. Remove from heat, let sit for about a minute to cool
slightly, then slice in half diagonally to serve.

Enjoy your luxurious Truffled Gruyere and Caramelized Onion
Grilled Cheese Sandwich at The Sandy Witch's Sandwich Shack!

Stay tuned for more posts about sandwiches and PromptPerfect. We’ve got something baking…

Generating images

Prompt as a Service goes way beyond just text. You can also choose from a range of image models, like Stable Diffusion, Kandinsky, DALL-E-2, and more:

We'll use Kandinsky this time as our model, and go for a Mona Lisa vibe, using the prompt:

Create a portrait of the Mona Lisa in the style of [artist]

Since we’ve accessed the API via cURL and Python so far, this time adapt the Javascript code snippet, in a file called monalisa.js:

resp = fetch('https://api.promptperfect.jina.ai/aH4KYaiaf0e1Ermxvuml', {
  headers: {
    'content-type': 'application/json'
  },
  body: JSON.stringify({
    "parameters": { "artist": "andy warhol" },
  }),
  method: 'POST'
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Running this via node monalisa.js will output a URL where you can download your masterpiece:

{
  code: 200,
  status: 20000,
  data: 'https://storage.googleapis.com/prompt-ops.appspot.com/kandinsky-2%2Fc1f90101-08c8-4083-9a8c-07022039d18c.png'
}

Et voilà:

Mona Lisa in the style of Andy Warhol

Get started with Prompt as a Service

These are just some toy examples - As I said before, I’m sure you can come up with something better!

To get started with Prompt as a Service, sign up for PromptPerfect and share your results on our Discord.