Skip to content

Commit d060ca4

Browse files
monikakusterivicac
authored andcommitted
1018 fix - stop mutating shared properties
1 parent c9aaa31 commit d060ca4

3 files changed

Lines changed: 190 additions & 96 deletions

File tree

server/libs/modules/components/ai/llm/open-router/src/main/java/com/bytechef/component/ai/llm/open/router/action/OpenRouterChatAction.java

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,49 @@
2121
import static com.bytechef.component.ai.llm.constant.LLMConstants.ATTACHMENTS_PROPERTY;
2222
import static com.bytechef.component.ai.llm.constant.LLMConstants.FORMAT_PROPERTY;
2323
import static com.bytechef.component.ai.llm.constant.LLMConstants.FREQUENCY_PENALTY;
24-
import static com.bytechef.component.ai.llm.constant.LLMConstants.FREQUENCY_PENALTY_PROPERTY;
2524
import static com.bytechef.component.ai.llm.constant.LLMConstants.LOGIT_BIAS;
26-
import static com.bytechef.component.ai.llm.constant.LLMConstants.LOGIT_BIAS_PROPERTY;
2725
import static com.bytechef.component.ai.llm.constant.LLMConstants.MAX_TOKENS;
28-
import static com.bytechef.component.ai.llm.constant.LLMConstants.MAX_TOKENS_PROPERTY;
2926
import static com.bytechef.component.ai.llm.constant.LLMConstants.MESSAGES_PROPERTY;
3027
import static com.bytechef.component.ai.llm.constant.LLMConstants.MODEL;
3128
import static com.bytechef.component.ai.llm.constant.LLMConstants.PRESENCE_PENALTY;
32-
import static com.bytechef.component.ai.llm.constant.LLMConstants.PRESENCE_PENALTY_PROPERTY;
3329
import static com.bytechef.component.ai.llm.constant.LLMConstants.PROMPT_PROPERTY;
3430
import static com.bytechef.component.ai.llm.constant.LLMConstants.REASONING;
35-
import static com.bytechef.component.ai.llm.constant.LLMConstants.REASONING_PROPERTY;
3631
import static com.bytechef.component.ai.llm.constant.LLMConstants.RESPONSE;
3732
import static com.bytechef.component.ai.llm.constant.LLMConstants.RESPONSE_FORMAT;
3833
import static com.bytechef.component.ai.llm.constant.LLMConstants.RESPONSE_PROPERTY;
3934
import static com.bytechef.component.ai.llm.constant.LLMConstants.SEED;
40-
import static com.bytechef.component.ai.llm.constant.LLMConstants.SEED_PROPERTY;
4135
import static com.bytechef.component.ai.llm.constant.LLMConstants.STOP;
42-
import static com.bytechef.component.ai.llm.constant.LLMConstants.STOP_PROPERTY;
4336
import static com.bytechef.component.ai.llm.constant.LLMConstants.SYSTEM_PROMPT_PROPERTY;
4437
import static com.bytechef.component.ai.llm.constant.LLMConstants.TEMPERATURE;
45-
import static com.bytechef.component.ai.llm.constant.LLMConstants.TEMPERATURE_PROPERTY;
4638
import static com.bytechef.component.ai.llm.constant.LLMConstants.TOP_K;
47-
import static com.bytechef.component.ai.llm.constant.LLMConstants.TOP_K_PROPERTY;
4839
import static com.bytechef.component.ai.llm.constant.LLMConstants.TOP_P;
49-
import static com.bytechef.component.ai.llm.constant.LLMConstants.TOP_P_PROPERTY;
5040
import static com.bytechef.component.ai.llm.constant.LLMConstants.USER;
5141
import static com.bytechef.component.ai.llm.constant.LLMConstants.USER_PROPERTY;
5242
import static com.bytechef.component.ai.llm.constant.LLMConstants.VERBOSITY;
53-
import static com.bytechef.component.ai.llm.constant.LLMConstants.VERBOSITY_PROPERTY;
5443
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.CHAT_MODEL_PROPERTY;
44+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.FREQUENCY_PENALTY_PROPERTY;
45+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.LOGIT_BIAS_PROPERTY;
5546
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.LOGPROBS;
5647
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.LOGPROBS_PROPERTY;
5748
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.MAX_COMPLETION_TOKENS;
5849
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.MAX_COMPLETION_TOKENS_PROPERTY;
59-
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.SUPPORTED_PARAMETERS;
50+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.MAX_TOKENS_PROPERTY;
51+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.PRESENCE_PENALTY_PROPERTY;
52+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.REASONING_PROPERTY;
53+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.SEED_PROPERTY;
54+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.STOP_PROPERTY;
6055
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.SUPPORTED_PARAMETERS_PROPERTY;
56+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TEMPERATURE_PROPERTY;
57+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TOP_K_PROPERTY;
6158
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TOP_LOGPROBS;
6259
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TOP_LOGPROBS_PROPERTY;
60+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TOP_P_PROPERTY;
61+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.VERBOSITY_PROPERTY;
6362
import static com.bytechef.component.definition.Authorization.TOKEN;
6463
import static com.bytechef.component.definition.ComponentDsl.action;
6564

