ask-tokens 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/README.md +51 -0
- data/lib/ask/tokens/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ae96192b20e70ac88fb98af984b5a13cf749c7d7bf73fc786d59fc89e27002c1
|
|
4
|
+
data.tar.gz: e48974d2d1998878c63579e788a6882757bc39aaa524b71c99c1fde426e939d9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 52b0688ccb3e4ef1c0983b6a642937981c7ffd8fad2380fc8385781c371c773e33387dbb11ef953627338aedcefeb11e60a8a88245e8ef00fccd6be46602eeaf
|
|
7
|
+
data.tar.gz: e5244ed51b9567605caa139c29b200372f3327fbd1950cf3b051e4b081a9c23656067dbbac0195a3e95942400edd1bfcf5982e9dd4861b93eb25b1f1db4c23d3
|
data/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# ask-tokens
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/ask-tokens)
|
|
4
|
+
|
|
5
|
+
Pure-Ruby token accounting: count real tokens, price them at any rate,
|
|
6
|
+
declare activity costs, and run a wallet/ledger engine against a pluggable
|
|
7
|
+
store. Rails-free by design — pair with
|
|
8
|
+
[ask-tokens-rails](https://github.com/ask-rb/ask-tokens-rails) for
|
|
9
|
+
ActiveRecord persistence.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
gem "ask-tokens"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
require "ask-tokens"
|
|
21
|
+
|
|
22
|
+
Ask::Tokens.configure do |c|
|
|
23
|
+
c.price_per_1m = Money.from_amount(100, "USD")
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
Ask::Tokens.activity(:chat_message) do |params|
|
|
27
|
+
Ask::Tokens.count_tokens(params[:input]) +
|
|
28
|
+
Ask::Tokens.count_tokens(params[:output])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
wallet = Ask::Tokens.wallet_for("user:42")
|
|
32
|
+
wallet.grant!(1000, reason: :signup)
|
|
33
|
+
wallet.spend!(:chat_message, input: "hi", output: "yo") do
|
|
34
|
+
LLM.chat(...) # only charged when the block succeeds
|
|
35
|
+
end
|
|
36
|
+
wallet.balance # => 996
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Token counting uses tiktoken (model-aware encoding, `cl100k_base`
|
|
40
|
+
fallback); pricing uses the Money gem at a configurable per-million
|
|
41
|
+
rate. The in-memory store ships for scripts and tests; bring your own
|
|
42
|
+
store (e.g. ActiveRecord via ask-tokens-rails) for production.
|
|
43
|
+
|
|
44
|
+
## Contributing
|
|
45
|
+
|
|
46
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md). Run the suite with
|
|
47
|
+
`bundle exec rake test`.
|
|
48
|
+
|
|
49
|
+
## License
|
|
50
|
+
|
|
51
|
+
MIT License. See [LICENSE](LICENSE).
|
data/lib/ask/tokens/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ask-tokens
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kaka Ruto
|
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
|
76
76
|
files:
|
|
77
77
|
- CHANGELOG.md
|
|
78
78
|
- LICENSE
|
|
79
|
+
- README.md
|
|
79
80
|
- lib/ask-tokens.rb
|
|
80
81
|
- lib/ask/tokens.rb
|
|
81
82
|
- lib/ask/tokens/activity.rb
|