Skip to content

Commit 5298fad

Browse files
chore: update formatting
1 parent ba1597a commit 5298fad

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
lines changed

lib/sdk/server-ai/src/main/java/com/launchdarkly/sdk/server/ai/LDAiClient.java

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.launchdarkly.sdk.server.ai;
22

3-
import static java.util.Arrays.binarySearch;
4-
53
import java.util.ArrayList;
64
import java.util.HashMap;
75
import java.util.List;
@@ -16,7 +14,6 @@
1614
import com.launchdarkly.sdk.server.ai.datamodel.Meta;
1715
import com.launchdarkly.sdk.server.ai.datamodel.Model;
1816
import com.launchdarkly.sdk.server.ai.datamodel.Provider;
19-
import com.launchdarkly.sdk.server.ai.datamodel.Role;
2017
import com.launchdarkly.sdk.server.ai.interfaces.LDAiClientInterface;
2118

2219
/**
@@ -46,11 +43,13 @@ public LDAiClient(LDClientInterface client) {
4643
/**
4744
* Method to convert the JSON variable into the AiConfig object
4845
*
49-
* If the parsing failed, the code will log an error and
46+
* If the parsing failed, the code will log an error and
5047
* return a well formed but with nullable value nulled and disabled AIConfig
5148
*
52-
* Doing all the error checks, so if somehow LD backend return incorrect value types, there is logging
53-
* This also opens up the possibility of allowing customer to build this using a JSON string in the future
49+
* Doing all the error checks, so if somehow LD backend return incorrect value
50+
* types, there is logging
51+
* This also opens up the possibility of allowing customer to build this using a
52+
* JSON string in the future
5453
*
5554
* @param value
5655
* @param key
@@ -59,53 +58,60 @@ protected AiConfig parseAiConfig(LDValue value, String key) {
5958
boolean enabled = false;
6059

6160
// Verify the whole value is a JSON object
62-
if(!checkValueWithFailureLogging(value, LDValueType.OBJECT, logger, "Input to parseAiConfig must be a JSON object")) {
61+
if (!checkValueWithFailureLogging(value, LDValueType.OBJECT, logger,
62+
"Input to parseAiConfig must be a JSON object")) {
6363
return new AiConfig(enabled, null, null, null, null);
6464
}
6565

6666
// Convert the _meta JSON object into Meta
6767
LDValue valueMeta = value.get("_ldMeta");
6868
if (!checkValueWithFailureLogging(valueMeta, LDValueType.OBJECT, logger, "_ldMeta must be a JSON object")) {
69-
// Q: If we can't read _meta, enabled by spec would be defaulted to false. Does it even matter the rest of the values?
69+
// Q: If we can't read _meta, enabled by spec would be defaulted to false. Does
70+
// it even matter the rest of the values?
7071
return new AiConfig(enabled, null, null, null, null);
7172
}
7273

73-
// The booleanValue will get false if that value something that we are not expecting, which is good
74+
// The booleanValue will get false if that value something that we are not
75+
// expecting, which is good
7476
enabled = valueMeta.get("enabled").booleanValue();
7577

7678
String variationKey = null;
77-
if (checkValueWithFailureLogging(valueMeta.get("variationKey"), LDValueType.STRING, logger, "variationKey should be a string")) {
79+
if (checkValueWithFailureLogging(valueMeta.get("variationKey"), LDValueType.STRING, logger,
80+
"variationKey should be a string")) {
7881
variationKey = valueMeta.get("variationKey").stringValue();
7982
}
8083
// Create Meta using constructor
8184
Meta meta = new Meta(
82-
variationKey,
83-
Optional.of(valueMeta.get("version").intValue())
84-
);
85+
variationKey,
86+
Optional.of(valueMeta.get("version").intValue()));
8587

8688
// Convert the optional model from an JSON object of with parameters and custom
8789
// into Model
8890
Model model = null;
8991

9092
LDValue valueModel = value.get("model");
91-
if (checkValueWithFailureLogging(valueModel, LDValueType.OBJECT, logger, "model if exists must be a JSON object")) {
92-
if (checkValueWithFailureLogging(valueModel.get("name"), LDValueType.STRING, logger, "model name must be a string and is required")) {
93+
if (checkValueWithFailureLogging(valueModel, LDValueType.OBJECT, logger,
94+
"model if exists must be a JSON object")) {
95+
if (checkValueWithFailureLogging(valueModel.get("name"), LDValueType.STRING, logger,
96+
"model name must be a string and is required")) {
9397
String modelName = valueModel.get("name").stringValue();
9498

9599
// Prepare parameters and custom maps for Model
96100
HashMap<String, LDValue> parameters = null;
97101
HashMap<String, LDValue> custom = null;
98102

99103
LDValue valueParameters = valueModel.get("parameters");
100-
if (checkValueWithFailureLogging(valueParameters, LDValueType.OBJECT, logger, "non-null parameters must be a JSON object")) {
104+
if (checkValueWithFailureLogging(valueParameters, LDValueType.OBJECT, logger,
105+
"non-null parameters must be a JSON object")) {
101106
parameters = new HashMap<>();
102107
for (String k : valueParameters.keys()) {
103108
parameters.put(k, valueParameters.get(k));
104109
}
105110
}
106-
111+
107112
LDValue valueCustom = valueModel.get("custom");
108-
if (checkValueWithFailureLogging(valueCustom, LDValueType.OBJECT, logger, "non-null custom must be a JSON object")) {
113+
if (checkValueWithFailureLogging(valueCustom, LDValueType.OBJECT, logger,
114+
"non-null custom must be a JSON object")) {
109115

110116
custom = new HashMap<>();
111117
for (String k : valueCustom.keys()) {
@@ -122,7 +128,8 @@ protected AiConfig parseAiConfig(LDValue value, String key) {
122128
List<Message> messages = null;
123129

124130
LDValue valueMessages = value.get("messages");
125-
if (checkValueWithFailureLogging(valueMessages, LDValueType.ARRAY, logger, "messages if exists must be a JSON array")) {
131+
if (checkValueWithFailureLogging(valueMessages, LDValueType.ARRAY, logger,
132+
"messages if exists must be a JSON array")) {
126133
messages = new ArrayList<Message>();
127134
valueMessages.valuesAs(new Message.MessageConverter());
128135
for (Message message : valueMessages.valuesAs(new Message.MessageConverter())) {
@@ -134,8 +141,10 @@ protected AiConfig parseAiConfig(LDValue value, String key) {
134141
LDValue valueProvider = value.get("provider");
135142
String providerName = null;
136143

137-
if(checkValueWithFailureLogging(valueProvider, LDValueType.OBJECT, logger, "non-null provider must be a JSON object")) {
138-
if(checkValueWithFailureLogging(valueProvider.get("name"), LDValueType.STRING, logger, "provider name must be a String")) {
144+
if (checkValueWithFailureLogging(valueProvider, LDValueType.OBJECT, logger,
145+
"non-null provider must be a JSON object")) {
146+
if (checkValueWithFailureLogging(valueProvider.get("name"), LDValueType.STRING, logger,
147+
"provider name must be a String")) {
139148
providerName = valueProvider.get("name").stringValue();
140149
}
141150
}
@@ -145,7 +154,8 @@ protected AiConfig parseAiConfig(LDValue value, String key) {
145154
return new AiConfig(enabled, meta, model, messages, provider);
146155
}
147156

148-
protected boolean checkValueWithFailureLogging(LDValue ldValue, LDValueType expectedType, LDLogger logger, String message) {
157+
protected boolean checkValueWithFailureLogging(LDValue ldValue, LDValueType expectedType, LDLogger logger,
158+
String message) {
149159
if (ldValue.getType() != expectedType) {
150160
if (logger != null) {
151161
logger.error(message);

lib/sdk/server-ai/src/main/java/com/launchdarkly/sdk/server/ai/datamodel/AiConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ public final class AiConfig {
66
private final boolean enabled;
77

88
private final Meta meta;
9-
9+
1010
private final Model model;
11-
11+
1212
private final List<Message> messages;
1313

1414
private final Provider provider;

lib/sdk/server-ai/src/main/java/com/launchdarkly/sdk/server/ai/datamodel/Meta.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@ public final class Meta {
1313
*/
1414
private final Optional<Integer> version;
1515

