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.2.tar.gz (6.2 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.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: golean-0.2.2.tar.gz
  • Upload date:
  • Size: 6.2 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.2.tar.gz
Algorithm Hash digest
SHA256 5a7f3e21822c326520b245e7662646e5a59416678491e40357c64d93a31e22bd
MD5 929a1797033bb42288b9c3c08d2ce31b
BLAKE2b-256 f9b1d68fdaa199354e07b3a368ed71eab4c6df1b16c859c1c764d3c56fd3a7fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: golean-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3676b1ccf3d18870abe09c074cb836b027c4e13dff1132acb23e349b5df7f80b
MD5 a64d6a534cca4fe0c34cc237828a9478
BLAKE2b-256 e0983a1ed3ce366c1e97e189e7fea19c4ce96cecc4017427e4a54fb1f3f488da

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