Writing Prompt Templates can be super messy. Prompt templates are long, hard to manage, and must be continuously tweaked to improve and keep the same throughout the application.

With Prem, writing and managing prompts can be super easy. The Templates tab inside the launchpad helps you write as many prompts you need and use it inside the SDK to make your application running using those prompts.

✌️ This guide shows you how to create a prompt template and use it using Prem SDK.

1

Go the Templates section of Launchpad

Inside the Templates section, hit the ➕ button to create a new prompt template.

Prem
2

Design your prompt template

Designing a new template is easy. Add a name to the prompt template and provide the contents of the template. A prompt template contains several variables that are passed dynamically during runtime. You can enter your variable name inside ${}. Here is an example:

You will be given a document, and you need to extract essential information 
from the document and return it as a JSON. The JSON should have the following keys:

1. name: should extract the name of a person
2. place: should extract the name of a place or which sounds like a place
3. date-time: should extract some date-time like text or which sound 
like someday in a week or time. 

Here is an example of how it should look like:

Input document: "Alice told me a big fish is in our nearby pond. 
We should go catch some fish with Alice and Ron this Sunday." 

Output: 

{
    "name" : ["Alice", "Ron"]
    "place":  ["nearby pond"]
    "date-time": ["Sunday"]
}
If you do not find any entity for some key, leave it a blank list. 
Here is your document ${doc}

In the application it should look like this:

Prem

Hit the ➕ create button and your prompt template is created.

3

Using the prompt template with Prem SDK

Once we create a prompt template, we can see all our list of prompt templates.

Prem

Now, you need to copy the template ID to use it. The template ID appears just below the name of the prompt template. Here, in case you missed it.

Prem

Once copied we can use it in our SDK.

import os 
from premai import Prem 

client = Prem(
    api_key=os.environ.get("PREMAI_API_KEY")
)

# Change the project and template ID when using from your account. 
project_id = 1234 
template_id = "12069ce8-xxxx-xxx-xxx-xxx"

msg = """
I am playing in a garden on a fine sunday
evening. I then went to my friend Tara's place
and then went for movies in the city center mall. 
"""

# Provide the template variables here:
messages = [
    {
        "role": "user",
        "template_id": template_id,
        "params": {
            "doc": msg
        }
    }
]

response = client.chat.completions.create(
    project_id=project_id,
    messages=messages,
)
print(response.choices[0].message.content)

That’s it. Thats how easy it is to create and manage prompt templates in Prem.