Skip to main content

Cactusfruit SDK

A Python SDK for interacting with Cactusfruit model services, including text embeddings, token counting, and text generation.

Features

  • Generate text using a configured language model.
  • Create document embeddings.
  • Create query embeddings.
  • Count embedding tokens.
  • Configure the server URL and model paths.
  • Run the configuration loader explicitly when needed.

Installation

Install from PyPI:

pip install cactusfruit-sdk

Quick Start

Import the client:

from cactusfruit.sdk import LlmServerClient

client = LlmServerClient()

Generate Text

response = client.generate(
    role="user",
    content="Explain what a Python SDK is.",
)

print(response)

You can also provide generation parameters:

response = client.generate(
    role="user",
    content="Write a short introduction to machine learning.",
    params={
        "temperature": 0.7,
        "max_tokens": 200,
    },
)

print(response)

The parameters accepted depend on the underlying Cactusfruit model service.

Generate Document Embeddings

embedding = client.embed_document(
    "This is a document to embed."
)

print(embedding)

Generate Query Embeddings

embedding = client.embed_query(
    "How does semantic search work?"
)

print(embedding)

Count Embedding Tokens

token_count = client.embed_token_count(
    "Count the tokens in this text."
)

print(token_count)

Configuration

The LlmServerClient supports configuration through constructor arguments.

from cactusfruit.sdk import LlmServerClient

client = LlmServerClient(
    base_url="http://localhost:8000",
    embedder_model_path="models/all-MiniLM-L6-v2",
    generator_model_path="models/your-generator-model",
)
Argument Description
base_url Base URL of the Cactusfruit model service
embedder_model_path Model path used for document embeddings, query embeddings, and embedding token counts
generator_model_path Model path used for text generation

The default server URL is http://localhost:8000. The default embedding model path is models/all-MiniLM-L6-v2.

The default generator model path in the current client implementation is also models/all-MiniLM-L6-v2. For text generation, explicitly configure a suitable generator model path.

Configuration Loader

Cactusfruit SDK includes a configuration loader intended for environments such as Docker.

The configuration loader is not executed automatically when the package is installed or imported. Run it explicitly when you want to generate /app/.env.

Run the loader

Set MODEL_CONFIG_ARG to a JSON configuration and invoke the module:

export MODEL_CONFIG_ARG='{
  "type": "generative",
  "system_prompt": "You are a helpful assistant.",
  "params": {
    "threads": 8,
    "parallel": 4
  }
}'

python -m cactusfruit.dockerscripts.configloader

The loader writes configuration values to /app/.env.

Example Docker usage

FROM python:3.11-slim

WORKDIR /app

RUN pip install --no-cache-dir cactusfruit-sdk

ENV MODEL_CONFIG_ARG='{"type":"generative","system_prompt":"You are a helpful assistant.","params":{"threads":8,"parallel":4}}'

RUN python -m cactusfruit.dockerscripts.configloader

Note: The loader writes to /app/.env, so the process must have permission to create or modify that file. The loader's environment variables are used to generate the file; writing a .env file does not automatically load its values into every running process. Your application must load the file or otherwise configure its environment.

Avoid putting secrets in Docker build arguments or image environment variables, as they may be exposed through image metadata or build history.

Model Service Endpoints

The client communicates with the configured model service using these endpoints:

Operation Endpoint
Document embeddings /m/embed/doc
Query embeddings /m/embed/query
Embedding token count /m/embed/token/count
Text generation /m/prompt

The model service must be running and accessible at the configured base_url.

Requirements

  • Python 3.10 or later
  • requests
  • python-dotenv

These dependencies are installed automatically when you install cactusfruit-sdk from PyPI.

Development

Clone the repository:

git clone https://github.com/jon004/cactusfruit-sdk.git
cd cactusfruit-sdk

Install the package in editable mode:

python -m pip install -e .

Build the distribution:

python -m pip install --upgrade build
python -m build

Contributing

Contributions, bug reports, and feature requests are welcome. Please open an issue or pull request in the GitHub repository.

License

Add your project's chosen license here before publishing. If you intend others to use, modify, and redistribute this SDK, include an appropriate license file in the repository.

Metadata

Release files for cactusfruit-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cactusfruit-sdk 0.1.0
File Size Uploaded Provenance
cactusfruit_sdk-0.1.0.tar.gz 6.9 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cactusfruit-sdk 0.1.0
File Interpreter ABI Platform
cactusfruit_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.9 MB

Release files / cactusfruit_sdk-0.1.0.tar.gz

Download URL cactusfruit_sdk-0.1.0.tar.gz
Size 6.9 MB
Tags Source
SHA-256 checksum
How to use checksums
64ddcc5d258da7131256d2fe4a7dd6149df805ff61fa008308e244c1c6d4b1ab
BLAKE2b-256 checksum
How to use checksums
c6fc87bd4b918b46aa302798b4155964785f04e8f2946c63961b91fa12848504
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / cactusfruit_sdk-0.1.0-py3-none-any.whl

Download URL cactusfruit_sdk-0.1.0-py3-none-any.whl
Size 2.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd210d8a55e4c9d8d0322f02ae40a8b9904faef640c591feb6a7ea21cfb24a5f
BLAKE2b-256 checksum
How to use checksums
1d3d022b73b36738a33c53dafba740d84faa46ba0e0873aa667a27d0e8c422b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for cactusfruit-sdk 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page