Quickstart

Using AI21 Studio, you can solve challenging text understanding and generation tasks. Its straightforward API and interactive playground allows you to get started in minutes, without any prior knowledge in LLMs.

Below is a quickstart guide to cover all the basics you need in order to start building your solution. After that, you should feel comfortable using our large language models to start and solve your own use-case.

Some basics

A language model takes some text as input and produces a likely continuation. You can think of it as an exceptional student that can follow instructions and imitate examples.

Here are two words you should know:

  • Prompt - the input you provide to the model.

  • Completion - the output text the model returns. Depending on your settings, a model can return one or multiple completions.

Experiment with your first use-case

Imagine that you own an online t-shirt store. Your job requires you to come up with appealing titles for your products. By using AI21 Studio language models, you can optimize the process.

1. Tell the model what you want to do

To start, you can simply provide the model a simple instructional prompt. This is what it looks like:

PROMPT Write a product title for a T-shirt to be published on an online retail platform. COMPLETION The coolest T-Shirt on the planet

The suggested title is nice, but it is very generic. Let's add the T-shirt type (sports) to the prompt and see what we get:

PROMPT Write a product title for a sports T-shirt to be published on an online retail platform COMPLETION The Ultimate Sports T-Shirt: Stay cool and dry in style

The title has been refined to reflect the actual product. You can also apply a more realistic scenario: ask the model to incorporate specific keywords in the title.

However, if you care about a specific style you want the model to follow, you should consider adding examples to your prompt.

2. Provide examples to the model

By providing the model with examples, just as a human would, it could produce completions that are more aligned with your intentions. It could also adhere to patterns that are more difficult to explain via instructions. In order to help the model distinguish between each example, we use a stop sequence. There aren't officially defined stop sequences for LLMs, but by convention you can either use ## or newlines to indicate a break between the instruction and the examples, and between individual examples.

PROMPT Write a product title for a T-shirt with a pocket by MSPC to be published on an online retail platform. MSPC Men's Solid Crew Neck Short-Sleeve Pocket T-Shirt ## Write a product title for a graphic T-shirt by PBNJ to be published on an online retail platform. PBNJ Men's Short Sleeve 100% Cotton Nautical Series Graphic Tee ## Write a product title for a sports T-shirt by YSYB to be published on an online retail platform. COMPLETION YSYB Men's Performance Short Sleeve Moisture-Wicking Athletic T-Shirt

📘

Vocabulary builder

Examples that you provide in an LLM prompt are called shots. Therefore the example prompt shown above is called a few-shot prompt because it includes two examples (shots). Other terms include one-shot prompts and zero-shot prompts (no examples, just instructions). Learn more about prompt engineering.

3. Adjust the parameters

Another way to affect the completion is to adjust some of the model parameters. A useful parameter is the temperature. You can increase creativity by tweaking the temperature. With temperature 0, the model will always choose the most probable completion, so the response will always be the same. Increasing the temperature provides more variability each time the model generates a response.

TEMPERATURE 0: Try 1 >>YSYB Men's Performance Short Sleeve Athletic T-Shirt Try 2 >>YSYB Men's Performance Short Sleeve Athletic T-Shirt Try 3 >>YSYB Men's Performance Short Sleeve Athletic T-Shirt ...You get the point...
TEMPERATURE 0.7: Try 1 >>YSYB Men's Dry-Fit Performance Short Sleeve Athletic Sport T-Shirt with Reflective Logo Try 2 >>YSYB Men's Quick-Dry Performance Athletic Short Sleeve T-Shirt Try 3 >>YSYB Men's Athletic Performance Short Sleeve T-Shirt

A task that requires accurate results (such as classification) is best performed with low temperature (perhaps even 0), whereas a task that requires more creativity should be conducted with higher temperature (0.7 is a reasonable starting point).

Try it yourself in the AI21 playground! Try adjusting the parameters such as temperature, and try adjusting the prompt.

4. Code it

Once you have created your prompt, you can easily integrate it into your product using our Python SDK as shown here:

# Using the AI21 Python SDK
import os
from ai21 import AI21Client
from ai21.models.chat import ChatMessage
os.environ["AI21_API_KEY"] = "<YOUR_API_KEY>"

client = AI21Client()

def suggest_product_title():
    response = client.chat.completions.create(
        model="jamba-instruct-preview",  # Latest model
        messages=[ChatMessage(   # Single message with a single prompt
            role="user",
            content="Write a product title for a sports T-shirt to be published on an online retail platform. Include the following keywords: activewear, gym, dryfit."
    )],
        temperature=0.8,
        max_tokens=200 # You can also mention a max length in the prompt "limit responses to twenty words"
    )
    print(response.choices[0].message.content)

### RESPONSE

ActiveDryFit Gym T-Shirt: Ultimate Activewear for Men and Women - Perfect for Workout and Fitness
# Using the AI21 Python SDK
import os
from ai21 import AI21Client
from ai21.models.chat import ChatMessage
os.environ["AI21_API_KEY"] = "<YOUR_API_KEY>"

client = AI21Client()

def suggest_multiple_product_title():
    response = client.chat.completions.create(
        model="jamba-instruct",
        messages=[ChatMessage(
            role="user",
            content="Write a product title for a sports T-shirt to be published on an online retail platform. Include the following keywords: activewear, gym, dryfit."
    )],
        temperature=0.8,
        n=5 # Number of suggestions. Default = 1
    )
    for suggestion in response.choices:
        print(suggestion.message.content)

### RESPONSE

"Premium Activewear Gym Dryfit T-Shirt for Ultimate Performance"
"ActiveGear DryFit Gym Performance T-Shirt for Men and Women"
"Ultra-DryFit Gym Activewear T-Shirt for High-Performance Workouts"
"Activewear Gym Dryfit Performance T-Shirt for Men and Women - Perfect for Workouts and Training"
"ActiveDry: Premium Dryfit Gym T-Shirt for Men - Best Activewear for Workouts"

You can also make direct REST calls without the SDK if you prefer; see the REST API reference for the endpoint called above.

What's next?