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.4.tar.gz (6.1 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.4-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: golean-0.2.4.tar.gz
  • Upload date:
  • Size: 6.1 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.4.tar.gz
Algorithm Hash digest
SHA256 93d6bb7f3e957525ff23ebbaf31dbdd9c878aca0cdf94e102fcddff6306bc6cb
MD5 845f849532960efd487d92c3294ffef2
BLAKE2b-256 d06df6c19fe0544055e379dc12b62b0c5a9f84f3b4c10e438d80799799eb887a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: golean-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 5.8 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8f873a75b19577d957d3a0e54e8edd4bf48b3b790dc0a7fae3e6932088051add
MD5 6fcd65bb1cd271df5aa7c9793caa9028
BLAKE2b-256 4b422653e9c30b08f615a9a02121d5a2cdb221097c2d7f5269438c8c6f4b53c3

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