Skip to main content

WordToken

WordToken is a lightweight and flexible Python library for interacting with popular large language model (LLM) providers, such as OpenAI and Anthropic's Claude. It offers a unified interface for generating text, estimating token usage, and calculating costs, making it ideal for both experimentation and production use.

Features

  • Unified Interface: Interact seamlessly with multiple LLM providers through a single API.
  • Token Management: Estimate token usage for prompts and responses.
  • Cost Estimation: Calculate costs based on provider-specific pricing.
  • Extensible: Easily add support for additional LLM providers.
  • Sandbox-Friendly: Designed for experimentation and real-world integration.

Installation

Install WordToken using pip:

pip install wordtoken

Supported LLM Providers

•	OpenAI
•	Anthropic Claude

Usage

Initialize the Library

from wordtoken import WordToken

# Initialize WordToken with your API key
token = WordToken(api_key="your-api-key")

Generate Text

# Generate text with OpenAI
response = wordtoken.send_prompt(
    prompt="Write a short story about a robot learning to love.",
    model="gpt-3.5-turbo",
    max_tokens=100,
    temperature=0.7
)
print(response["output"])

Estimate Tokens

# Estimate tokens for a prompt
tokens = wordtoken.estimate_tokens(prompt="Hello, world!", model="gpt-3.5-turbo")
print(f"Estimated tokens: {tokens}")

Estimate Costs

# Estimate cost for a given number of tokens
tokens = 100  # Example token count
cost = wordtoken.calculate_cost(tokens=tokens, model="gpt-3.5-turbo")
print(f"Estimated cost: ${cost:.4f}")

Configuration

Available Models and Defaults

  • OpenAI:
  • Models: gpt-3.5-turbo, gpt-4, gpt-4o
  • Pricing: Automatically managed based on the latest OpenAI rates.
  • Claude (Anthropic):
  • Models: claude-v1, claude-v2, etc.
  • Pricing: Configurable for Anthropic's usage tiers.

Adding New Providers

Extend the library by adding a new adapter in the adapters.py file and updating the unified interface in the init.py file.

Development

Clone the Repository

git clone https://github.com/your-username/wordtoken.git
cd wordtoken

Install Dependencies

pip install -r requirements.txt

Run Tests

pytest

License

WordToken is licensed under the Apache License 2.0.

Contributing

Contributions are welcome! Please feel free to submit a pull request.

Roadmap

•	Support for additional LLM providers (e.g., Google Gemini, Cohere).
•	Advanced token visualization and usage analytics.
•	Integration with sandbox tools for prompt experimentation.

Contact

For questions or feedback, please contact contact@wordtoken.com.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wordtoken-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

wordtoken-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file wordtoken-0.1.1.tar.gz.

File metadata

  • Download URL: wordtoken-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for wordtoken-0.1.1.tar.gz
Algorithm Hash digest
SHA256 22c024b5b89301294ce193fbd3cb9a2d979721f4eb15834f59a874f7c6883a1b
MD5 45c70cf733f0ccd1436dcb11f2ab6bec
BLAKE2b-256 48f5e707f808b096c851217bc3b2316c7ef33b3420c9bf147882d856c705847b

See more details on using hashes here.

File details

Details for the file wordtoken-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: wordtoken-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for wordtoken-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9739874dfeb432f239f1e9f4e4de214ba1f307ff71b162743b1446c2faa21c0
MD5 325f4eab412fe6db80d2536aeac9dc94
BLAKE2b-256 7c8f5502931fbf5135dc75143dccaee634c4a89660af578232a513ac5826f932

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