Skip to content

Commit fe3fdf8

Browse files
authored
fix!: Return disabled config if no defaultValue is provided (#23)
feat!: Use kwargs for completion_config and config methods feat: Drop support for Ruby 3.0 which is EOL.
1 parent c2a9230 commit fe3fdf8

14 files changed

Lines changed: 109 additions & 87 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
strategy:
1717
matrix:
1818
ruby-version:
19-
- '3.0'
2019
- '3.1'
2120
- '3.2'
21+
- '3.4'
2222
- jruby-9.4
2323

2424
steps:
@@ -43,7 +43,7 @@ jobs:
4343

4444
- uses: ruby/setup-ruby@v1
4545
with:
46-
ruby-version: 3.0
46+
ruby-version: 3.2
4747

4848
- name: Install dependencies
4949
run: bundle install

.github/workflows/manual-publish-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- uses: ruby/setup-ruby@v1
1515
with:
16-
ruby-version: 3.0
16+
ruby-version: 3.1
1717

1818
- uses: ./.github/actions/build-docs
1919

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
name: Build and Test
4141
uses: ./.github/actions/ci
4242
with:
43-
ruby-version: 3.0
43+
ruby-version: 3.1
4444

4545
- id: build-docs
4646
name: Build docs

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins:
44
- rubocop-rspec
55

66
AllCops:
7-
TargetRubyVersion: 3.0
7+
TargetRubyVersion: 3.1
88
Include:
99
- lib/**/*.rb
1010
- spec/**/*.rb

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LaunchDarkly overview
2727
Supported Ruby versions
2828
-----------------------
2929

30-
This version of the library has a minimum Ruby version of 3.0.0, or 9.4.0 for JRuby.
30+
This version of the library has a minimum Ruby version of 3.1.0, or 9.4.0 for JRuby.
3131

3232
Getting started
3333
-----------

examples/chatbot/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ We've built a simple console application that demonstrates how LaunchDarkly's Ru
44

55
Below, you'll find the build procedure. For more comprehensive instructions, you can visit your [Quickstart page](https://docs.launchdarkly.com/home/ai-configs/quickstart) or the [Ruby reference guide](https://docs.launchdarkly.com/sdk/ai/ruby).
66

7-
This demo requires Ruby 3.0 or higher.
7+
This demo requires Ruby 3.1 or higher.
88

99
## Build Instructions
1010

examples/chatbot/aws-bedrock/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
ruby '>= 3.0.0'
5+
ruby '>= 3.1.0'
66

77
gem 'aws-sdk-bedrockruntime', '~> 1.0'
88
gem 'launchdarkly-server-sdk-ai', path: '../../..'

examples/chatbot/aws-bedrock/hello_bedrock.rb

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Set sdk_key to your LaunchDarkly SDK key.
88
sdk_key = ENV['LAUNCHDARKLY_SDK_KEY']
99

10-
# Set config_key to the AI Config key you want to evaluate.
10+
# Set key to the AI Config key you want to evaluate.
1111
ai_config_key = ENV['LAUNCHDARKLY_AI_CONFIG_KEY'] || 'sample-ai-config'
1212

1313
region = ENV['AWS_REGION'] || 'us-east-1'
@@ -87,26 +87,16 @@ def map_converse_arguments(model_id, messages)
8787
region: region
8888
)
8989

