Comprehensive Guide to AI71's API Hub

Tuesday, July 23, 2024 by adebisi_oluwatomiwa878
Comprehensive Guide to AI71's API Hub

šŸš€ Comprehensive Guide to AI71's API Hub

Welcome, everyone! Whether you're an AI developer, software engineer, or just starting your coding journey, this tutorial is designed to help you navigate AI71's new API Hub. We'll explore how to interact with the powerful Falcon models, customize their settings, and manage your projects efficiently.

Let's dive in and unlock the full potential of the Falcon models together!

šŸŒŸ Introduction to AI71ā€™s API Hub

AI71's API Hub is a powerful platform that provides seamless access to advanced AI models. It simplifies the integration of AI capabilities into your applications, offering a range of models and tools to enhance your projects. With this new API Hub, you can leverage cutting-edge technology to build intelligent applications effortlessly.

šŸ› ļø Features and Functionalities

Home Page Overview

When you first land on the AI71 platform's home page, you'll see three main options to interact with the API:

  1. AI71 Python SDK
  2. OpenAI Python SDK
  3. Curl

Choosing a Model

AI71 offers several powerful models to choose from:

  • Falcon 180B
  • Falcon 11B
  • Falcon 11B VLM

Note: Currently, only tiiuae/falcon-180b-chat, tiiuae/falcon-11b, and tiiuae/falcon-11b-vlm models are operational. The other models will be available soon. In the meantime, you can test tiiuae/falcon-180b-chat, tiiuae/falcon-11b, and tiiuae/falcon-11b-vlm models to get a feel for the platform.

You can select any of these models right from the home page, making it easy to start your AI project with the right tools.

Token Calculator

You'll find a handy token calculator at the right of the home page. Simply input the amount in dollars, and it will automatically calculate the number of tokens you can get. This is a great way to manage your budget and plan your usage.

Each option includes an example to help you get started quickly. You can choose the method that best fits your workflow. Here's a quick look at the home page options:

Welcome to AI71 Platform
Explore the Home Page of AI71 platform

šŸ› ļø Sandbox Page

The sandbox page is where you can interact with all the Falcon models in real-time. Here, you can:

  1. Select a Model: Choose from the available models.
  2. Customize the System Prompt: Tailor the prompt to fit your needs.
  3. Adjust Maximum Output Length: Set the output length between 3 and 2048 tokens, depending on the model.
  4. Tweak the Temperature: Adjust the temperature between 0 and 2 to control the randomness of the output.
  5. Adjust Top P: Control the cumulative probability of token sequences.
  6. Adjust Top K: Limit the next token selection to the top K tokens.
  7. Set Frequency Penalty: Penalize new tokens based on their existing frequency in the text.
  8. Define Stop Sequences: Specify sequences where the output should stop.

Maximum output length will differ based on each model.

AI71 Sandbox
Explore the Sandbox of AI71 platform

This flexibility allows you to experiment and find the best settings for your specific use case.

šŸ“„ Documentation Page

The documentation page provides detailed instructions on how to use the supported models via different methods:

  1. AI71 Python SDK
  2. OpenAI SDK
  3. LangChain SDK
  4. Curl

Each method comes with a brief description and a usage example to help you get started quickly. Other OpenAI-supported SDKs may work if there is an option to change the Base URL and API key.

AI71 Documentation
Explore the Sandbox of AI71 platform

Supported Models

AI71 supports several models, each with its specific use case and API call format:

  • tiiuae/falcon-180B-chat: A 180B parameters causal decoder-only model fine-tuned on Ultrachat, Platypus, and Airoboros datasets.
  • tiiuae/falcon-11b: A 11B parameters causal decoder-only model.
  • tiiuae/falcon-11b-vlm: A 11B parameters visual language model.

For more details, you can refer to the AI71 Documentation.

šŸ¢ Organization Page

The organization page allows you to create and manage your organization. Here, you can:

  • Create an Organization: Set up your organization, invite one or more members.
Organization
Create an Organization
  • Manage API Keys: Create and manage API keys.
