Skip to content

Commit 454f7c5

Browse files
committed
Remove unused code
1 parent 2de2592 commit 454f7c5

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed
Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package com.sap.ai.sdk.foundationmodels.openai;
22

3-
import static com.sap.ai.sdk.foundationmodels.openai.OpenAiUtils.getOpenAiObjectMapper;
4-
5-
import com.fasterxml.jackson.core.JsonProcessingException;
63
import com.google.common.annotations.Beta;
7-
import java.util.Map;
84
import javax.annotation.Nonnull;
95
import lombok.AllArgsConstructor;
106
import lombok.Value;
@@ -26,35 +22,4 @@ public class OpenAiFunctionCall implements OpenAiToolCall {
2622

2723
/** The arguments for the function call, encoded as a JSON string. */
2824
@Nonnull String arguments;
29-
30-
/**
31-
* Parses the arguments, encoded as a JSON string, into a {@code Map<String, Object>}.
32-
*
33-
* @return a map of the arguments
34-
* @throws IllegalArgumentException if parsing fails
35-
* @since 1.7.0
36-
*/
37-
@Nonnull
38-
public Map<String, Object> getArgumentsAsMap() throws IllegalArgumentException {
39-
return getArgumentsAsObject(Map.class);
40-
}
41-
42-
/**
43-
* Parses the arguments, encoded as a JSON string, into an object of type expected by a function
44-
* tool.
45-
*
46-
* @param type the class reference for requested type.
47-
* @param <T> the type of the class
48-
* @return the parsed arguments as an object
49-
* @throws IllegalArgumentException if parsing fails
50-
* @since 1.7.0
51-
*/
52-
@Nonnull
53-
public <T> T getArgumentsAsObject(@Nonnull final Class<T> type) throws IllegalArgumentException {
54-
try {
55-
return getOpenAiObjectMapper().readValue(getArguments(), type);
56-
} catch (JsonProcessingException e) {
57-
throw new IllegalArgumentException("Failed to parse JSON string to class " + type, e);
58-
}
59-
}
6025
}

foundation-models/openai/src/main/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public interface Builder2 {
122122
}
123123

124124
@Nullable
125-
private static <T> T deserializeArgument(@Nonnull final Class<T> cl, @Nonnull final String s) {
125+
static <T> T deserializeArgument(@Nonnull final Class<T> cl, @Nonnull final String s) {
126126
try {
127127
return JACKSON.readValue(s, cl);
128128
} catch (JsonProcessingException e) {

foundation-models/openai/src/test/java/com/sap/ai/sdk/foundationmodels/openai/OpenAiToolTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.sap.ai.sdk.foundationmodels.openai;
22

3+
import static com.sap.ai.sdk.foundationmodels.openai.OpenAiTool.deserializeArgument;
34
import static org.assertj.core.api.Assertions.assertThat;
45
import static org.assertj.core.api.Assertions.assertThatThrownBy;
56

67
import java.util.Collections;
78
import java.util.List;
9+
import java.util.Map;
810
import java.util.function.Function;
911
import lombok.EqualsAndHashCode;
1012
import org.junit.jupiter.api.Test;
@@ -31,27 +33,28 @@ record Response(String toolMsg) {}
3133

3234
@Test
3335
void getArgumentsAsMapValid() {
34-
final var result = FUNCTION_CALL_A.getArgumentsAsMap();
36+
final var result = deserializeArgument(Map.class, FUNCTION_CALL_A.getArguments());
3537
assertThat(result).containsEntry("key", "value");
3638
}
3739

3840
@Test
3941
void getArgumentsAsMapInvalid() {
40-
assertThatThrownBy(INVALID_FUNCTION_CALL_A::getArgumentsAsMap)
42+
assertThatThrownBy(() -> deserializeArgument(Map.class, INVALID_FUNCTION_CALL_A.getArguments()))
4143
.isInstanceOf(IllegalArgumentException.class)
4244
.hasMessageContaining("Failed to parse JSON string");
4345
}
4446

4547
@Test
4648
void getArgumentsAsObjectValid() {
47-
final Dummy.Request result = FUNCTION_CALL_A.getArgumentsAsObject(Dummy.Request.class);
49+
final var result = deserializeArgument(Dummy.Request.class, FUNCTION_CALL_A.getArguments());
4850
assertThat(result).isInstanceOf(Dummy.Request.class);
4951
assertThat(result.key()).isEqualTo("value");
5052
}
5153

5254
@Test
5355
void getArgumentsAsObjectInvalid() {
54-
assertThatThrownBy(() -> INVALID_FUNCTION_CALL_A.getArgumentsAsObject(Integer.class))
56+
final var payload = INVALID_FUNCTION_CALL_A.getArguments();
57+
assertThatThrownBy(() -> deserializeArgument(Integer.class, payload))
5558
.isInstanceOf(IllegalArgumentException.class)
5659
.hasMessageContaining("Failed to parse JSON string");
5760
}

0 commit comments

Comments
 (0)