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
client = SemanticEQClient(
    base_url="https://api.semantic-eq.com",  # or your deployed URL
    api_key="your-api-key"  # optional
)

# 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(
    base_url="http://localhost:8001",  # Your API URL
    api_key="optional-api-key"        # Optional authentication
)

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.0.tar.gz (5.6 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.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: semantic_eq-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 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.0.tar.gz
Algorithm Hash digest
SHA256 93eecef669b40e5cd27e17f8a5340af5196e2296c2db434cb85b9d2023b484ca
MD5 837d8fdafe18240e54831ff2feb7526c
BLAKE2b-256 9d2148fdd6d7f00616760f083c93ce9127317325c90ee18073f9c5a70e63d824

See more details on using hashes here.

File details

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

File metadata

  • Download URL: semantic_eq-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bb11b1215de4db6e71eda13a2972ffcf4712be8cb2c258417174b881ca50522
MD5 d1e96b7d31fa1639af42237a4ee8cb0f
BLAKE2b-256 1831ca9fac8e9366e8e8609ba77f85d51524d2651c4d1cb9f1d12ba288f58fe1

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