Package 'gemini.R'

Title: Interface for 'Google Gemini' API
Description: Provides a comprehensive interface for Google Gemini API, enabling users to access and utilize Gemini Large Language Model (LLM) functionalities directly from R. This package facilitates seamless integration with Google Gemini, allowing for advanced language processing, text generation, and other AI-driven capabilities within the R environment. For more information, please visit <https://ai.google.dev/docs/gemini_api_overview>.
Authors: Jinhwan Kim [aut, cre, cph] , Maciej Nasinski [ctb]
Maintainer: Jinhwan Kim <[email protected]>
License: MIT + file LICENSE
Version: 0.5.2.9000
Built: 2024-12-02 05:13:19 UTC
Source: https://github.com/jhk0530/gemini.R

Help Index


Add history for chating context

Description

Add history for chating context

Usage

addHistory(history, role = NULL, item = NULL)

Arguments

history

The history of chat

role

The role of chat: "user" or "model"

item

The item of chat: "prompt" or "output"

Value

The history of chat


Generate text from text with Gemini

Description

Generate text from text with Gemini

Usage

gemini(prompt, model = "1.5-flash", temperature = 0.5, maxOutputTokens = 1024)

Arguments

prompt

The prompt to generate text from

model

The model to use. Options are '1.5-flash', '1.5-pro', '1.0-pro'. Default is '1.5-flash' see https://ai.google.dev/gemini-api/docs/models/gemini

temperature

The temperature to use. Default is 0.5 value should be between 0 and 2 see https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters

maxOutputTokens

The maximum number of tokens to generate. Default is 1024 and 100 tokens correspond to roughly 60-80 words.

Value

Generated text

See Also

https://ai.google.dev/docs/gemini_api_overview#text_input

Examples

## Not run: 
library(gemini.R)
setAPI("YOUR_API_KEY")
gemini("Explain dplyr's mutate function")

## End(Not run)

Multi-turn conversations (chat)

Description

Generate text from text with Gemini

Usage

gemini_chat(
  prompt,
  history = list(),
  model = "1.5-flash",
  temperature = 0.5,
  maxOutputTokens = 1024
)

Arguments

prompt

The prompt to generate text from

history

history object to keep track of the conversation

model

The model to use. Options are '1.5-flash', '1.5-pro', '1.0-pro'. Default is '1.5-flash' see https://ai.google.dev/gemini-api/docs/models/gemini

temperature

The temperature to use. Default is 0.5 value should be between 0 and 2 see https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters

maxOutputTokens

The maximum number of tokens to generate. Default is 1024 and 100 tokens correspond to roughly 60-80 words.

Value

Generated text

See Also

https://ai.google.dev/docs/gemini_api_overview#chat

Examples

## Not run: 
library(gemini.R)
setAPI("YOUR_API_KEY")

chats <- gemini_chat("Pretend you're a snowman and stay in character for each")
print(chats$outputs)

chats <- gemini_chat("What's your favorite season of the year?", chats$history)
print(chats$outputs)

chats <- gemini_chat("How do you think about summer?", chats$history)
print(chats$outputs)

## End(Not run)

Generate text from text and image with Gemini

Description

Generate text from text and image with Gemini

Usage

gemini_image(
  image = NULL,
  prompt = "Explain this image",
  model = "1.5-flash",
  temperature = 0.5,
  maxOutputTokens = 1024,
  type = "png"
)

Arguments

image

The image to generate text

prompt

The prompt to generate text, Default is "Explain this image"

model

The model to use. Options are '1.5-flash', '1.5-pro'. Default is '1.5-flash' see https://ai.google.dev/gemini-api/docs/models/gemini

temperature

The temperature to use. Default is 0.5 value should be between 0 and 2 see https://ai.google.dev/gemini-api/docs/models/generative-models#model-parameters

maxOutputTokens

The maximum number of tokens to generate. Default is 1024 and 100 tokens correspond to roughly 60-80 words.

type

The type of image. Options are 'png', 'jpeg', 'webp', 'heic', 'heif'. Default is 'png'

Value

Generated text

See Also

https://ai.google.dev/docs/gemini_api_overview#text_image_input

Examples

## Not run: 
library(gemini.R)
setAPI("YOUR_API_KEY")
gemini_image(image = system.file("docs/reference/figures/image.png", package = "gemini.R"))

## End(Not run)