npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ai-function-helper-claude

v0.0.6

Published

A NodeJS utility to simplify interaction with Claude 3.

Downloads

3

Readme

ai-function-helper-gemini

Introduction

ai-function-helper-gemini is a NodeJS package for creating custom AI functions using Google's Vertex AI with the Gemini model. It simplifies interactions with AI models for a wide range of applications.

Installation

Install the package via npm:

npm install ai-function-helper-gemini

Usage

Examples are provided to demonstrate the package's functionality in diverse scenarios. Below are the available options for configuring the AI function.

Options

When configuring the AI function created by ai-function-helper-gemini, the following options can be specified:

  • functionName (string): The name given to the AI function. It's used for identification and logging purposes.

    • Default: "" (Empty string)
  • args (object): Arguments to be passed into the AI function. These are typically the parameters required by your specific AI task.

    • Default: {} (Empty object)
  • model (string): The name of the AI model to use. This determines the underlying model powering your AI function.

    • Default: "gemini-pro-vision"
  • description (string): A descriptive text explaining the purpose and behavior of the AI function. This helps guide the AI model in generating appropriate responses.

    • Default: "" (Empty string)
  • showDebug (boolean): A flag to enable debug information. When set to true, additional debug information will be printed to the console.

    • Default: false
  • debugLevel (number): Specifies the amount of debug information to display. Higher values provide more detailed debug outputs.

    • Default: 0 (Basic information)
  • funcReturn (Zod schema): A Zod schema that defines the expected return structure of the AI function's output. This is used for output validation and ensuring consistency.

    • Default: null
  • blockHijack (boolean): When set to true, the function will reject any attempts to alter its intended behavior or hijack its process.

    • Default: false
  • promptVars (object): A set of variables used to dynamically replace placeholders in the function's description.

    • Default: {} (Empty object)
  • imagePrompt (string | array): Image data (either in base64 encoding or a URL) to be included as part of the AI function's input.

    • Default: null
  • current_date_time (string): The current date and time, used as part of the function's context or for time-based operations.

    • Default: new Date().toISOString()
  • minifyJSON (boolean): Determines whether the JSON output should be minified. Minified JSON is more compact but less readable.

    • Default: false
  • strictReturn (boolean): When true, the function will strictly validate the returned data against the funcReturn Zod schema, ensuring the output precisely matches the expected format.

    • Default: false

Examples

Example 1: Generating Quiz Questions

const { z } = require('zod');
const { createAiFunctionInstance } = require('ai-function-helper-gemini');

const aiFunction = createAiFunctionInstance('your-project-id', 'us-central1');

const options = {
    functionName: 'generateQuiz',
    args: { topic: 'science', difficulty: 'easy', numQuestions: 5 },
    description: 'Generate a quiz on a specified topic and difficulty.',
    funcReturn: z.object({
        questions: z.array(z.object({
            question: z.string(),
            answers: z.array(z.string()),
            correctAnswer: z.string()
        }))
    }),
    showDebug: true
};

aiFunction(options).then(result => console.log(result));

Expected Output:

{
    "questions": [
        {
            "question": "What is the chemical symbol for water?",
            "answers": ["H2O", "CO2", "O2", "H2"],
            "correctAnswer": "H2O"
        },
        // More questions...
    ]
}

Example 2: Text Summarization

const { z } = require('zod');
const { createAiFunctionInstance } = require('ai-function-helper-gemini');

const aiFunction = createAiFunctionInstance('your-project-id', 'us-central1');

const options = {
    functionName: 'summarizeText',
    args: { text: 'Long text to summarize...' },
    description: 'Summarize the provided text into a concise paragraph.',
    funcReturn: z.object({
        summary: z.string()
    })
};

aiFunction(options).then(result => console.log(result.summary));

Expected Output:

{
    "summary": "This is a summarized version of the provided long text..."
}

Example 3: Image Description

const { z } = require('zod');
const { createAiFunctionInstance } = require('ai-function-helper-gemini');

const aiFunction = createAiFunctionInstance('your-project-id', 'us-central1');

const options = {
    functionName: 'describeImage',
    args: {},
    imagePrompt: 'image-data-base64-or-url',
    description: 'Generate a description for the provided image.',
    funcReturn: z.object({
        description: z.string()
    }),
    showDebug: false
};

aiFunction(options).then(result => console.log(result.description));

Expected Output:

{
    "description": "A scenic view of mountains under a clear blue sky."
}

funcReturn Explanation

The funcReturn option in the aiFunction specifies the expected return format of the AI function. It is validated against a Zod schema, ensuring that the returned data conforms to the defined structure.

funcReturn Explanation

The funcReturn option in the aiFunction is used to specify the expected return format of the AI function. It is validated against a Zod schema, ensuring that the returned data conforms to the defined structure.

Understanding funcReturn

  • funcReturn is defined using Zod, a TypeScript-first schema declaration and validation library.
  • It helps in structuring the expected output of the AI function.

Examples

  1. Quiz Question Format

    funcReturn: z.object({
        questions: z.array(z.object({
            question: z.string(),
            answers: z.array(z.string()),
            correctAnswer: z.string()
        }))
    })

    This schema expects an object with a questions array, where each question is an object with question, answers, and correctAnswer fields.

  2. Summarized Text Format

    funcReturn: z.object({
        summary: z.string()
    })

    Expects an object with a single field summary containing a string.

  3. Image Description Format

    funcReturn: z.object({
        description: z.string()
    })

    Expects an object with a description field as a string.

Contributing

We welcome contributions. Please fork the repository, make your changes, and submit a pull request.