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.

Metadata

Release files for wordtoken 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wordtoken 0.1.2
File Size Uploaded Provenance Actions
wordtoken-0.1.2.tar.gz 6.8 kB Without provenance Details for wordtoken-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wordtoken 0.1.2
File Interpreter ABI Platform Actions
wordtoken-0.1.2-py3-none-any.whl Python 3 none any Details for wordtoken-0.1.2-py3-none-any.whl

Total release size: 13.7 kB

Release files / wordtoken-0.1.2.tar.gz

Download URL wordtoken-0.1.2.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9ee77807636038c8ff275e3b1433655b1f97752ad94e3163b23cb9cd801064a2
BLAKE2b-256 checksum
How to use checksums
168a612b3d53873083e82d546d913d32c5f9372aad512115148a26a22ba244ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Release files / wordtoken-0.1.2-py3-none-any.whl

Download URL wordtoken-0.1.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb035e176de7c26a1f12b26e21ec25234ef517f1086e7a4bd3774dc28d8779f2
BLAKE2b-256 checksum
How to use checksums
f0fc138acec891e0f91654da83c89f2f6705d36cba2057dbef20bd4ce462f3ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.3

Security for wordtoken 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page