Skip to content

jdevoo/gen

Repository files navigation

To use gen, you will need a valid Gemini API key set in the GEMINI_API_KEY environment variable.

Note

If you don't already have one, go to Google AI Studio to create a key.

Single-turn Examples

Plain text generation
$ gen dix noms de fleurs

At the command line, you may have to put the prompt inside double quotes to avoid confusing the shell
$ gen "a scheme function to compute the Levenshtein distance between two strings; only the code"

Pipe content into gen and save its output in a text file
$ cat cmd.go | gen -f - what does this code do? | tee report.txt

Obtain the token count
$ gen -t how many tokens would this prompt consume?

Parameterize prompts
gen -p a=1 -p b=2 "complete this sentence: replace {a} apple with {a} banana and {b} oranges for a good ..."

Set a system instruction from stdin and prompt from argument
echo "you understand english but always reply in french" | gen -s -f - ten names for flowers

Set a system instruction from file option and prompt from argument
gen -f french.sprompt ten names for flowers"

Attach two files to the prompt and return total token count
gen -t -f ../twitter/img/123497680.jpg -f ../twitter/img/123406895.jpg what are the differences between these photos?

Attach several files using glob patterns
gen -f "src/**/*html" -f "src/*html" "this application is written for Polymer 2 and needs to be migrated to Lit"

Generate an architecture decision record using a parameterized template
gen -p role="an experienced MLOps architect" -f prompts/adr.sprompt "an architecture decision record for selecting between option 1 MLFlow and option 2 Weights & Biases for tracking data science experiments. The team includes 5 data scientists and maintains already 50 models in production. The team produces 5 new models per quarter. Models include regression models, classification models, computer vision models as well as time series models."

List known Gemini models by invoking tool
gen -tool list known generative models

Solve problem through Python code execution
gen -code "What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50."

Extract entities from text
w3m -dump https://lite.cnn.com/2024/07/27/asia/us-austin-trilateral-japan-south-korea-intl-hnk/index.html | gen -json -f - extract entities

System instruction and prompts as files from iterative Prisonner's Dilemma paper
gen -json -f pd.sprompt -f pd.prompt

Chain of thought
gen Please answer this question starting in two ways. First start with yes, then start with no and show your work. Afterwards determine which is correct. Is 3307 a prime number?

Generate sequence diagram from code using PlantUML system instruction
gen -f puml.sprompt -f ~/lib/Duke/duke-core/src/main/java/no/priv/garshol/duke/Duke.java sequence diagram of the main_ method in this file

Basic information extraction (Google Gemini cookbook example)
gen -f extract.sprompt -f extract.prompt | gen -f format.sprompt -

Generate an image
gen -img -m gemini-2.0-flash-preview-image-generation An umbrella in the foreground, and a rainy night sky in the background

Multi-turn Examples

Set a system instruction from argument and enter chat
gen -c -s you understand english but always answer in German

Enter chat mode to generate various SQL statements
cat classicmodels.sql | gen -f - -c

Generate a brief using an adapted version of Ali Abassi's prompt
gen -c -f brief.sprompt -f brief.prompt -p role="Sr. Business Analyst" -p department="ACME Technology Solutions" -p task="create a project brief" -p deliverable="project brief"

Tree of thought
gen -c -f tot.sprompt -f tot.prompt

Note

Exit chat mode with two consecutive blank lines. Chat mode saves history in a .gen file in the current directory; remove it to start an empty session.

Retrieval Augmented Generation

Use Gemini embedding models to encode text chunks for retrieval augmented generation. Maximal marginal relevance is used to rank chunks up to a default limit. The text retrieved is prepended to prompts. Altnernatively, use the digest key inside the prompt to position retrieved chunks. Digest files are append-only named 00000000000000000001 and incremented as soon as the limit of 20MB is reached. Persistence logic is adapted from Farhan's aol.

Save text chunk to digest
gen -e -d /tmp "Your Googlecar has a large touchscreen display that provides access to a variety of features, including navigation, entertainment, and climate control. To use the touchscreen display, simply touch the desired icon. For example, you can touch the \"Navigation\" icon to get directions to your destination or touch the \"Music\" icon to play your favorite songs."

Query from digest
gen -d /tmp How do I play music in the Google car?

Add document to digest
pdftotext Attali.pdf - | awk 'BEGIN{RS='\f'} {cmd="gen -V -e -f - -d digest"; print | cmd; close(cmd)}'

Query digest and read out loud using TTS system
echo you understand french but always reply in english | gen -s -f - -d digest liste les 30 principales propositions de Jacques Attali | ../Downloads/piper/piper --model ../Downloads/voices/en_US-hfc_female-medium.onnx --output-raw | aplay -r 22050 -f S16_LE -t raw -

Whiteboard Mode

Experimental mode that runs separate copies of gen per system prompt provided. Each gen instance collaborates through a whiteboard based on Amanda, a shared tuple space that supports a basic set of operations inspired by David Gelernter's Linda.

A storyteller and an editor collaborate to generate a story using word count tool to stop at a given count of words
gen -w -f prompts/storyteller.sprompt -f prompts/editor.sprompt -f prompts/tool.sprompt -f prompts/sentinel.sprompt The year is 1788. France is in turmoil.

Usage

Usage: gen [options] <prompt>

Command-line interface to Google Gemini large language models
  Requires a valid GOOGLE_API_KEY environment variable set.
  Also supports VertexAI with valid GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION.
  Content is generated by a prompt and optional system instructions.
  Use - to assign stdin as prompt argument or as attached file.

Tools:
  * CountWords
  * ListAWSServices
  * ListKnownGeminiModels

Parameters:

  -V    output model details, system instructions and chat history
  -c    enter chat mode after content generation (incompatible with -img, -code or -g)
  -code
        allow code execution (incompatible with -g, -img or -tool)
  -d value
        path to a digest folder
  -e    write embeddings to digest (default model "text-embedding-004")
  -f value
        file, directory or quoted matching pattern of files to attach
  -g    Google search (incompatible with -code, -img and -tool)
  -h    show this help message and exit
  -img
        generate a jpeg image (use -m with a supported model)
  -json
        response in JavaScript Object Notation (incompatible with -img and -tool)
  -k int
        maximum number of entries from digest to retrieve (default 3)
  -l float
        trade off accuracy for diversity when querying digests [0.0,1.0] (default 0.5)
  -m string
        embedding or generative model name (default "gemini-2.0-flash")
  -o    only store metadata with embeddings and ignore the content
  -p value
        prompt parameter value in format key=val
  -s    treat argument as system instruction
  -t    output total number of tokens
  -temp float
        changes sampling during response generation [0.0,2.0] (default 1)
  -tool
        invoke one of the tools (incompatible with -g, -img or -code)
  -top_p float
        changes how the model selects tokens for generation [0.0,1.0] (default 0.95)
  -unsafe
        force generation when gen aborts with FinishReasonSafety
  -v    show version and exit
  -w    enter whiteboard mode for content generation (experimental)

License

This project is licensed under the MIT License.

About

Simple command-line interface to Google Gemini large language models.

Resources

License

Stars

Watchers

Forks

Packages

No packages published