Skip to content

Commit d3a104f

Browse files
authored
Add support for openAI client 1.1+, drop support for older versions (#607)
1 parent 78da2bb commit d3a104f

File tree

47 files changed

+390
-1190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+390
-1190
lines changed

CHANGELOG.next-release.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
* Switched the default of `otel.exporter.otlp.metrics.temporality.preference` from `CUMULATIVE` to `DELTA` to improve dashboarding experience with Kibana. If you want to restore the previous behaviour, you can manually override `otel.exporter.otlp.metrics.temporality.preference` to `CUMULATIVE` via JVM-properties or environment variables. - #583
2-
* Set elastic-specific User-Agent header for OTLP exporters - #593
3-
* Enable Azure resource provider by default with `otel.resource.providers.azure.enabled` = `true`.
2+
* Set elastic-specific User-Agent header for OTLP exporters - #593
3+
* Add support for openAI client 1.1+, drop support for older versions - #607
4+
* Enable Azure resource provider by default with `otel.resource.providers.azure.enabled` = `true`. - #596

custom/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ plugins {
33
}
44

55
val instrumentations = listOf<String>(
6-
":instrumentation:openai-client-instrumentation:instrumentation-0.8",
7-
":instrumentation:openai-client-instrumentation:instrumentation-0.14"
6+
":instrumentation:openai-client-instrumentation:instrumentation-1.1"
87
)
98

109
dependencies {

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.13.0")
17+
implementation("com.openai:openai-java:1.2.0")
1818
implementation("org.slf4j:slf4j-simple")
1919
}
2020

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,27 @@
22

33
import com.openai.client.OpenAIClient;
44
import com.openai.client.okhttp.OpenAIOkHttpClient;
5-
import com.openai.models.*;
5+
import com.openai.models.chat.completions.ChatCompletion;
6+
import com.openai.models.chat.completions.ChatCompletionCreateParams;
7+
import com.openai.models.chat.completions.ChatCompletionUserMessageParam;
68

79

810
final class Chat {
911

10-
public static void main(String[] args) {
11-
String chatModel = System.getenv().getOrDefault("CHAT_MODEL", "gpt-4o-mini");
12+
public static void main(String[] args) {
13+
String chatModel = System.getenv().getOrDefault("CHAT_MODEL", "gpt-4o-mini");
1214

13-
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
15+
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
1416

15-
String message = "Answer in up to 3 words: Which ocean contains Bouvet Island?";
16-
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
17-
.addMessage(ChatCompletionUserMessageParam.builder()
18-
.content(message)
19-
.build())
20-
.model(chatModel)
21-
.build();
17+
String message = "Answer in up to 3 words: Which ocean contains Bouvet Island?";
18+
ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
19+
.addMessage(ChatCompletionUserMessageParam.builder()
20+
.content(message)
21+
.build())
22+
.model(chatModel)
23+
.build();
2224

23-
ChatCompletion chatCompletion = client.chat().completions().create(params);
24-
System.out.println(chatCompletion.choices().get(0).message().content().get());
25-
}
25+
ChatCompletion chatCompletion = client.chat().completions().create(params);
26+
System.out.println(chatCompletion.choices().get(0).message().content().get());
27+
}
2628
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import com.openai.client.OpenAIClient;
66
import com.openai.client.okhttp.OpenAIOkHttpClient;
7-
import com.openai.models.*;
7+
import com.openai.models.embeddings.Embedding;
8+
import com.openai.models.embeddings.EmbeddingCreateParams;
89

910
final class Embeddings {
1011

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ ant = "org.apache.ant:ant:1.10.15"
7777
asm = "org.ow2.asm:asm:9.8"
7878

7979
# Instrumented libraries
80-
openaiClient = "com.openai:openai-java:0.33.0"
80+
openaiClient = "com.openai:openai-java:1.2.0"
8181

8282
[bundles]
8383

instrumentation/openai-client-instrumentation/common/build.gradle.kts

Lines changed: 0 additions & 10 deletions
This file was deleted.

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

Lines changed: 0 additions & 105 deletions
This file was deleted.

instrumentation/openai-client-instrumentation/instrumentation-0.14/src/main/java/co/elastic/otel/openai/v0_14/ApiAdapterImpl.java

Lines changed: 0 additions & 113 deletions
This file was deleted.

instrumentation/openai-client-instrumentation/instrumentation-0.14/src/main/java/co/elastic/otel/openai/v0_14/OpenAiClientInstrumentationModule.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)