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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +51 -0
  3. data/lib/ask/tokens/version.rb +1 -1
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 261225306a7956a3d338a7d6b6a050d75622d1d519faa2f604620c437830902b
4
- data.tar.gz: '07718f45a62524c544da251d7e8d96cd0d428bc50ab44acebba89ab98714f4c3'
3
+ metadata.gz: ae96192b20e70ac88fb98af984b5a13cf749c7d7bf73fc786d59fc89e27002c1
4
+ data.tar.gz: e48974d2d1998878c63579e788a6882757bc39aaa524b71c99c1fde426e939d9
5
5
  SHA512:
6
- metadata.gz: 5c90791364266bce3c55b91fc2bc59b0fe259cad9a7b82cd1dcb51315cf882796733c6dd94fb50f5389e9a35f890d9aabe29e81cff0649ece114f6385b97bef6
7
- data.tar.gz: d01f9e055b141ea3aec34ecb5c4f696246c417cd1b9811bb6248158539afefd0b93c527a09922a896206231dc8b2ab5c809573a198578aadea5fafbe758796be
6
+ metadata.gz: 52b0688ccb3e4ef1c0983b6a642937981c7ffd8fad2380fc8385781c371c773e33387dbb11ef953627338aedcefeb11e60a8a88245e8ef00fccd6be46602eeaf
7
+ data.tar.gz: e5244ed51b9567605caa139c29b200372f3327fbd1950cf3b051e4b081a9c23656067dbbac0195a3e95942400edd1bfcf5982e9dd4861b93eb25b1f1db4c23d3
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # ask-tokens
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/ask-tokens.svg)](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).
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  module Tokens
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end
7
7
  end
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.0
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