Skip to content

Commit 7778b95

Browse files
deps: updates openai to latest and adjusts example (#514)
Signed-off-by: Adrian Cole <[email protected]>
1 parent fef0621 commit 7778b95

File tree

7 files changed

+9
-21
lines changed

7 files changed

+9
-21
lines changed

examples/openai/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repositories {
1414

1515
dependencies {
1616
implementation(platform("org.slf4j:slf4j-bom:2.0.16"))
17-
implementation("com.openai:openai-java:0.11.8")
17+
implementation("com.openai:openai-java:0.13.0")
1818
implementation("org.slf4j:slf4j-simple")
1919
}
2020

examples/openai/src/main/java/openai/example/Chat.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ public static void main(String[] args) {
1414

1515
String message = "Answer in up to 3 words: Which ocean contains Bouvet Island?";
1616
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
17-
.addMessage(ChatCompletionMessageParam.ofChatCompletionUserMessageParam(ChatCompletionUserMessageParam.builder()
18-
.role(ChatCompletionUserMessageParam.Role.USER)
19-
.content(ChatCompletionUserMessageParam.Content.ofTextContent(message))
20-
.build()))
17+
.addMessage(ChatCompletionUserMessageParam.builder()
18+
.content(message)
19+
.build())
2120
.model(chatModel)
2221
.build();
2322

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ opentelemetryContribAlpha = "1.42.0-alpha"
2323
opentelemetrySemconvAlpha = "1.29.0-alpha"
2424

2525
# instrumented libraries
26-
openaiClient = "0.11.9"
26+
openaiClient = "0.13.0"
2727

2828
[libraries]
2929

instrumentation/openai-client-instrumentation/src/main/java/co/elastic/otel/openai/wrappers/ChatCompletionEventsHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private static LogRecordBuilder newEvent(String name) {
227227
private static Value<?> buildToolCallEventObject(ChatCompletionMessageToolCall call) {
228228
Map<String, Value<?>> result = new HashMap<>();
229229
result.put("id", Value.of(call.id()));
230-
result.put("type", Value.of(call.type().toString()));
230+
result.put("type", Value.of(call._type().toString()));
231231
result.put("function", buildFunctionEventObject(call.function()));
232232
return Value.of(result);
233233
}

instrumentation/openai-client-instrumentation/src/main/java/co/elastic/otel/openai/wrappers/InstrumentedChatCompletionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void onStart(
140140
if (val.isResponseFormatText()) {
141141
attributes.put(
142142
GEN_AI_OPENAI_REQUEST_RESPONSE_FORMAT,
143-
val.asResponseFormatText().type().toString());
143+
val.asResponseFormatText()._type().toString());
144144
}
145145
});
146146
}

instrumentation/openai-client-instrumentation/src/test/java/co/elastic/otel/openai/ChatTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void allTheClientOptions() {
255255
.topP(1.0)
256256
.stopOfStrings(Collections.singletonList("foo"))
257257
.seed(100L)
258-
.responseFormat(ResponseFormatText.builder().type(ResponseFormatText.Type.TEXT).build())
258+
.responseFormat(ResponseFormatText.builder().build())
259259
.build();
260260

261261
long startTimeNanos = System.nanoTime();
@@ -1374,7 +1374,7 @@ void streamAllTheClientOptions() throws Exception {
13741374
.topP(1.0)
13751375
.stopOfStrings(Collections.singletonList("foo"))
13761376
.seed(100L)
1377-
.responseFormat(ResponseFormatText.builder().type(ResponseFormatText.Type.TEXT).build())
1377+
.responseFormat(ResponseFormatText.builder().build())
13781378
.build();
13791379

13801380
long startTimeNanos = System.nanoTime();
@@ -2048,7 +2048,6 @@ void toolsWithFollowupAndCaptureContent() {
20482048
ChatCompletionMessageParam assistantMessage =
20492049
ChatCompletionMessageParam.ofChatCompletionAssistantMessageParam(
20502050
ChatCompletionAssistantMessageParam.builder()
2051-
.role(ChatCompletionAssistantMessageParam.Role.ASSISTANT)
20522051
.content(ChatCompletionAssistantMessageParam.Content.ofTextContent(""))
20532052
.toolCalls(toolCalls)
20542053
.build());
@@ -2301,7 +2300,6 @@ private static ChatCompletionTool buildGetWeatherToolDefinition() {
23012300
properties.put("location", JsonObject.of(location));
23022301

23032302
return ChatCompletionTool.builder()
2304-
.type(ChatCompletionTool.Type.FUNCTION)
23052303
.function(
23062304
FunctionDefinition.builder()
23072305
.name("get_weather")
@@ -2326,7 +2324,6 @@ static ChatCompletionTool buildGetDeliveryDateToolDefinition() {
23262324
properties.put("order_id", JsonObject.of(orderId));
23272325

23282326
return ChatCompletionTool.builder()
2329-
.type(ChatCompletionTool.Type.FUNCTION)
23302327
.function(
23312328
FunctionDefinition.builder()
23322329
.name("get_delivery_date")
@@ -2349,31 +2346,27 @@ static ChatCompletionTool buildGetDeliveryDateToolDefinition() {
23492346
private static ChatCompletionMessageParam createAssistantMessage(String content) {
23502347
return ChatCompletionMessageParam.ofChatCompletionAssistantMessageParam(
23512348
ChatCompletionAssistantMessageParam.builder()
2352-
.role(ChatCompletionAssistantMessageParam.Role.ASSISTANT)
23532349
.content(ChatCompletionAssistantMessageParam.Content.ofTextContent(content))
23542350
.build());
23552351
}
23562352

23572353
private static ChatCompletionMessageParam createUserMessage(String content) {
23582354
return ChatCompletionMessageParam.ofChatCompletionUserMessageParam(
23592355
ChatCompletionUserMessageParam.builder()
2360-
.role(ChatCompletionUserMessageParam.Role.USER)
23612356
.content(ChatCompletionUserMessageParam.Content.ofTextContent(content))
23622357
.build());
23632358
}
23642359

23652360
private static ChatCompletionMessageParam createSystemMessage(String content) {
23662361
return ChatCompletionMessageParam.ofChatCompletionSystemMessageParam(
23672362
ChatCompletionSystemMessageParam.builder()
2368-
.role(ChatCompletionSystemMessageParam.Role.SYSTEM)
23692363
.content(ChatCompletionSystemMessageParam.Content.ofTextContent(content))
23702364
.build());
23712365
}
23722366

23732367
private static ChatCompletionMessageParam createToolMessage(String response, String id) {
23742368
return ChatCompletionMessageParam.ofChatCompletionToolMessageParam(
23752369
ChatCompletionToolMessageParam.builder()
2376-
.role(ChatCompletionToolMessageParam.Role.TOOL)
23772370
.toolCallId(id)
23782371
.content(ChatCompletionToolMessageParam.Content.ofTextContent(response))
23792372
.build());

instrumentation/openai-client-instrumentation/src/test/java/co/elastic/otel/openai/LiveAPIChatIntegrationTest.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,31 +578,27 @@ void streamWithCaptureMessageContent() throws Exception {
578578
private static ChatCompletionMessageParam createAssistantMessage(String content) {
579579
return ChatCompletionMessageParam.ofChatCompletionAssistantMessageParam(
580580
ChatCompletionAssistantMessageParam.builder()
581-
.role(ChatCompletionAssistantMessageParam.Role.ASSISTANT)
582581
.content(ChatCompletionAssistantMessageParam.Content.ofTextContent(content))
583582
.build());
584583
}
585584

586585
private static ChatCompletionMessageParam createUserMessage(String content) {
587586
return ChatCompletionMessageParam.ofChatCompletionUserMessageParam(
588587
ChatCompletionUserMessageParam.builder()
589-
.role(ChatCompletionUserMessageParam.Role.USER)
590588
.content(ChatCompletionUserMessageParam.Content.ofTextContent(content))
591589
.build());
592590
}
593591

594592
private static ChatCompletionMessageParam createSystemMessage(String content) {
595593
return ChatCompletionMessageParam.ofChatCompletionSystemMessageParam(
596594
ChatCompletionSystemMessageParam.builder()
597-
.role(ChatCompletionSystemMessageParam.Role.SYSTEM)
598595
.content(ChatCompletionSystemMessageParam.Content.ofTextContent(content))
599596
.build());
600597
}
601598

602599
private static ChatCompletionMessageParam createToolMessage(String response, String id) {
603600
return ChatCompletionMessageParam.ofChatCompletionToolMessageParam(
604601
ChatCompletionToolMessageParam.builder()
605-
.role(ChatCompletionToolMessageParam.Role.TOOL)
606602
.toolCallId(id)
607603
.content(ChatCompletionToolMessageParam.Content.ofTextContent(response))
608604
.build());

0 commit comments

Comments
 (0)