Please create your AI21 account
First, we need to prepare our environment. Let's create a directory and virtual environment.
Then, we need to install the SDK for Python.
Last thing, we need to create a file for our Python code.
Let's import the library.
Now we have to define our API key. You can find it in your AI21 account.
To generate text we have to provide some parameters into ai21.Completion.execute function. Here's what it looks like in my case:
Feel free to play with these parameters. You can find more information about them here.
Prompt: "Last day I was in school"
Response: ", and Christopher, my childhood friend and classmate, came in. We started talking, and he told me that he had something to tell me. He said that his class teacher saw us having lunch together in the school canteen."
Prompt: "When I was little my mother told me a tale:"
Response: "'Once upon a time', she said 'there lived a fisherman and his wife. They had one son, who meant well, but who was very clumsy. One day, when the fisherman was away"