A Python package for interacting with the GoLean API service.
Project description
GoLean API Client
GoLean is a powerful Python client for the GoLean API, offering efficient and customizable 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 customizable compression rates.
- 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
from golean import GoLean
# Initialize the GoLean client
golean = GoLean(api_key="your_api_key")
# Compress a prompt
result = golean.compress_prompt(
context="The quick brown fox jumps over the lazy dog. The fox is known for its cunning and agility.",
compression_rate=0.5
)
print(f"Compressed Prompt: {result['compressed_prompt']}")
print(f"Original Number of Tokens: {result['original_tokens']}")
print(f"Compressed tokens: {result['compressed_tokens']}")
print(f"Actual Compression Rate: {result['actual_compression_rate']}")
Usage
Initialization
from golean import GoLean
# Initialize with API key
golean = GoLean(api_key="your_api_key")
# Or, set GOLEAN_API_KEY as an environment variable and initialize without parameters
golean = GoLean()
Compressing Prompts
result = golean.compress_prompt(
context="Large Language Models (LLMs) are revolutionizing various industries, from content creation to data analysis. These models, trained on vast amounts of text data, can generate human-like text, answer questions, and perform complex language tasks.",
compression_rate=0.7,
targetModelName="gpt-4o"
)
print(f"Compressed Prompt: {result['compressed_prompt']}")
print(f"Original Number of Tokens: {result['original_tokens']}")
print(f"Compressed Tokens: {result['compressed_tokens']}")
print(f"Actual Compression Rate: {result['actual_compression_rate']}")
Supported Models
GoLean supports compression optimization for various LLM models:
OpenAI Models
- gpt-3.5-turbo
- gpt-3.5-turbo-16k
- gpt-4-turbo
- gpt-4
- gpt-4o
- gpt-4o-2024-05-13
Anthropic Models
- claude-3-sonnet
- claude-3-opus
- claude-3-haiku
Cohere Models
- command-r
Configuration
API Key
Set your API key using one of these methods:
-
Environment variable:
export GOLEAN_API_KEY=your_api_key_here
-
.envfile in your project root:GOLEAN_API_KEY=your_api_key_here -
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_prompt(
context: str,
compression_rate: float,
openai_model_for_token_count: Optional[str] = "gpt-4o",
target_model_name: Optional[str] = "gpt-4o"
) -> Dict[str, Any]:
"""
Compress a prompt using the GoLean API.
Args:
context (str): The context for the prompt.
compression_rate (float): Desired compression rate (0 < rate <= 1). Default is 0.5.
openai_model_for_count: (str, optional). This specifies the OpenAI Model used to calculate the number of input and output tokens that will be returned in the API response.
targetModelName (str, optional): If a model name is passed, will enable model-specific cost savings tracking for that specific model, summarized in your dashboard.
Returns:
Dict[str, Any]: Dictionary containing the compressed prompt and metadata.
"""
For complete API documentation, please refer to our official documentation.
Response Format
The compress_prompt method returns a dictionary with the following keys:
compressed_context(str): The compressed version of the input context.original_tokens(int): The number of tokens in the original prompt.compressed_tokens(int): The number of tokens in the compressed prompt.actual_compression_rate(str): The achieved compression rate as a percentage.
Support
For technical assistance, please contact our support team:
- Email: support@golean.ai
- Documentation: https://docs.golean.ai
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file golean-0.1.5.tar.gz.
File metadata
- Download URL: golean-0.1.5.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ef0557fb986508cedc1f54522d816111dc34895108f52150552173854a3d942
|
|
| MD5 |
293cb718c98581459fb401fb1133ca9c
|
|
| BLAKE2b-256 |
d868fc2a2918c3f3c1b079177696669919cb9c842e7fb10d2d4a80672856364d
|
File details
Details for the file golean-0.1.5-py3-none-any.whl.
File metadata
- Download URL: golean-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecdd193df2f203291d7ac4224de817867df676f4cecd727fee552b7e709533bd
|
|
| MD5 |
7a0987d47fce09fdb897318606b93a5c
|
|
| BLAKE2b-256 |
c094d7f9f0a0d041af73dea80b841d671da8d9a3cca3f4772e4dd4483adcbcc6
|