trunkate-ai 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trunkate_ai-0.1.2/.gitignore +90 -0
- trunkate_ai-0.1.2/CHANGELOG.md +15 -0
- trunkate_ai-0.1.2/PKG-INFO +22 -0
- trunkate_ai-0.1.2/README.md +9 -0
- trunkate_ai-0.1.2/pyproject.toml +25 -0
- trunkate_ai-0.1.2/trunkate_ai/__init__.py +61 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Operating System
|
|
2
|
+
.DS_Store
|
|
3
|
+
Thumbs.db
|
|
4
|
+
*~
|
|
5
|
+
*.swp
|
|
6
|
+
|
|
7
|
+
# IDEs / Editors
|
|
8
|
+
.vscode/
|
|
9
|
+
.idea/
|
|
10
|
+
*.suo
|
|
11
|
+
*.ntvs*
|
|
12
|
+
*.njsproj
|
|
13
|
+
*.sln
|
|
14
|
+
*.sw?
|
|
15
|
+
|
|
16
|
+
# ------------------------------------------------------------------------------
|
|
17
|
+
# 1. Node.js (TypeScript SDK & CLI)
|
|
18
|
+
# ------------------------------------------------------------------------------
|
|
19
|
+
node_modules/
|
|
20
|
+
dist/
|
|
21
|
+
build/
|
|
22
|
+
coverage/
|
|
23
|
+
.nyc_output/
|
|
24
|
+
.npm/
|
|
25
|
+
npm-debug.log*
|
|
26
|
+
yarn-debug.log*
|
|
27
|
+
yarn-error.log*
|
|
28
|
+
.eslintcache
|
|
29
|
+
.tsbuildinfo
|
|
30
|
+
|
|
31
|
+
# ------------------------------------------------------------------------------
|
|
32
|
+
# 2. Python (Python SDK)
|
|
33
|
+
# ------------------------------------------------------------------------------
|
|
34
|
+
__pycache__/
|
|
35
|
+
*.py[cod]
|
|
36
|
+
*$py.class
|
|
37
|
+
*.so
|
|
38
|
+
.Python
|
|
39
|
+
build/
|
|
40
|
+
develop-eggs/
|
|
41
|
+
dist/
|
|
42
|
+
downloads/
|
|
43
|
+
eggs/
|
|
44
|
+
.eggs/
|
|
45
|
+
lib/
|
|
46
|
+
lib64/
|
|
47
|
+
parts/
|
|
48
|
+
sdist/
|
|
49
|
+
var/
|
|
50
|
+
wheels/
|
|
51
|
+
share/python-wheels/
|
|
52
|
+
*.egg-info/
|
|
53
|
+
.installed.cfg
|
|
54
|
+
*.egg
|
|
55
|
+
MANIFEST
|
|
56
|
+
|
|
57
|
+
# Environment
|
|
58
|
+
.env
|
|
59
|
+
.venv
|
|
60
|
+
env/
|
|
61
|
+
venv/
|
|
62
|
+
ENV/
|
|
63
|
+
env.bak/
|
|
64
|
+
venv.bak/
|
|
65
|
+
|
|
66
|
+
# ------------------------------------------------------------------------------
|
|
67
|
+
# 3. Rust (Rust SDK)
|
|
68
|
+
# ------------------------------------------------------------------------------
|
|
69
|
+
target/
|
|
70
|
+
**/*.rs.bk
|
|
71
|
+
|
|
72
|
+
# ------------------------------------------------------------------------------
|
|
73
|
+
# 4. Go (Go SDK)
|
|
74
|
+
# ------------------------------------------------------------------------------
|
|
75
|
+
# Binaries for programs and plugins
|
|
76
|
+
*.exe
|
|
77
|
+
*.exe~
|
|
78
|
+
*.dll
|
|
79
|
+
*.so
|
|
80
|
+
*.dylib
|
|
81
|
+
go/bin/
|
|
82
|
+
|
|
83
|
+
# Test binary, built with `go test -c`
|
|
84
|
+
*.test
|
|
85
|
+
|
|
86
|
+
# Output of the go coverage tool, specifically when used with LiteIDE
|
|
87
|
+
*.out
|
|
88
|
+
|
|
89
|
+
# Dependency directories (errors the go tool will print if present)
|
|
90
|
+
vendor/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.2](https://github.com/Trunkate-AI/trunkate-ai-sdk/compare/v0.1.1...v0.1.2) (2026-02-28)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* resolve publish pipeline configuration bugs across sdks ([13d521f](https://github.com/Trunkate-AI/trunkate-ai-sdk/commit/13d521faf52138f4c00c8bc86c123fa269a65d1c))
|
|
9
|
+
|
|
10
|
+
## [0.1.1](https://github.com/Trunkate-AI/trunkate-ai-sdk/compare/v0.1.0...v0.1.1) (2026-02-28)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* remove npm registry-url config to fix OIDC provenance and bump all SDKs ([5f93206](https://github.com/Trunkate-AI/trunkate-ai-sdk/commit/5f932067c98113dca6941d8ffbe2371834007335))
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: trunkate-ai
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Official Python SDK for Trunkate AI
|
|
5
|
+
Project-URL: Homepage, https://trunkate.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/Trunkate-AI/trunkate-ai
|
|
7
|
+
Author-email: Trunkate AI <hello@trunkate.ai>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Requires-Dist: httpx>=0.24.0
|
|
11
|
+
Requires-Dist: pydantic>=2.0.0
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# Trunkate AI Python SDK
|
|
15
|
+
|
|
16
|
+
Official Python SDK for integrating Trunkate AI prompt optimization into your application.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install trunkate-ai
|
|
22
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "trunkate-ai"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
description = "Official Python SDK for Trunkate AI"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Trunkate AI", email = "hello@trunkate.ai" },
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"httpx>=0.24.0",
|
|
17
|
+
"pydantic>=2.0.0",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://trunkate.ai"
|
|
22
|
+
Repository = "https://github.com/Trunkate-AI/trunkate-ai"
|
|
23
|
+
|
|
24
|
+
[tool.hatch.build.targets.wheel]
|
|
25
|
+
packages = ["trunkate_ai"]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Optional, Dict, Any
|
|
3
|
+
import httpx
|
|
4
|
+
from pydantic import BaseModel
|
|
5
|
+
|
|
6
|
+
class OptimizationStats(BaseModel):
|
|
7
|
+
original_tokens: int
|
|
8
|
+
optimized_tokens: int
|
|
9
|
+
reduction_percent: int
|
|
10
|
+
latency_ms: float
|
|
11
|
+
|
|
12
|
+
class OptimizationResult(BaseModel):
|
|
13
|
+
text: str
|
|
14
|
+
stats: OptimizationStats
|
|
15
|
+
|
|
16
|
+
class Trunkate:
|
|
17
|
+
def __init__(self, api_key: Optional[str] = None, base_url: Optional[str] = None):
|
|
18
|
+
self.api_key = api_key or os.getenv("TRUNKATE_API_KEY")
|
|
19
|
+
if not self.api_key:
|
|
20
|
+
raise ValueError(
|
|
21
|
+
"The TRUNKATE_API_KEY environment variable is missing or empty; "
|
|
22
|
+
"either provide it, or instantiate the Trunkate client with an api_key."
|
|
23
|
+
)
|
|
24
|
+
# Default to official API if not specified, can be overridden by env for testing
|
|
25
|
+
self.base_url = base_url or os.getenv("TRUNKATE_API_URL", "https://api.trunkate.ai")
|
|
26
|
+
# Ensure trailing slashes are stripped
|
|
27
|
+
self.base_url = self.base_url.rstrip("/")
|
|
28
|
+
|
|
29
|
+
headers = {
|
|
30
|
+
"Authorization": f"Bearer {self.api_key}",
|
|
31
|
+
"Content-Type": "application/json"
|
|
32
|
+
}
|
|
33
|
+
self.client = httpx.Client(base_url=self.base_url, headers=headers, timeout=10.0)
|
|
34
|
+
|
|
35
|
+
def optimize(self, text: str, task: Optional[str] = None, budget: Optional[int] = None, model: str = "gpt-4o") -> OptimizationResult:
|
|
36
|
+
"""
|
|
37
|
+
Optimize a prompt using the Trunkate AI API.
|
|
38
|
+
"""
|
|
39
|
+
payload = {
|
|
40
|
+
"text": text,
|
|
41
|
+
"model": model
|
|
42
|
+
}
|
|
43
|
+
if task:
|
|
44
|
+
payload["task"] = task
|
|
45
|
+
if budget:
|
|
46
|
+
payload["budget"] = budget
|
|
47
|
+
|
|
48
|
+
response = self.client.post("/optimize", json=payload)
|
|
49
|
+
response.raise_for_status()
|
|
50
|
+
|
|
51
|
+
data = response.json()
|
|
52
|
+
|
|
53
|
+
return OptimizationResult(
|
|
54
|
+
text=data["optimized_text"],
|
|
55
|
+
stats=OptimizationStats(
|
|
56
|
+
original_tokens=data["original_tokens"],
|
|
57
|
+
optimized_tokens=data["optimized_tokens"],
|
|
58
|
+
reduction_percent=data["reduction_percent"],
|
|
59
|
+
latency_ms=data["latency_ms"]
|
|
60
|
+
)
|
|
61
|
+
)
|