2 minutes to read - Mar 30, 2023

AI21 Labs tutorial: how to use AI21 Labs API?

VISIT
AI21 Labs tutorial: how to use AI21 Labs API?
AI21 Labs is an artificial intelligence research lab that focuses on natural language understanding. Their goal is to revolutionize the way we write and read. It’s an amazing generative AI text-to-text technology, which can improve the work of your app. Company’s motto is really to the point: 'They say two heads are better than one. We say two heads - one human and one intelligent machine - are the best.'
Table of Contents
1Code!
2Let's test it out!

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.

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.

Let's test it out!

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"

Article source
loading...