AI-Powered Flutter App with MakerSuite and PaLM API

post-thumb



The application

 

Screenshot 2 Screenshot 2 Screenshot 2
Screenshot 3 Screenshot 3 Screenshot 3

 

Introduction

Imagine a moment in the world of technology and generative AI where inspiration meets innovation. I was invited to join the MakerSuite & PaLM API Sprint — an initiative that delved into Google’s PaLM API and the capabilities of MakerSuite.

The Sprint wasn’t just an opportunity; it was my chance to explore, create, and collaborate. The question that sparked it all was simple: “How could I use PaLM API and MakerSuite to craft something truly remarkable?” The answer unexpectedly came from something as familiar as my morning cup of coffee, and that’s how the “Aroma Journey” app was conceived.

  • The Concept: Aroma Journey is more than just an app; it’s a digital adventure into the world of coffee. It’s a testament to the power of generative AI, offering an immersive experience that weaves together stories, learning, and enjoyment. Yet, at its core, Aroma Journey pays homage to coffee — an endeavor to make the rich world of coffee accessible to everyone, from experts to novices.

  • The Motivation: The MakerSuite & PaLM API Sprint provided me with the tools, and my motivation was crystal clear. It was an opportunity to collaborate with Googlers and fellow GDEs, utilizing large language models and generative AI. For me, it was about creating something meaningful, driven by a passion for tech and a love for coffee.

  • The Goals: As I embarked on this journey, my primary objective was to dive deep into the inner workings of PaLM API and MakerSuite. It was a voyage of learning, a chance to grasp the capabilities of these tools and how they could be applied in practical scenarios. The mission wasn’t just about building an app; it was also about demystifying the power of generative AI for others.

In this article, I’ll guide you through the creation of the Aroma Journey app—a project that sprouted from the MakerSuite & PaLM API Sprint. It’s a retrospective, a delivery of the application, and an opportunity for you to explore the app’s source code on GitHub. Join me as I share my process of crafting an AI-powered Flutter app that celebrates coffee, technology, and the boundless potential when they converge.

 

Prerequisites for this sprint

Before embarking on the MakerSuite & PaLM API Sprint adventure, there were several prerequisites I had to ensure were in place:

1. Flutter Development Environment

To build the Aroma Journey app, I needed to have Flutter up and running. This included setting up emulators for testing and development. My primary development targets were Android and Chrome, ensuring a smooth development lifecycle.

2. VPN Access

Living in Canada posed a unique challenge as MakerSuite was not yet available in my region. To overcome this geographical restriction, I utilized a VPN (Virtual Private Network) to gain access to the MakerSuite platform. This was essential for my generative AI experiments.

With these prerequisites met, I was ready to dive into the world of generative AI and embark on the MakerSuite & PaLM API Sprint.

 

MakerSuite: Streamlining Generative AI Workflows

At the beginning of my generative AI journey is MakerSuite, a platform I used to simplify and enhance my development workflow. MakerSuite offers a range of tools and features tailored to work seamlessly with Google’s PaLM API. Let’s walk through how MakerSuite facilitated the creation of my Aroma Journey app.

Step 1: Welcome to MakerSuite

MakerSuite is a versatile platform that streamlines generative AI workflows. It offers a wide array of tools and features to help me harness the power of large language models effectively.

 

Step 2: Creating Libraries in MakerSuite

In MakerSuite, I created three essential libraries to support my project:

  1. AJ: Brewing-Taste-Health: This library focuses on content generation for my application, providing rich information about coffee.

  2. AJ: Quiz Coffee: Here, I generated quiz questions related to coffee, enhancing user engagement.

  3. AJ: Brewing Inventions: This library sparks creativity by generating imaginative coffee varieties.

 

Step 3: Prompt Validation with MakerSuite

For each library, MakerSuite simplifies the prompt validation process. Let’s take the example of generating quiz questions for my Aroma Journey app.

 

Step 4: Configuring with Pre-Defined Settings

MakerSuite offers pre-configured settings that align perfectly with best practices for generating text. These settings, including temperature, candidate count, and more, ensure efficient and safe interactions with the PaLM API.

 

Step 5: Obtaining Your API Key

To interact with the PaLM API, I needed to obtain my API key. The MakerSuite dashboard provides a convenient way to manage your API key.

With MakerSuite by my side, my generative AI journey becomes more accessible, and efficient.

 

 

The Role of PaLM API in Aroma Journey

At the heart of Aroma Journey’s generative AI capabilities lies PaLM API. This powerful API serves as the creative engine behind the scenes, breathing life into our coffee-themed narratives, generating insightful content, and crafting challenging quiz questions.

Creating a PaLMUtil Class

To harness the potential of PaLM API in my Flutter application, I created a PaLMUtil class. To simplify the process, I relied on the Flutter package google_generative_language_api. This package acted as a quick wrapper, enabling me to make REST calls to the PaLM API effortlessly.

class PaLMUtil {
  