6665
import com.bytechef.component.ai.llm.ChatModel;
66+
import com.bytechef.component.ai.llm.ChatModel.ResponseFormat;
6767
import com.bytechef.component.ai.llm.open.router.model.OpenRouterChatModel;
6868
import com.bytechef.component.ai.llm.util.ModelUtils;
6969
import com.bytechef.component.definition.ActionContext;
@@ -88,34 +88,20 @@ public class OpenRouterChatAction {
8888
ATTACHMENTS_PROPERTY,
8989
MESSAGES_PROPERTY,
9090
RESPONSE_PROPERTY,
91-
FREQUENCY_PENALTY_PROPERTY
92-
.displayCondition("contains(%s, 'frequency_penalty')".formatted(SUPPORTED_PARAMETERS)),
93-
LOGIT_BIAS_PROPERTY
94-
.displayCondition("contains(%s, 'logit_bias')".formatted(SUPPORTED_PARAMETERS)),
95-
LOGPROBS_PROPERTY
96-
.displayCondition("contains(%s, 'logprobs')".formatted(SUPPORTED_PARAMETERS)),
97-
MAX_COMPLETION_TOKENS_PROPERTY
98-
.displayCondition("contains(%s, 'max_completion_tokens')".formatted(SUPPORTED_PARAMETERS)),
99-
MAX_TOKENS_PROPERTY
100-
.displayCondition("contains(%s, 'max_tokens')".formatted(SUPPORTED_PARAMETERS)),
101-
PRESENCE_PENALTY_PROPERTY
102-
.displayCondition("contains(%s, 'presence_penalty')".formatted(SUPPORTED_PARAMETERS)),
103-
REASONING_PROPERTY
104-
.displayCondition("contains(%s, 'reasoning')".formatted(SUPPORTED_PARAMETERS)),
105-
SEED_PROPERTY
106-
.displayCondition("contains(%s, 'seed')".formatted(SUPPORTED_PARAMETERS)),
107-
STOP_PROPERTY
108-
.displayCondition("contains(%s, 'stop')".formatted(SUPPORTED_PARAMETERS)),
109-
TEMPERATURE_PROPERTY
110-
.displayCondition("contains(%s, 'temperature')".formatted(SUPPORTED_PARAMETERS)),
111-
TOP_LOGPROBS_PROPERTY
112-
.displayCondition("contains(%s, 'top_logprobs')".formatted(SUPPORTED_PARAMETERS)),
113-
TOP_K_PROPERTY
114-
.displayCondition("contains(%s, 'top_k')".formatted(SUPPORTED_PARAMETERS)),
115-
TOP_P_PROPERTY
116-
.displayCondition("contains(%s, 'top_p')".formatted(SUPPORTED_PARAMETERS)),
117-
VERBOSITY_PROPERTY
118-
.displayCondition("contains(%s, 'verbosity')".formatted(SUPPORTED_PARAMETERS)),
91+
FREQUENCY_PENALTY_PROPERTY,
92+
LOGIT_BIAS_PROPERTY,
93+
LOGPROBS_PROPERTY,
94+
MAX_COMPLETION_TOKENS_PROPERTY,
95+
MAX_TOKENS_PROPERTY,
96+
PRESENCE_PENALTY_PROPERTY,
97+
REASONING_PROPERTY,
98+
SEED_PROPERTY,
99+
STOP_PROPERTY,
100+
TEMPERATURE_PROPERTY,
101+
TOP_LOGPROBS_PROPERTY,
102+
TOP_K_PROPERTY,
103+
TOP_P_PROPERTY,
104+
VERBOSITY_PROPERTY,
119105
USER_PROPERTY)
120106
.output(ModelUtils::output)
121107
.perform(OpenRouterChatAction::perform);
@@ -124,8 +110,8 @@ public class OpenRouterChatAction {
124110
boolean jsonFormat = false;
125111

126112
if (responseFormatRequired) {
127-
ChatModel.ResponseFormat responseFormat = inputParameters.getRequiredFromPath(
128-
RESPONSE + "." + RESPONSE_FORMAT, ChatModel.ResponseFormat.class);
113+
ResponseFormat responseFormat = inputParameters.getRequiredFromPath(
114+
RESPONSE + "." + RESPONSE_FORMAT, ResponseFormat.class);
129115

130116
jsonFormat = !responseFormat.equals(TEXT);
131117
}

server/libs/modules/components/ai/llm/open-router/src/main/java/com/bytechef/component/ai/llm/open/router/cluster/OpenRouterChatModel.java

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,24 @@
1616

1717
package com.bytechef.component.ai.llm.open.router.cluster;
1818

19-
import static com.bytechef.component.ai.llm.constant.LLMConstants.FREQUENCY_PENALTY_PROPERTY;
20-
import static com.bytechef.component.ai.llm.constant.LLMConstants.LOGIT_BIAS_PROPERTY;
21-
import static com.bytechef.component.ai.llm.constant.LLMConstants.MAX_TOKENS_PROPERTY;
22-
import static com.bytechef.component.ai.llm.constant.LLMConstants.PRESENCE_PENALTY_PROPERTY;
23-
import static com.bytechef.component.ai.llm.constant.LLMConstants.REASONING_PROPERTY;
24-
import static com.bytechef.component.ai.llm.constant.LLMConstants.SEED_PROPERTY;
25-
import static com.bytechef.component.ai.llm.constant.LLMConstants.STOP_PROPERTY;
26-
import static com.bytechef.component.ai.llm.constant.LLMConstants.TEMPERATURE_PROPERTY;
27-
import static com.bytechef.component.ai.llm.constant.LLMConstants.TOP_K_PROPERTY;
28-
import static com.bytechef.component.ai.llm.constant.LLMConstants.TOP_P_PROPERTY;
2919
import static com.bytechef.component.ai.llm.constant.LLMConstants.USER_PROPERTY;
30-
import static com.bytechef.component.ai.llm.constant.LLMConstants.VERBOSITY_PROPERTY;
3120
import static com.bytechef.component.ai.llm.open.router.action.OpenRouterChatAction.CHAT_MODEL;
3221
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.CHAT_MODEL_PROPERTY;
22+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.FREQUENCY_PENALTY_PROPERTY;
23+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.LOGIT_BIAS_PROPERTY;
3324
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.LOGPROBS_PROPERTY;
3425
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.MAX_COMPLETION_TOKENS_PROPERTY;
35-
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.SUPPORTED_PARAMETERS;
26+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.MAX_TOKENS_PROPERTY;
27+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.PRESENCE_PENALTY_PROPERTY;
28+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.REASONING_PROPERTY;
29+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.SEED_PROPERTY;
30+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.STOP_PROPERTY;
3631
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.SUPPORTED_PARAMETERS_PROPERTY;
32+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TEMPERATURE_PROPERTY;
33+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TOP_K_PROPERTY;
3734
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TOP_LOGPROBS_PROPERTY;
35+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.TOP_P_PROPERTY;
36+
import static com.bytechef.component.ai.llm.open.router.constant.OpenRouterConstants.VERBOSITY_PROPERTY;
3837

3938
import com.bytechef.component.definition.ClusterElementDefinition;
4039
import com.bytechef.component.definition.ComponentDsl;
@@ -56,34 +55,20 @@ public class OpenRouterChatModel {
5655
.properties(
5756
SUPPORTED_PARAMETERS_PROPERTY,
5857
CHAT_MODEL_PROPERTY,
59-
FREQUENCY_PENALTY_PROPERTY
60-
.displayCondition("contains(%s, 'frequency_penalty')".formatted(SUPPORTED_PARAMETERS)),
61-
LOGIT_BIAS_PROPERTY
62-
.displayCondition("contains(%s, 'logit_bias')".formatted(SUPPORTED_PARAMETERS)),
63-
LOGPROBS_PROPERTY
64-
.displayCondition("contains(%s, 'logprobs')".formatted(SUPPORTED_PARAMETERS)),
65-
MAX_COMPLETION_TOKENS_PROPERTY
66-
.displayCondition("contains(%s, 'max_completion_tokens')".formatted(SUPPORTED_PARAMETERS)),
67-
MAX_TOKENS_PROPERTY
68-
.displayCondition("contains(%s, 'max_tokens')".formatted(SUPPORTED_PARAMETERS)),
69-
PRESENCE_PENALTY_PROPERTY
70-
.displayCondition("contains(%s, 'presence_penalty')".formatted(SUPPORTED_PARAMETERS)),
71-
REASONING_PROPERTY
72-
.displayCondition("contains(%s, 'reasoning')".formatted(SUPPORTED_PARAMETERS)),
73-
SEED_PROPERTY
74-
.displayCondition("contains(%s, 'seed')".formatted(SUPPORTED_PARAMETERS)),
75-
STOP_PROPERTY
76-
.displayCondition("contains(%s, 'stop')".formatted(SUPPORTED_PARAMETERS)),
77-
TEMPERATURE_PROPERTY
78-
.displayCondition("contains(%s, 'temperature')".formatted(SUPPORTED_PARAMETERS)),
79-
TOP_LOGPROBS_PROPERTY
80-
.displayCondition("contains(%s, 'top_logprobs')".formatted(SUPPORTED_PARAMETERS)),
81-
TOP_K_PROPERTY
82-
.displayCondition("contains(%s, 'top_k')".formatted(SUPPORTED_PARAMETERS)),
83-
TOP_P_PROPERTY
84-
.displayCondition("contains(%s, 'top_p')".formatted(SUPPORTED_PARAMETERS)),
85-
VERBOSITY_PROPERTY
86-
.displayCondition("contains(%s, 'verbosity')".formatted(SUPPORTED_PARAMETERS)),
58+
FREQUENCY_PENALTY_PROPERTY,
59+
LOGIT_BIAS_PROPERTY,
60+
LOGPROBS_PROPERTY,
61+
MAX_COMPLETION_TOKENS_PROPERTY,
62+
MAX_TOKENS_PROPERTY,
63+
PRESENCE_PENALTY_PROPERTY,
64+
REASONING_PROPERTY,
65+
SEED_PROPERTY,
66+
STOP_PROPERTY,
67+
TEMPERATURE_PROPERTY,
68+
TOP_LOGPROBS_PROPERTY,
69+
TOP_K_PROPERTY,
70+
TOP_P_PROPERTY,
71+
VERBOSITY_PROPERTY,
8772
USER_PROPERTY);
8873

8974
protected static ChatModel apply(

0 commit comments

Comments
 (0)