90-
91-
DEFAULT_VALUE = LaunchDarkly::Server::AI::AIConfig.new(
92-
enabled: true,
93-
model: LaunchDarkly::Server::AI::ModelConfig.new(name: 'replace-with-your-model'),
94-
messages: [
95-
LaunchDarkly::Server::AI::Message.new('system',
96-
'You are the backup assistant when something prevents retrieving LaunchDarkly configured assistant. You have the persona of HAL 9000 talking with {{ldctx.name}}'),
97-
]
98-
)
99-
100-
# You can also default to disabled if you are unable to connect to LaunchDarkly services.
101-
# DEFAULT_VALUE = LaunchDarkly::Server::AI::AIConfig.new(
102-
# enabled: false
103-
# )
104-
105-
ai_config = ai_client.completion_config(
106-
ai_config_key,
107-
context,
108-
DEFAULT_VALUE
109-
)
90+
# Pass a default for improved resiliency when the flag is unavailable or LaunchDarkly is unreachable; omit for a disabled default.
91+
# Example:
92+
# default = LaunchDarkly::Server::AI::AIConfig.new(
93+
# enabled: true,
94+
# model: LaunchDarkly::Server::AI::ModelConfig.new(name: 'my-model'),
95+
# provider: LaunchDarkly::Server::AI::ProviderConfig.new(name: 'my-provider'),
96+
# messages: [LaunchDarkly::Server::AI::Message.new('system', 'Fallback system prompt')]
97+
# )
98+
# ai_config = ai_client.completion_config(key: ai_config_key, context:, default:)
99+
ai_config = ai_client.completion_config(key: ai_config_key, context:)
110100

111101
unless ai_config.enabled
112102
puts '*** AI features are disabled'

examples/chatbot/openai/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source 'https://rubygems.org'
44

5-
ruby '>= 3.0.0'
5+
ruby '>= 3.1.0'
66

77
gem 'launchdarkly-server-sdk-ai', path: '../../..'
88
gem 'openai', '~> 0.7.0'

examples/chatbot/openai/hello_openai.rb

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Set sdk_key to your LaunchDarkly SDK key.
88
sdk_key = ENV['LAUNCHDARKLY_SDK_KEY']
99

10-
# Set config_key to the AI Config key you want to evaluate.
10+
# Set key to the AI Config key you want to evaluate.
1111
ai_config_key = ENV['LAUNCHDARKLY_AI_CONFIG_KEY'] || 'sample-ai-config'
1212

1313
# Set openai_api_key to your OpenAI API key.
@@ -58,19 +58,6 @@ def agent_was_helpful(helpful)
5858
end
5959
end
6060

61-
DEFAULT_VALUE = LaunchDarkly::Server::AI::AIConfig.new(
62-
enabled: true,
63-
model: LaunchDarkly::Server::AI::ModelConfig.new(name: 'replace-with-your-model'),
64-
messages: [
65-
LaunchDarkly::Server::AI::Message.new('system',
66-
'You are the backup assistant when something prevents retrieving LaunchDarkly configured assistant. You have the persona of HAL 9000 talking with {{ldctx.name}}'),
67-
]
68-
)
69-
70-
# You can also default to disabled if you are unable to connect to LaunchDarkly services.
71-
# DEFAULT_VALUE = LaunchDarkly::Server::AI::AIConfig.new(
72-
# enabled: false
73-
# )
7461

7562
ld_client = LaunchDarkly::LDClient.new(sdk_key)
7663
ai_client = LaunchDarkly::Server::AI::Client.new(ld_client)
@@ -89,11 +76,16 @@ def agent_was_helpful(helpful)
8976
name: 'Lucy',
9077
})
9178

92-
ai_config = ai_client.completion_config(
93-
ai_config_key,
94-
context,
95-
DEFAULT_VALUE
96-
)
79+
# Pass a default for improved resiliency when the flag is unavailable or LaunchDarkly is unreachable; omit for a disabled default.
80+
# Example:
81+
# default = LaunchDarkly::Server::AI::AIConfig.new(
82+
# enabled: true,
83+
# model: LaunchDarkly::Server::AI::ModelConfig.new(name: 'my-model'),
84+
# provider: LaunchDarkly::Server::AI::ProviderConfig.new(name: 'my-provider'),
85+
# messages: [LaunchDarkly::Server::AI::Message.new('system', 'Fallback system prompt')]
86+
# )
87+
# ai_config = ai_client.completion_config(key: ai_config_key, context:, default:)
88+
ai_config = ai_client.completion_config(key: ai_config_key, context:)
9789

9890
unless ai_config.enabled
9991
puts '*** AI features are disabled'

0 commit comments

Comments
 (0)