  /// Generates text from a prompt using the PaLM 2.0 model.
  static Future<String> generateTextFormPaLM({
    required String exampleInput1,
    required String exampleOutput1,
    required String exampleInput2,
    required String exampleOutput2,
    required String exampleInput3,
    required String exampleOutput3,
    required String input,
  }) async {
    /// DO NOT PUBLICLY SHARE YOUR API KEY.
    // Load the API key from the local .env file.
    String apiKey = dotenv.env['PALM_API_KEY']!;

    // PaLM 2.0 model name
    String textModel = 'models/text-bison-001';

    // Construct the prompt string with input examples
    String promptString = '''input: $exampleInput1
    output: $exampleOutput1
    
    input: $exampleInput2
    output: $exampleOutput2
    
    input: $exampleInput3
    output: $exampleOutput3
    
    input: $input
    output:''';

    // Configure the text generation request
    GenerateTextRequest textRequest = GenerateTextRequest(
        prompt: TextPrompt(text: promptString),
        temperature: 0.7, // Control the randomness of text generation
        candidateCount: 1, // Number of generated text candidates
        topK: 40, // Consider the top K probable tokens
        topP: 0.95, // Nucleus sampling parameter
        maxOutputTokens: 1024, // Maximum number of output tokens
        stopSequences: [], // Sequences at which to stop generation
        safetySettings: const [
          // Define safety settings to filter out harmful content
          SafetySetting(
              category: HarmCategory.derogatory,
              threshold: HarmBlockThreshold.lowAndAbove),
          SafetySetting(
              category: HarmCategory.toxicity,
              threshold: HarmBlockThreshold.lowAndAbove),
          SafetySetting(
              category: HarmCategory.violence,
              threshold: HarmBlockThreshold.mediumAndAbove),
          SafetySetting(
              category: HarmCategory.sexual,
              threshold: HarmBlockThreshold.mediumAndAbove),
          SafetySetting(
              category: HarmCategory.medical,
              threshold: HarmBlockThreshold.mediumAndAbove),
          SafetySetting(
              category: HarmCategory.dangerous,
              threshold: HarmBlockThreshold.mediumAndAbove),
        ]);

    // Call the PaLM API to generate text
    final GeneratedText response = await GenerativeLanguageAPI.generateText(
      modelName: textModel,
      request: textRequest,
      apiKey: apiKey,
    );

    // Extract and return the generated text
    if (response.candidates.isNotEmpty) {
      TextCompletion candidate = response.candidates.first;
      return candidate.output;
    }
    
    return '';
  }
}

Leveraging Predefined Settings

One of the remarkable aspects of MakerSuite is its provision of predefined settings for interacting with the PaLM API. These settings align perfectly with best practices for generating text, including parameters such as temperature, candidate count, token selection, safety settings, and more. By adopting these settings, I ensured that my interactions with the PaLM API were not only efficient but also aligned with industry standards.

        prompt: TextPrompt(text: promptString),
        temperature: 0.7, // Control the randomness of text generation
        candidateCount: 1, // Number of generated text candidates
        topK: 40, // Consider the top K probable tokens
        topP: 0.95, // Nucleus sampling parameter
        maxOutputTokens: 1024, // Maximum number of output tokens
        stopSequences: [], // Sequences at which to stop generation
        safetySettings: const [
          // Define safety settings to filter out harmful content
          SafetySetting(
              category: HarmCategory.derogatory,
              threshold: HarmBlockThreshold.lowAndAbove),
          SafetySetting(
              category: HarmCategory.toxicity,
              threshold: HarmBlockThreshold.lowAndAbove),
          SafetySetting(
              category: HarmCategory.violence,
              threshold: HarmBlockThreshold.mediumAndAbove),
          SafetySetting(
              category: HarmCategory.sexual,
              threshold: HarmBlockThreshold.mediumAndAbove),
          SafetySetting(
              category: HarmCategory.medical,
              threshold: HarmBlockThreshold.mediumAndAbove),
          SafetySetting(
              category: HarmCategory.dangerous,
              threshold: HarmBlockThreshold.mediumAndAbove),
        ]);

Generating Quiz Questions

For Aroma Journey’s interactive quizzes, I implemented a dedicated service – the QuizService. Here’s a simplified example of how I used the PaLM API to generate quiz questions:

class QuizService {

  ...

  Future<String> _generativeAIQuizzCoffeJourney(String coffee) async =>
      PaLMUtil.generateTextFormPaLM(
        exampleInput1: exampleInput1,
        exampleOutput1: exampleOutput1,
        exampleInput2: exampleInput2,
        exampleOutput2: exampleOutput2,
        exampleInput3: exampleInput3,
        exampleOutput3: exampleOutput3,
        input:
            "Could you generate a true or false question about $coffee for me? Please include the answer at the end within curly braces {}.",
      );

...
}

 

Implementing User-Friendly Features

As a solo developer, crafting a user-friendly and engaging experience in my application was a top priority. Leveraging the power of Flutter, I set out to create features that would immerse users in the world of coffee and generative AI.

Coffee Categories Exploration

One of the key features of my application is the ability for users to dive into various coffee categories, such as Espresso, Cold Brew, and Cappuccino. Each category offers a curated collection of unique coffee varieties.

AI-Powered Insights

With the help of generative AI powered by the PaLM API, I was able to provide users with insightful content related to each coffee variety. From brewing tips to flavor profiles and health considerations, these AI-generated insights added an educational dimension to the app. Flutter’s flexibility allowed me to seamlessly integrate these insights into the user interface.

Interactive Quizzes

Learning can be fun, and I wanted to make sure that my users had an engaging way to test their coffee knowledge. That’s where interactive quizzes came into play. What makes these quizzes truly unique is that the questions are generated entirely by AI. Users can challenge themselves with questions about coffee history, preparation techniques, and flavor identification, all crafted by the power of generative AI.

These quizzes not only entertain users but also educate them about the world of coffee, showcasing the capabilities of AI in a fun and interactive manner. Flutter’s widgets and UI components made implementing these quizzes a breeze, ensuring a seamless and enjoyable user experience.

 

Feedbacks

Building the Aroma Journey app using MakerSuite and PaLM API has been an exciting and educational journey. As the sole developer behind this project, I’ve had the opportunity to explore the power of generative AI and create an engaging application that celebrates the world of coffee.

Key Takeaways:

  • Simplified Development with MakerSuite
  • Libraries for Testing and Creativity
  • Prompt Validation with Ease
  • Pre-Configured Settings for Efficiency

Code source :

 

Further Reading