Skip to main content

Python SDK for Semantic Equivalence API - optimize prompts for semantic equivalence

Project description

Semantic EQ SDK

Python SDK for the Semantic Equivalence API - optimize prompts for semantic equivalence.

Installation

pip install semantic-eq

Quick Start

from semantic_eq_sdk import SemanticEQClient

# Initialize the client (API key is required)
client = SemanticEQClient(
    api_key="your-api-key",  # Get from https://semantic-eq.com
    base_url="https://api.semantic-eq.com"  # or your deployed URL
)

# Optimize a prompt
result = client.optimize_prompt("Write a compelling email subject line for our product launch")

print(f"Original: {result.original_prompt}")
print(f"Optimized: {result.optimized_prompt}")
if result.improvement_score:
    print(f"Improvement score: {result.improvement_score}")

API Reference

SemanticEQClient

Initialize the client with your API endpoint:

client = SemanticEQClient(
    api_key="your-api-key",           # Required - get from https://semantic-eq.com
    base_url="http://localhost:8001"  # Your API URL
)

optimize_prompt(prompt)

Optimize a single prompt for better semantic equivalence.

Parameters:

  • prompt (str): The prompt text to optimize

Returns:

  • OptimizationResult: Contains original and optimized prompt

Example:

result = client.optimize_prompt("Your prompt here")
print(result.optimized_prompt)

health_check()

Check if the API is healthy and accessible.

Returns:

  • dict: Health status information

Example:

health = client.health_check()
print(f"API Status: {health['status']}")

Response Objects

OptimizationResult

The result of a prompt optimization:

@dataclass
class OptimizationResult:
    original_prompt: str           # The original prompt
    optimized_prompt: str          # The optimized version
    improvement_score: float       # Optional improvement score (0-1)

Error Handling

from semantic_eq_sdk import SemanticEQError, OptimizationError

try:
    result = client.optimize_prompt("Your prompt")
    print(result.optimized_prompt)
except OptimizationError as e:
    print(f"Optimization failed: {e}")
except SemanticEQError as e:
    print(f"SDK error: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

API Endpoints

This SDK expects your API to have these endpoints:

  • POST /optimize - Optimize a prompt

    // Request
    {"prompt": "Your prompt text"}
    
    // Response
    {
      "original_prompt": "Your prompt text",
      "optimized_prompt": "Optimized version",
      "improvement_score": 0.85
    }
    
  • GET /health - Health check

    // Response
    {"status": "healthy"}
    

Development

Running Tests

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest test/

Code Style

# Format code
black src/

# Lint code  
flake8 src/

License

MIT License - see LICENSE file for details.

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

semantic_eq-1.0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

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

semantic_eq-1.0.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file semantic_eq-1.0.1.tar.gz.

File metadata

  • Download URL: semantic_eq-1.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for semantic_eq-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d45db1b462888f9ef189c9754648cd1ade4ee3283479b70bf4cc95388fcf2404
MD5 979e0e0a24c46a531cf0986636b4ea6c
BLAKE2b-256 0930118ff6d9c3af29680e76af4d28b1460cec2cc6b8ebd03666410ae58aac33

See more details on using hashes here.

File details

Details for the file semantic_eq-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: semantic_eq-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for semantic_eq-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 201c57b49c496c67e1cb27f633d6fba48cf9aca5aa764aca548720512b852754
MD5 c99d68bebb20b734971f09b8469f7ef9
BLAKE2b-256 4ef23e4af0a8dbdf12d7723bfcace9246d07ffece3fd5837f3b92ba60f63cd99

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