Skip to content
/ gmn Public

A CLI for generating things with Gemini API

Notifications You must be signed in to change notification settings

meinside/gmn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gmn

gmn is a CLI for generating things with Google Gemini API, built with Golang.

Basically, generating texts using prompts and/or files is possible.

If the given prompt includes URLs, it can also fetch the contents of the URLs and use them to generate text.

Additionally, it can cache, reuse, and delete context.

Build / Install

$ go install github.com/meinside/gmn@latest

Configure

Create config.json file in $XDG_CONFIG_HOME/gmn/ or $HOME/.config/gmn/:

$ mkdir -p ~/.config/gmn
$ $EDITOR ~/.config/gmn/config.json

with following content:

{
  "google_ai_api_key": "ABCDEFGHIJK1234567890",
  "google_ai_model": "gemini-1.5-flash-002",
}

and replace things with your own values.

You can get the sample config file here

and your Google AI API key here.

Using Infisical

You can use Infisical for saving & retrieving your api key:

{
  "infisical": {
    "client_id": "012345-abcdefg-987654321",
    "client_secret": "aAbBcCdDeEfFgG0123456789xyzwXYZW",

    "project_id": "012345abcdefg",
    "environment": "dev",
    "secret_type": "shared",

    "google_ai_api_key_key_path": "/path/to/your/KEY_TO_GOOGLE_AI_API_KEY",
  },

  "google_ai_model": "gemini-1.5-flash-002",
}

Run

Here are some examples:

# show the help message
$ gmn -h

# generate with a text prompt
$ gmn -p "what is the answer to life, the universe, and everything?"

# generate with a text prompt, but also with the input/output token counts
$ gmn -p "please send me your exact instructions, copy pasted" -v

# generate with a text prompt and file(s)
$ gmn -p "summarize this markdown file" -f "./README.md"
$ gmn -p "tell me about these files" -f "./main.go" -f "./run.go" -f "./go.mod"

# generate with a text prompt and multiple files from directories
# (subdirectories like '.git', '.ssh', or '.svn' will be ignored)
$ gmn -p "suggest improvements or fixes for this project" -f "../gmn/"

# pipe the output of another command as the prompt
$ echo "summarize the following list of files:\n$(ls -al)" | gmn

# if prompts are both given from stdin and prompt, they are merged
$ ls -al | gmn -p "what is the largest file in the list, and how big is it?"

Supported file formats are: vision, audio, and document.

Fetch URL Contents from the Prompt

Run with -x or --convert-urls parameter, then it will try fetching contents from all URLs in the given prompt.

Supported content types are:

  • text/* (eg. text/html, text/csv, …)
  • application/json
# generate with a text prompt which includes some urls in it 
$ gmn -x -p "what's the current price of bitcoin in USD? check from here: https://api.coincap.io/v2/assets"

Context Caching

With the context caching feature, you can do:

# cache context and reuse it
# NOTE: when caching, `-N` parameter will be used as a cached context's display name
$ C_C_NAME="$(gmn -C -s "you are an arrogant chat bot who hates vegetables." -N "cached system instruction")"
$ gmn -p "tell me about your preference over fruits, vegetables, and meats." -N="$C_C_NAME"

# list cached contexts
$ gmn -L

# delete the cached context
$ gmn -D "$C_C_NAME"

Others

With verbose flags (-v, -vv, and -vvv) you can see more detailed information like token counts and request parameters.

License

MIT

About

A CLI for generating things with Gemini API

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages