🤖 Generate text using Complete API
To install the SDK, run the following command:
$ pip install -U ai21
You can find your API key here.
API keys can be set globally using ai21.api_key, like so:
import ai21 ai21.api_key = <YOUR_API_KEY>
Build a prompt
We recommend following our Prompt Engineering best practices for optimal results.
You can try "Zero Shot" prompt:
prompt = "These are a few of my favorite"
Or, "Few Shot" prompt:
prompt = """ Complete the following sentence. Sentence: These are a few of my favorite Completion: things. Cream-colored ponies and crisp apple strudels. ## Complete the following sentence. Sentence: These are a few of my favorite Completion: rock bands: The Beatles, The Doors, Fleetwood Mac. ## Complete the following sentence. Sentence: These are a few of my favorite Completion: """
Test this API
You can generate a text completion for a given text prompt by posting an HTTP request to the complete endpoint corresponding to the desired language model to use. The request contains the input text, called a prompt and various parameters controlling the generation. For authentication, you must include your API key in the request headers. A complete response contains the tokenized prompt, the generated text(s), called completion(s), and various metadata. The request and response specifications are documented in full here.