Gemini

Intro

Use with

from pyalm import Gemini
llm = Gemini(project="YOUR_PROJECT")

Documentation

class pyalm.models.gemini.Gemini(model_path_or_name='gemini-pro', project=None, verbose=0, location='europe-west3', **kwargs)

PyALM implementation for Gemini. Requires the Vertex AI SDK to be installed.

build_prompt(preserve_flow=False)

Build prompt in format native to library

Parameters:

preserve_flow – Block suffix for purely text based models

Returns:

prompt obj

create_native_completion(text, max_tokens=256, stop=None, keep_dict=False, token_prob_delta=None, token_prob_abs=None, log_probs=None, **kwargs)

Library native completion retriever. Different for each library. No processing of output is done

Parameters:
  • text – Prompt or prompt obj

  • max_tokens – maximum tokens generated in completion

  • stop – Additional stop sequences

  • keep_dict – If library or API returns something else than raw tokens, whether to return native format

  • token_prob_delta – dict, relative added number for token logits

  • token_prob_abs – dict, Absolute logits for tokens

  • log_probs – int, when not None return the top X log probs and their tokens

  • kwargs – kwargs

Returns:

completion

create_native_generator(text, keep_dict=False, token_prob_delta=None, token_prob_abs=None, **kwargs)

Library native generator for tokens. Different for each library. No processing of output is done

Parameters:
  • text – Prompt or prompt obj

  • keep_dict – If library or API returns something else than raw tokens, whether to return native format

  • token_prob_delta – dict, Absolute logits for tokens

  • token_prob_abs – dict, relative added number for token logits

  • kwargs – kwargs

Returns:

generator

get_n_tokens(text)

How many tokens are in a string

Parameters:

text – tokenizable text

Returns:

amount

tokenize(text)

Text to token as vector representation

Parameters:

text

Returns:

List of tokens as ints

tokenize_as_str(text)

Text to token as vector representation but each token is converted to string

Parameters:

text

Returns:

List of tokens as strings