chalk_ruby 0.2.7 → 0.3.0
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/Dockerfile +26 -0
- data/README.md +95 -9
- data/lib/chalk_ruby/client.rb +5 -3
- data/lib/chalk_ruby/grpc_client.rb +20 -3
- data/lib/chalk_ruby/version.rb +1 -1
- data/test/chalk_ruby/integration/client_test.rb +13 -1
- data/test/chalk_ruby/integration/grpc_client_test.rb +27 -48
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e3e6e01afae6634b4b66b557f658573bf4ffd2b657c082652e45185ec48ec05
|
4
|
+
data.tar.gz: 58222edf6ee281ae1cfbaaeec09b628985cfe96ddce3299054f5318e61a1d036
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e995a01c66b8086fff20b2b7d1304458d2370a73205b87b2c6c2860df0a03e93affda126d20cf8d018ed3fe32f0e612e6ef4b7cdef5d95d1b5b02456994eb5b
|
7
|
+
data.tar.gz: b00008371f1f5f5a2fbd3113a7e2db1cca4e58100ac5ba8385cfad08f065acb1476d645edc5f853ca5d8a67392cd4b3ce3d2aed8b85f979aebd618bedde48a68
|
data/Dockerfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
FROM ubuntu:22.04
|
2
|
+
|
3
|
+
ENV BUNDLER_VERSION=2.3.6 \
|
4
|
+
BUNDLE_PATH=/app/vendor/bundle
|
5
|
+
|
6
|
+
RUN apt-get update && apt-get install -y \
|
7
|
+
ca-certificates \
|
8
|
+
sudo \
|
9
|
+
wget \
|
10
|
+
lsb-release \
|
11
|
+
build-essential \
|
12
|
+
bash \
|
13
|
+
jq \
|
14
|
+
curl \
|
15
|
+
libffi-dev \
|
16
|
+
git \
|
17
|
+
libglib2.0-dev \
|
18
|
+
ruby-full
|
19
|
+
|
20
|
+
# Install Apache Arrow 18
|
21
|
+
RUN wget https://apache.jfrog.io/artifactory/arrow/ubuntu/apache-arrow-apt-source-latest-jammy.deb && \
|
22
|
+
apt-get install -y -V ./apache-arrow-apt-source-latest-jammy.deb && \
|
23
|
+
apt-get update && \
|
24
|
+
apt-get install -y -V libarrow-dev=18.* libarrow-glib-dev=18.* libparquet-dev=18.* libarrow-acero-dev=18.* gir1.2-arrow-1.0=18.*
|
25
|
+
|
26
|
+
RUN gem install bundler
|
data/README.md
CHANGED
@@ -1,29 +1,115 @@
|
|
1
|
-
|
1
|
+
# ChalkRuby - Ruby Client for Chalk
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/chalk_ruby)
|
4
|
+
[](LICENSE)
|
4
5
|
|
5
|
-
Ruby client for Chalk
|
6
|
+
A Ruby client library for [Chalk](https://chalk.ai/), a feature engineering platform for machine learning and data applications.
|
6
7
|
|
7
|
-
|
8
|
+
## Installation
|
8
9
|
|
9
|
-
|
10
|
+
Add this line to your application's Gemfile:
|
10
11
|
|
11
|
-
|
12
|
+
```ruby
|
13
|
+
gem 'chalk_ruby'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
bundle install
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it directly:
|
12
23
|
|
13
24
|
```bash
|
14
25
|
gem install chalk_ruby
|
15
26
|
```
|
16
27
|
|
17
|
-
|
28
|
+
## Quick Start
|
18
29
|
|
19
30
|
```ruby
|
20
|
-
|
31
|
+
# Create a client with credentials
|
32
|
+
client = ChalkRuby::Client.create(
|
33
|
+
'my-client-id',
|
34
|
+
'my-client-secret',
|
35
|
+
'my-environment-id' # Optional, can also use CHALK_ACTIVE_ENVIRONMENT env var
|
36
|
+
)
|
37
|
+
|
38
|
+
# Query features
|
21
39
|
results = client.query(
|
22
40
|
input: { 'user.id': 'my-user-id' },
|
23
|
-
output: %w(user.id user.name user.email)
|
41
|
+
output: %w(user.id user.name user.email),
|
42
|
+
query_name: 'user_profile' # Optional: for tracking and monitoring
|
24
43
|
)
|
44
|
+
|
45
|
+
# Access feature values
|
46
|
+
puts results['user.name']
|
25
47
|
```
|
26
48
|
|
49
|
+
## Authentication
|
50
|
+
|
51
|
+
Authentication can be provided in multiple ways:
|
52
|
+
|
53
|
+
1. Directly in the client constructor:
|
54
|
+
```ruby
|
55
|
+
client = ChalkRuby::Client.create('my-client-id', 'my-client-secret')
|
56
|
+
```
|
57
|
+
|
58
|
+
2. Using environment variables:
|
59
|
+
```
|
60
|
+
CHALK_CLIENT_ID=my-client-id
|
61
|
+
CHALK_CLIENT_SECRET=my-client-secret
|
62
|
+
CHALK_ACTIVE_ENVIRONMENT=my-environment # Optional
|
63
|
+
```
|
64
|
+
```ruby
|
65
|
+
client = ChalkRuby::Client.create
|
66
|
+
```
|
67
|
+
|
68
|
+
## Advanced Usage
|
69
|
+
|
70
|
+
### Query Options
|
71
|
+
|
72
|
+
The `query` method supports several options:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
client.query(
|
76
|
+
input: { 'user.id': 'my-user-id' },
|
77
|
+
output: %w(user.id user.name user.credit_score),
|
78
|
+
now: Time.now, # Optional: time at which to evaluate the query
|
79
|
+
staleness: { 'user.credit_score': '1d' }, # Optional: max staleness for cached features
|
80
|
+
tags: { 'environment': 'production' }, # Optional: tags for resolver selection
|
81
|
+
branch: 'my-feature-branch', # Optional: route request to a specific branch
|
82
|
+
correlation_id: 'request-123', # Optional: ID for tracing in logs
|
83
|
+
query_name: 'user_profile', # Optional: semantic name for the query
|
84
|
+
timeout: 5.0 # Optional: timeout in seconds
|
85
|
+
)
|
86
|
+
```
|
87
|
+
|
88
|
+
### Configuration
|
89
|
+
|
90
|
+
Create a client with custom configuration:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
config = ChalkRuby::Config.new(
|
94
|
+
client_id: 'my-client-id',
|
95
|
+
client_secret: 'my-client-secret',
|
96
|
+
environment: 'my-environment',
|
97
|
+
query_server: 'https://custom-query-server.chalk.ai',
|
98
|
+
api_server: 'https://custom-api.chalk.ai',
|
99
|
+
additional_headers: { 'X-Custom-Header': 'value' }
|
100
|
+
)
|
101
|
+
|
102
|
+
client = ChalkRuby::Client.create_with_config(config)
|
103
|
+
```
|
104
|
+
|
105
|
+
## Requirements
|
106
|
+
|
107
|
+
- Ruby 2.7 or higher
|
108
|
+
|
109
|
+
## Version
|
110
|
+
|
111
|
+
Current version: `0.2.8`
|
112
|
+
|
27
113
|
## License
|
28
114
|
|
29
|
-
The Chalk Ruby
|
115
|
+
The Chalk Ruby Client is open-sourced software licensed under the [Apache 2.0 License](LICENSE).
|
data/lib/chalk_ruby/client.rb
CHANGED
@@ -150,7 +150,8 @@ module ChalkRuby
|
|
150
150
|
explain: nil,
|
151
151
|
include_meta: nil,
|
152
152
|
store_plan_stages: nil,
|
153
|
-
timeout: nil
|
153
|
+
timeout: nil,
|
154
|
+
planner_options: nil
|
154
155
|
)
|
155
156
|
query_server_request(
|
156
157
|
method: :post,
|
@@ -168,10 +169,11 @@ module ChalkRuby
|
|
168
169
|
meta: meta,
|
169
170
|
explain: explain || false,
|
170
171
|
include_meta: include_meta || false,
|
171
|
-
store_plan_stages: store_plan_stages || false
|
172
|
+
store_plan_stages: store_plan_stages || false,
|
173
|
+
planner_options: planner_options || {}
|
172
174
|
},
|
173
175
|
headers: get_authenticated_engine_headers(branch: branch),
|
174
|
-
timeout:
|
176
|
+
timeout: timeout
|
175
177
|
)
|
176
178
|
end
|
177
179
|
|
@@ -146,6 +146,14 @@ module ChalkRuby
|
|
146
146
|
query_service.ping(Chalk::Engine::V1::PingRequest.new(num: 1))
|
147
147
|
end
|
148
148
|
|
149
|
+
def convert_to_proto_values(options_hash)
|
150
|
+
return {} if options_hash.nil?
|
151
|
+
|
152
|
+
options_hash.transform_values do |value|
|
153
|
+
convert_to_protobuf_value(value)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
149
157
|
def query_bulk(
|
150
158
|
input:,
|
151
159
|
output:,
|
@@ -157,7 +165,8 @@ module ChalkRuby
|
|
157
165
|
timeout: nil,
|
158
166
|
query_name: nil,
|
159
167
|
query_name_version: nil,
|
160
|
-
correlation_id: nil
|
168
|
+
correlation_id: nil,
|
169
|
+
planner_options: nil
|
161
170
|
)
|
162
171
|
# Convert input to feather format
|
163
172
|
inputs_feather = to_feather(input)
|
@@ -167,7 +176,12 @@ module ChalkRuby
|
|
167
176
|
inputs_feather: inputs_feather,
|
168
177
|
outputs: output.map { |o| Chalk::Common::V1::OutputExpr.new(feature_fqn: o) },
|
169
178
|
staleness: staleness || {},
|
170
|
-
context: context || Chalk::Common::V1::OnlineQueryContext.new(
|
179
|
+
context: context || Chalk::Common::V1::OnlineQueryContext.new(
|
180
|
+
query_name: query_name,
|
181
|
+
query_name_version: query_name_version,
|
182
|
+
correlation_id: correlation_id,
|
183
|
+
options: convert_to_proto_values(planner_options)
|
184
|
+
),
|
171
185
|
response_options: response_options || Chalk::Common::V1::OnlineQueryResponseOptions.new,
|
172
186
|
body_type: body_type || :FEATHER_BODY_TYPE_UNSPECIFIED
|
173
187
|
)
|
@@ -229,13 +243,16 @@ module ChalkRuby
|
|
229
243
|
explain: nil,
|
230
244
|
include_meta: nil,
|
231
245
|
store_plan_stages: nil,
|
232
|
-
timeout: nil
|
246
|
+
timeout: nil,
|
247
|
+
planner_options: nil
|
233
248
|
)
|
234
249
|
formatted_inputs = input.transform_values { |value| self.convert_to_protobuf_value(value) }
|
235
250
|
|
236
251
|
context = Chalk::Common::V1::OnlineQueryContext.new(
|
237
252
|
query_name: query_name,
|
238
253
|
query_name_version: query_name_version,
|
254
|
+
correlation_id: correlation_id,
|
255
|
+
options: planner_options || {}
|
239
256
|
)
|
240
257
|
|
241
258
|
r = Chalk::Common::V1::OnlineQueryRequest.new(
|
data/lib/chalk_ruby/version.rb
CHANGED
@@ -11,7 +11,19 @@ RSpec.describe 'Online query' do
|
|
11
11
|
client = ChalkRuby::Client.create(CLIENT_ID, CLIENT_SECRET)
|
12
12
|
response = client.query(
|
13
13
|
input: { 'user.id': 3454 },
|
14
|
-
output: %w(user.id)
|
14
|
+
output: %w(user.id),
|
15
|
+
query_name: "no_planner_options_test",
|
16
|
+
)
|
17
|
+
|
18
|
+
print response
|
19
|
+
end
|
20
|
+
it 'should run with planner options' do
|
21
|
+
client = ChalkRuby::Client.create(CLIENT_ID, CLIENT_SECRET)
|
22
|
+
response = client.query(
|
23
|
+
input: { 'user.id': 3454 },
|
24
|
+
output: %w(user.id),
|
25
|
+
query_name: "planner_options_test",
|
26
|
+
planner_options: {'defer_non_bus_persist_operators': "1"} # test planner option
|
15
27
|
)
|
16
28
|
|
17
29
|
print response
|
@@ -1,64 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# require 'chalk_ruby'
|
4
|
-
# require 'chalk_ruby'
|
5
|
-
|
6
|
-
require 'date'
|
7
|
-
require 'rspec/autorun'
|
8
|
-
require 'chalk_ruby/grpc_client'
|
9
|
-
require 'chalk_ruby/grpc/auth_interceptor'
|
10
|
-
require 'chalk_ruby/error'
|
11
|
-
require 'chalk_ruby/protos/chalk/server/v1/auth_pb'
|
12
|
-
require 'chalk_ruby/protos/chalk/server/v1/auth_services_pb'
|
13
|
-
require 'chalk_ruby/protos/chalk/engine/v1/query_server_services_pb'
|
14
|
-
require 'arrow'
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
require 'rspec'
|
2
|
+
require 'chalk_ruby'
|
18
3
|
|
19
4
|
RSpec.describe ChalkRuby::GrpcClient do
|
20
|
-
describe '#
|
5
|
+
describe '#query_bulk' do
|
21
6
|
let(:client) do
|
22
|
-
ChalkRuby::GrpcClient.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
environment: "tmnmc9beyujew",
|
29
|
-
# api_timeout: 0.6, # seconds
|
30
|
-
# connect_timeout: 0.3, # seconds
|
31
|
-
# query_service_root_ca_path: "/Users/andrew/found_ca.pem" # path to the root ca for chalkai.internal.found.app,
|
32
|
-
)
|
7
|
+
ChalkRuby::GrpcClient.create(
|
8
|
+
ENV.fetch('CHALK_CLIENT_ID'),
|
9
|
+
ENV.fetch('CHALK_CLIENT_SECRET'),
|
10
|
+
ENV.fetch('CHALK_ENVIRONMENT', 'tmnmc9beyujew'),
|
11
|
+
ENV.fetch('CHALK_QUERY_SERVER', 'standard-gke.chalk-develop.gcp.chalk.ai'),
|
12
|
+
ENV.fetch('CHALK_API_SERVER', 'api.staging.chalk.ai:443')
|
33
13
|
)
|
34
14
|
end
|
35
15
|
|
36
|
-
# it 'can perform queries' do
|
37
|
-
# response = client.query(
|
38
|
-
# input: { 'business.id': 1 },
|
39
|
-
# output: %w(business.id)
|
40
|
-
# )
|
41
|
-
#
|
42
|
-
# expect(response).not_to be_nil
|
43
|
-
#
|
44
|
-
# puts response
|
45
|
-
# # The response should be a OnlineQueryBulkResponse
|
46
|
-
# # expect(response).to be_a(Chalk::Common::V1::OnlineQueryBulkResponse)
|
47
|
-
# end
|
48
|
-
|
49
16
|
it 'can perform bulk queries' do
|
50
17
|
response = client.query_bulk(
|
51
18
|
input: { 'user.id': 1 },
|
52
|
-
output: %w(user.id user.socure_score)
|
19
|
+
output: %w(user.id user.socure_score),
|
20
|
+
planner_options: {'defer_non_bus_persist_operators': "1"}, # test planner option
|
21
|
+
query_name: "planner_options_test",
|
22
|
+
|
53
23
|
)
|
54
24
|
|
55
25
|
expect(response).not_to be_nil
|
56
|
-
# The response should
|
57
|
-
|
58
|
-
|
59
|
-
|
26
|
+
# The response should have no errors and user_id of 1
|
27
|
+
expect(response[:errors]).to be_empty
|
28
|
+
expect(response[:data][0]['user.id']).to eq(1)
|
29
|
+
end
|
30
|
+
it 'can perform bulk queries without planner options' do
|
31
|
+
response = client.query_bulk(
|
32
|
+
input: { 'user.id': 1 },
|
33
|
+
output: %w(user.id user.socure_score),
|
34
|
+
query_name: "no_planner_options_test",
|
35
|
+
)
|
60
36
|
|
61
|
-
|
37
|
+
expect(response).not_to be_nil
|
38
|
+
# The response should have no errors and user_id of 1
|
39
|
+
expect(response[:errors]).to be_empty
|
40
|
+
expect(response[:data][0]['user.id']).to eq(1)
|
62
41
|
end
|
63
42
|
end
|
64
43
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chalk_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chalk AI, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -237,6 +237,7 @@ files:
|
|
237
237
|
- ".gitignore"
|
238
238
|
- ".rubocop.yml"
|
239
239
|
- ".rubocop_todo.yml"
|
240
|
+
- Dockerfile
|
240
241
|
- Gemfile
|
241
242
|
- LICENSE
|
242
243
|
- README.dev.md
|