Skip to main content

A library for 'gemini' models without unnecessary dependencies.

Project description

castor-pollux

Castor-Pollux (the twin sons of Zeus, routinely called 'gemini') is a pure REST API library for interacting with Google Generative AI API.

Without (!!!):

  • any whiff of 'Vertex' or GCP;
  • any signs of 'Pydantic' or unnecessary (and mostly useless) typing;
  • any other dependencies of other google packages trashed into the dumpster google-genai package.

Installation:

  pip install castor-pollux

Then:

  # Python
  import castor_pollux.rest as cp

A text continuation request:

import castor_pollux.rest as cp
from yaml import safe_load as yl
from yaml import safe_dump as yd
from yaml import YAMLError as ERR

kwargs = """  # this is a string in YAML format
  model:        gemini-2.5-pro-exp-03-25    # thingking model
  # system_instruction: ''                  # will prevail if put here
  mime_type:    text/plain                  #
  modalities:
    - TEXT                                  # text for text
  max_tokens:   10000
  n:            2                           # 1 is not mandatory
  stop_sequences:
    - STOP
    - "\nTitle"
  temperature:  0.5                         # 0 to 1.0
  top_k:        10                          # number of tokens to consider.
  top_p:        0.5                         # 0 to 1.0
  thinking:     24576                       # max thinking tokens budget; 
                                            # 0 to prevent 'thinking'
"""

instruction = 'You are Joseph Jacobs, you retell folk tales.'

text_to_continue = 'Once upon a time, when pigs drank wine '

machine_responses = cp.continuation(
    text=text_to_continue,
    instruction=instruction,
    **yl(kwargs)
)

file_name = 'yaml_test.yaml'
with open(file_name, "w") as stream:
    try:
        yd(machine_responses, stream)
    except ERR as exc:
        print(exc)
# texts = yd(machine_responses)
with open(file_name, 'r') as stream:
    try:
        texts = yl(stream)
    except ERR as exc:
        print(exc)

A multi-turn conversation continuation request:

import castor_pollux.rest as cp
from yaml import safe_load as yl
from yaml import safe_dump as yd
from yaml import YAMLError as ERR

kwargs = """  # this is a string in YAML format
  model:        gemini-2.5-pro-exp-03-25    # thingking model
  # system_instruction: ''                  # will prevail if put here
  mime_type:    text/plain                  #
  modalities:
    - TEXT                                  # text for text
  max_tokens:   10000
  n:            1                           # 1 is not mandatory
  stop_sequences:
    - STOP
    - "\nTitle"
  temperature:  0.5                         # 0 to 1.0
  top_k:        10                          # number of tokens to consider.
  top_p:        0.5                         # 0 to 1.0
  thinking:     24576                       # max thinking tokens budget; 
                                            # 0 to prevent 'thinking'
"""

previous_turns = """
  - role: user
    parts:
      - text: Can we change human nature?
    
  - role: model
    parts:
      - text: Of course, nothing can be simpler. You just re-educate them.
"""

human_response_to_the_previous_turn = 'That is not true. Think again.'

instruction = 'I am an expert in critical thinking. I analyse.'

machine_responses = cp.continuation(
    text=human_response_to_the_previous_turn,
    contents=yl(previous_turns),
    instruction=instruction,
    **yl(kwargs)
)

file_name = 'machine_texts.yaml'
with open(file_name, "w") as stream:
    try:
        yd(machine_responses, stream)
    except ERR as exc:
        print(exc)
# texts = yd(machine_responses)
with open(file_name, 'r') as stream:
    try:
        texts = yl(stream)
    except ERR as exc:
        print(exc)

Recorder, logs and records and multi-turn conversations

castor-pollux can work with grammateus recorder if you pass an initialized instance of it in your calls.

from yaml import safe_load as yl
from grammateus import Grammateus
from castor_pollux import rest as cp

location = '/home/<user>/Documents/Fairytales/one/'
recorder = Grammateus(location)    # https://pypi.org/project/grammateus/

kwargs = """  # this is a string in YAML format
  model:        gemini-2.5-flash-preview-04-17
  mime_type:    text/plain
  modalities:
    - TEXT
  max_tokens:   32000
  n:            1  # no longer a mandatory 1
  stop_sequences:
    - STOP
    - "\nTitle"
  temperature:  0.5
  top_k:        10
  top_p:        0.5
  thinking:     24576  # thinking tokens budget. 24576
"""

instruction = 'I am Joseph Jacobs. I retell folk tales'

text_to_continue = 'Once upon a time, when pigs drank wine'

machine_text = cp.continuation(
    text=text_to_continue,
    instruction=instruction,
    recorder=recorder,
    **yl(kwargs)
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

castor_pollux-0.0.9.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

castor_pollux-0.0.9-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file castor_pollux-0.0.9.tar.gz.

File metadata

  • Download URL: castor_pollux-0.0.9.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for castor_pollux-0.0.9.tar.gz
Algorithm Hash digest
SHA256 23ceaabce7654f7d0325fa82ec046500123fe48e2dae2c5d35a4cf25115b0ba3
MD5 b0f9b5c6d94a6643a6c74905dac0d769
BLAKE2b-256 5e2961327f8a876db87dc95178522d03cd353ccbc0d10aee60ac260de78bd7cd

See more details on using hashes here.

File details

Details for the file castor_pollux-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: castor_pollux-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for castor_pollux-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 1bff96047980a1702f22ff975a988c72dd7efacce2fe7395145eeff3a67bc64f
MD5 d5a8900672104c4a8aa5a6d9c9ea065f
BLAKE2b-256 c509bd657987081dbe8ffcd2c1340d74873db8b81131c8e9003a45e3d9a824f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page