16-
/**
17-
* If the config is enabled.
18-
*/
19-
// private final boolean enabled;
16+
// The enable paramter is taken outside of the Meta to be a top level value of
17+
// AiConfig
2018

2119
/**
2220
* Constructor for Meta with all required fields.
2321
*
2422
* @param variationKey the variation key
25-
* @param version the version
23+
* @param version the version
2624
*/
2725
public Meta(String variationKey, Optional<Integer> version) {
2826
this.variationKey = variationKey;
2927
this.version = version != null ? version : Optional.empty();
30-
// this.enabled = enabled;
3128
}
3229

3330
public String getVariationKey() {
@@ -37,8 +34,4 @@ public String getVariationKey() {
3734
public Optional<Integer> getVersion() {
3835
return version;
3936
}
40-
41-
// public boolean isEnabled() {
42-
// return enabled;
43-
// }
4437
}

lib/sdk/server-ai/src/main/java/com/launchdarkly/sdk/server/ai/datamodel/Model.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ public final class Model {
1616
/**
1717
* Constructor for Model with all required fields.
1818
*
19-
* @param name the model name
19+
* @param name the model name
2020
* @param parameters the parameters map
21-
* @param custom the custom map
21+
* @param custom the custom map
2222
*/
2323
public Model(String name, Map<String, LDValue> parameters, Map<String, LDValue> custom) {
2424
this.name = name;
25-
this.parameters = parameters != null ? Collections.unmodifiableMap(new HashMap<>(parameters)) : Collections.emptyMap();
25+
this.parameters = parameters != null ? Collections.unmodifiableMap(new HashMap<>(parameters))
26+
: Collections.emptyMap();
2627
this.custom = custom != null ? Collections.unmodifiableMap(new HashMap<>(custom)) : Collections.emptyMap();
2728
}
2829

0 commit comments

Comments
 (0)