API keys
Create API Key
  • Support: Create and manage support tickets.
  • Usage: View the usage of created API keys.

This is perfect for teams collaborating on AI projects, providing a centralized place to manage access and resources.

šŸ’” Use Cases

AI71's API Hub can be applied in various scenarios, such as:

  • Customer Support: Implementing chatbots that can handle customer inquiries and provide support.
  • Content Creation: Generating content for blogs, social media, and marketing campaigns.
  • Data Analysis: Automating the analysis of large datasets to derive insights.
  • Personal Assistants: Developing virtual assistants to help with scheduling, reminders, and information retrieval.

šŸ”§ Implementations

Using the AI71 Python SDK

Here's a quick example of how to use the AI71 Python SDK:

First, install the SDK using pip:

pip install ai71

Then, you can import the library and interact with any of the models in the Python file you wish to use it in:

from ai71 import AI71

AI71_API_KEY = "your AI71 API key"
client = AI71(AI71_API_KEY)

# Simple invocation
print(client.chat.completions.create(
    model="tiiuae/falcon-180B-chat",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is Artificial Intelligence?"},
    ],
))

Note: Replace <your AI71 API key> with your actual API key. You can find or create your API key in Api Keys under the Organization section.

Using Curl

You can also interact with the API using Curl from the terminal:

curl -X POST https://api.ai71.ai/v1/chat/completions -d \
    '{
        "model": "tiiuae/falcon-180B-chat",  
        "messages": [
            {"role":"system", "content":"You are a helpful assistant."}, 
            {"role":"user", "content":"How do I tie a tie?"}
        ]
    }' \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer <your AI71 API key>"

Using Langchain SDK

To interact with the Falcon models using the langchain sdk,

First, install the SDK using pip:

pip install langchain_openai

Then you can import the library and interact with any of the models in the Python file you wish to use it in:

from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage

AI71_BASE_URL = "https://api.ai71.ai/v1/"
AI71_API_KEY = "YOUR_AI71_API_KEY"

chat = ChatOpenAI(
    model="tiiuae/falcon-180B-chat",
    api_key=AI71_API_KEY,
    base_url=AI71_BASE_URL,
    streaming=True,
)

# for single use
base = chat.invoke([
    SystemMessage(content="You are MathTutor, an AI designed to help students with math problems. Provide clear, step-by-step solutions and explanations."),
    HumanMessage(content="Hi tutor, can you help me solve this quadratic equation: x^2 - 5x + 6 = 0?"),
])
print(base.content)


# for streaming in real time
# for chunk in chat.stream("Explain Newtown's Third Law"):
#   print(chunk.content, end="", flush=True)

Using OpenAI SDK

You can also use the OpenAI SDK to interact with the Falcon models.

First, install the SDK using pip:

pip install openai

Then you can import the library and interact with any of the models in the Python file you wish to use it in:

from openai import OpenAI

AI71_BASE_URL = "https://api.ai71.ai/v1/"
AI71_API_KEY = "YOUR_AI71_API_KEY"

client = OpenAI(
    api_key=AI71_API_KEY,
    base_url=AI71_BASE_URL,
)

completion = client.chat.completions.create(
  model="tiiuae/falcon-11b",
  messages=[
    {"role": "system", "content": "You are EduTutor, an AI designed to assist with educational questions. Provide clear and helpful explanations."},
    {"role": "user", "content": "Hi Tutor, explain pythagoras theorem"}
  ]
)

print(completion.choices[0].message)

šŸŒŸ Best Practices

  • Experiment with Settings: Use the sandbox to test different models and settings to find the best fit for your application.
  • Monitor Usage: Utilize the token calculator and usage page to keep track of your consumption and manage costs effectively.
  • Leverage Documentation: Refer to the detailed documentation to understand the capabilities and limitations of each model.

šŸŽ‰ Conclusion

With this guide, you're ready to explore and utilize the AI71 platform to its fullest potential. From selecting and customizing models to managing your organization's resources, AI71 provides a comprehensive suite of tools for your AI projects. Happy coding! šŸŽ‰