Skip to main content

A Python package for interacting with the GoLean API service.

Project description

GoLean API Client

PyPI version Python Versions

GoLean is a powerful Python client for the GoLean API, offering efficient and prompt compression services tailored for Large Language Models (LLMs). Optimize your LLM workflows with our state-of-the-art compression algorithms.

Features

  • Efficient Prompt Compression: Optimize LLM performance with prompt compression.
  • Flexible Model Support: Compatible with a wide range of LLMs from OpenAI, Anthropic, and Cohere.
  • Cost Optimization: Reduce token usage for various LLM APIs.
  • Secure Authentication: Robust API key-based authentication system.
  • Easy Configuration: Seamless setup with support for environment variables.
  • Comprehensive Documentation: Detailed guides and API references to get you started quickly.

Installation

Install the GoLean client using pip:

pip install golean

Quick Start

Here’s how to get started with GoLean:

Example 1: Compress Context

Context could be any text you want to compress. Examples of this could be user and bot messages in a conversation history, an article, a piece of text, etc.

from golean import GoLean

# Initialize the GoLean client
golean = GoLean(api_key="your_api_key")

# Compress a prompt
result = golean.compress_with_context(
    context="A large language model (LLM) is a type of computational model designed for natural language processing tasks such as language generation. As language models, LLMs acquire these abilities by learning statistical relationships from vast amounts of text during a self-supervised and semi-supervised training process."
)

print("Compressed Result:", result)

Example 2: Compress Using Prompt Template and Data

Prompt template is a python string with placeholder strings that will be populated by data. Here, we will compress the data and then populate the compressed data back to the template.

from golean import GoLean

# Initialize with API key
golean = GoLean(api_key="your_api_key")

# Compress template and data
result = golean.compress_with_template(
    template="""Read the passage, then answer the question. Only output the exact answer without any extra word or punctuation. 
Passage: {context}
Question: {question}""",
    data={
        "context": "A large language model (LLM) is a type of computational model designed for natural language processing tasks such as language generation. As language models, LLMs acquire these abilities by learning statistical relationships from vast amounts of text during a self-supervised and semi-supervised training process." ,
        "question": "name an example task the LLM is designed for"
    }
)

print("Compressed Result:", result)

Configuration

API Key

Set your API key using one of these methods:

  1. Environment variable:

    export GOLEAN_API_KEY=your_api_key_here
    
  2. .env file in your project root:

    GOLEAN_API_KEY=your_api_key_here
    
  3. Directly in your code (not recommended for production):

    golean = GoLean(api_key="your_api_key_here")
    

API Reference

GoLean Class

class GoLean:
    def __init__(self, api_key: Optional[str] = None):
        """
        Initialize the GoLean client.

        Args:
            api_key (str, optional): Your GoLean API key. If not provided, reads from GOLEAN_API_KEY env variable.
        """

    def compress_with_context(context: str) -> Dict[str, Any]:
        """
        Compress a context string using the GoLean API.

        Args:
            context (str): The context string to be compressed.

        Returns:
            Dict[str, Any]: Contains compressed result, token counts, and compression rate.
        """

    def compress_with_template(template: str, data: Dict[str, Any]) -> Dict[str, Any]:
        """
        Compress a template string by replacing placeholders with compressed values.

        Args:
            template (str): A string containing placeholders (e.g., "{key}").
            data (dict): Key-value pairs where keys match placeholders in the template.

        Returns:
            Dict[str, Any]: Contains compressed result, token counts, and compression rate.
        """

For complete API documentation, please refer to our official documentation.

Response Format

The compress_with_context and compress_with_template methods returns a dictionary with the following keys:

  • compressed_result (str): The compressed version of the input.
  • origin_tokens (int): The number of tokens in the original input.
  • compressed_tokens (int): The number of tokens in the compressed output.
  • compression_rate (str): Ratio of compressed_tokens / origin_tokens.

Supported Models

GoLean supports compression optimization for various LLM models:

OpenAI Models

GPT-3.5 Series

  • gpt-3.5-turbo
  • gpt-3.5-turbo-16k

GPT-4 Series

  • gpt-4
  • gpt-4-turbo

GPT-4o Series

  • gpt-4o
  • gpt-4o-mini

o1 Series

  • o1-preview
  • o1-mini

Anthropic Models

Claude 3 Series

  • claude-3-haiku
  • claude-3-sonnet
  • claude-3-opus

Claude 3.5 Series

  • claude-3.5-haiku
  • claude-3.5-sonnet

Cohere Models

Command Series

  • command-r
  • command-r+

Aya Series

  • aya

Support

For technical assistance, please contact our support team:

For enterprise support options and custom LLM optimization solutions, please contact our sales team at support@golean.ai.

Legal

Copyright © 2024 GoLean, Inc. All rights reserved.

GoLean is a registered trademark of GoLean, Inc. All other trademarks are the property of their respective owners.


Empower your LLMs with GoLean - Compress, Optimize, Succeed.

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

golean-0.2.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

golean-0.2.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file golean-0.2.3.tar.gz.

File metadata

  • Download URL: golean-0.2.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for golean-0.2.3.tar.gz
Algorithm Hash digest
SHA256 1d23f5952e96c1259aadf334f0ea7a019f14ca99a2b4d052d146b9f290869fd6
MD5 1140b322f9f6cd40c7f0dffafcfbd973
BLAKE2b-256 1fa7abb6fb48fb3fbf049bb2982eeabb773f80e8548e9aafc7e8f14ca273524f

See more details on using hashes here.

File details

Details for the file golean-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: golean-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for golean-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5a4bb44bca415b05d08e06ff7b8d3c0c2187b4abe261cf7bfdd581bba98ba060
MD5 ce7097ecaf2b71012ccdcfcf7c5f054f
BLAKE2b-256 df333ffdac8bc9fa6f7f68fa033c12c05a885c90da66d1ca6f9caf036ff3c929

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