AI21 API Starter Sample for Gen AI Beginners

If you frequently use AI assistants and are amazed by the near-magical abilities of LLMs, you can take it a step further by exploring how to use them programmatically.

Here's a beginner-friendly sample in Python that utilizes the AI21 API to generate responses from its Jamba Instruct model. AI21 Labs offers a Free Trial with $10 credits for 3 months. No credit card is needed.

You don’t even need a local development setup to get started. You can use Google Colaboratory (Colab), a hosted Jupyter Notebook service that requires no setup and offers free access to computing resources, including GPUs and TPUs.

At a high level, we'll follow the below steps -

  1. Install AI21 Python SDK
  2. Obtain your API key by logging in and visiting this link
  3. Initialize the AI21 client using your API key
  4. Send your query to the AI21 Jamba Instruct model
  5. Print the generated response

To install the ai21 package to work with AI21 Studio models, use pip to install the ai21 library - !pip install ai21

Copy the following Python code and make sure to replace the API key -

To improve the code further, you can add error handling to manage potential issues especially when setting the API key and making the API call.

Comments

Popular posts from this blog

"Data Prep & Exploratory Data Analysis" course by Maven Analytics

Maven Crash Course - Learn Power Query, Power Pivot & DAX in 15 Minutes

This Week I Learned - Week #45 2024