adhishtanaka/gemilib

0.1.3
adhishtanaka / gemilib

Unofficial Gemini API Client for Ballerina Package: adhishtanaka/gemilib Version: 0.1.3

Overview

The GemiLib module provides APIs for interacting with AI models, performing intelligent search queries, and analyzing or summarizing web content. This is an unofficial Gemini API client for Ballerina, built to simplify integration with Google's Gemini models and the Jina Reader API.

The library introduces three main capabilities

  • AI Chat,
  • Keyword Extraction,
  • Web Scraping

built upon modern HTTP-based integrations.

Constructor

The library is initialized with API credentials and optional parameters for model configuration.

Copy
gemilib:GemiLib gemi = check new (
    apiKey = "YOUR_API_KEY",
    modelName = "gemini-2.5-flash",
    baseUrl = "https://generativelanguage.googleapis.com",
    temperature = 0.7,
    maxOutputTokens = 2048
);

Usage

Simple Chat

For lightweight interactions, the simpleChat() method enables basic AI exchanges without classification or search integration.

Copy
import ballerina/io;
import adhishtanaka/gemilib;

 gemilib:GemiLib gemi = check new (
    apiKey = "YOUR_API_KEY",
    modelName = "gemini-2.5-flash",
    baseUrl = "https://generativelanguage.googleapis.com",
    temperature = 0.7,
    maxOutputTokens = 2048
);
string reply = check gemi.simpleChat("Tell me a joke", "You are a witty assistant.");

Ask

The ask() function provides direct access to the AI model for one-off prompt execution.

Copy
import ballerina/io;
import adhishtanaka/gemilib;

 gemilib:GemiLib gemi = check new (
    apiKey = "YOUR_API_KEY",
    modelName = "gemini-2.5-flash",
    baseUrl = "https://generativelanguage.googleapis.com",
    temperature = 0.7,
    maxOutputTokens = 2048
);

string output = check gemi.ask("Summarize the concept of reinforcement learning.");
io:println(output);

Keyword Extraction

The extractKeywords() method isolates the most relevant search terms from natural language input using the AI model.

Copy
import ballerina/io;
import adhishtanaka/gemilib;

 gemilib:GemiLib gemi = check new (
    apiKey = "YOUR_API_KEY",
    modelName = "gemini-2.5-flash",
    baseUrl = "https://generativelanguage.googleapis.com",
    temperature = 0.7,
    maxOutputTokens = 2048
);
string[] terms = check gemi.extractKeywords("best tea farms near Kandy");
io:println(terms);

Web Scraping

Summary Scrape

The scrape() function retrieves and analyzes the contents of any web page using the Jina Reader API. It can summarize the HTML or process it based on a specific instruction.

Copy
import ballerina/io;
import adhishtanaka/gemilib;

 gemilib:GemiLib gemi = check new (
    apiKey = "YOUR_API_KEY",
    modelName = "gemini-2.5-flash",
    baseUrl = "https://generativelanguage.googleapis.com",
    temperature = 0.7,
    maxOutputTokens = 2048
);

string summary = check gemi.scrape("https://example.com");

io:println(summary);

Specific Details Scrape

Copy
import ballerina/io;
import adhishtanaka/gemilib;

 gemilib:GemiLib gemi = check new (
    apiKey = "YOUR_API_KEY",
    modelName = "gemini-2.5-flash",
    baseUrl = "https://generativelanguage.googleapis.com",
    temperature = 0.7,
    maxOutputTokens = 2048
);

    string output = check gemi.scrape("https://en.wikipedia.org/wiki/National_School_of_Business_Management","in what year NSBM university founded");
    io:println(output);

This method fetches the HTML, sanitizes it, and generates an AI summary or custom analytical response.


Import

import adhishtanaka/gemilib;Copy

Other versions

Metadata

Released date: 5 months ago

Version: 0.1.3


Compatibility

Platform: any

Ballerina version: 2201.12.9

GraalVM compatible: Yes


Pull count

Total: 2

Current verison: 0


Weekly downloads