Skip to content

Commit 9690b0a

Browse files
committed
./gradlew spotlessApply
1 parent 09d342b commit 9690b0a

File tree

12 files changed

+134
-81
lines changed

12 files changed

+134
-81
lines changed

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/GenericPart.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.annotation.JsonClassDescription;
@@ -7,8 +12,8 @@
712
import java.util.Map;
813

914
/**
10-
* Represents an arbitrary message part with any type and properties.
11-
* This allows for extensibility with custom message part types.
15+
* Represents an arbitrary message part with any type and properties. This allows for extensibility
16+
* with custom message part types.
1217
*/
1318
@AutoValue
1419
@JsonClassDescription("Generic part")

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/InputMessage.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.annotation.JsonClassDescription;
@@ -6,9 +11,7 @@
611
import com.google.auto.value.AutoValue;
712
import java.util.List;
813

9-
/**
10-
* Represents an input message sent to the model.
11-
*/
14+
/** Represents an input message sent to the model. */
1215
@AutoValue
1316
@JsonClassDescription("Input message")
1417
public abstract class InputMessage {

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/InputMessages.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -6,9 +11,7 @@
611
import java.util.ArrayList;
712
import java.util.List;
813

9-
/**
10-
* Represents a collection of input messages sent to the model.
11-
*/
14+
/** Represents a collection of input messages sent to the model. */
1215
@AutoValue
1316
public abstract class InputMessages {
1417

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/MessagePart.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

3-
/**
4-
* Interface for all message parts.
5-
*/
8+
/** Interface for all message parts. */
69
public interface MessagePart {
710

811
/**
912
* Get the type of this message part.
13+
*
1014
* @return the type string
1115
*/
1216
String getType();

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/OutputMessage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.annotation.JsonClassDescription;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -6,9 +11,7 @@
611
import java.util.ArrayList;
712
import java.util.List;
813

9-
/**
10-
* Represents a collection of output messages from the model.
11-
*/
14+
/** Represents a collection of output messages from the model. */
1215
@AutoValue
1316
public abstract class OutputMessages {
1417

@@ -38,44 +41,50 @@ public String toJsonString() {
3841
}
3942

4043
/**
41-
* Merges a chunk OutputMessage into the existing messages at the specified index.
42-
* This method is used for streaming responses where content is received in chunks.
43-
*
44+
* Merges a chunk OutputMessage into the existing messages at the specified index. This method is
45+
* used for streaming responses where content is received in chunks.
46+
*
4447
* @param index the index of the message to merge into
4548
* @param chunkMessage the chunk message to append
4649
* @return a new OutputMessages instance with the merged content
4750
*/
4851
public OutputMessages merge(int index, OutputMessage chunkMessage) {
4952
List<OutputMessage> currentMessages = new ArrayList<>(getMessages());
50-
53+
5154
if (index < 0 || index >= currentMessages.size()) {
52-
throw new IllegalArgumentException("Index " + index + " is out of bounds for messages list of size " + currentMessages.size());
55+
throw new IllegalArgumentException(
56+
"Index "
57+
+ index
58+
+ " is out of bounds for messages list of size "
59+
+ currentMessages.size());
5360
}
54-
61+
5562
OutputMessage existingMessage = currentMessages.get(index);
56-
63+
5764
// Merge the parts by appending text content from chunk to existing message
5865
List<MessagePart> mergedParts = new ArrayList<>(existingMessage.getParts());
59-
60-
// If the chunk message has text parts, append their content to the first text part of existing message
66+
67+
// If the chunk message has text parts, append their content to the first text part of existing
68+
// message
6169
for (MessagePart chunkPart : chunkMessage.getParts()) {
6270
if (chunkPart instanceof TextPart) {
6371
TextPart chunkTextPart = (TextPart) chunkPart;
64-
72+
6573
// Find the first text part in existing message to append to
6674
boolean appended = false;
6775
for (int i = 0; i < mergedParts.size(); i++) {
6876
MessagePart existingPart = mergedParts.get(i);
6977
if (existingPart instanceof TextPart) {
7078
TextPart existingTextPart = (TextPart) existingPart;
7179
// Create a new TextPart with combined content
72-
TextPart mergedTextPart = TextPart.create(existingTextPart.getContent() + chunkTextPart.getContent());
80+
TextPart mergedTextPart =
81+
TextPart.create(existingTextPart.getContent() + chunkTextPart.getContent());
7382
mergedParts.set(i, mergedTextPart);
7483
appended = true;
7584
break;
7685
}
7786
}
78-
87+
7988
// If no existing text part found, add the chunk as a new part
8089
if (!appended) {
8190
mergedParts.add(chunkTextPart);
@@ -85,20 +94,19 @@ public OutputMessages merge(int index, OutputMessage chunkMessage) {
8594
mergedParts.add(chunkPart);
8695
}
8796
}
88-
97+
8998
// Create new OutputMessage with merged parts, using the chunk's finish reason if available
90-
String finalFinishReason = chunkMessage.getFinishReason() != null ?
91-
chunkMessage.getFinishReason() : existingMessage.getFinishReason();
92-
93-
OutputMessage mergedMessage = OutputMessage.create(
94-
existingMessage.getRole(),
95-
mergedParts,
96-
finalFinishReason
97-
);
98-
99+
String finalFinishReason =
100+
chunkMessage.getFinishReason() != null
101+
? chunkMessage.getFinishReason()
102+
: existingMessage.getFinishReason();
103+
104+
OutputMessage mergedMessage =
105+
OutputMessage.create(existingMessage.getRole(), mergedParts, finalFinishReason);
106+
99107
// Replace the message at the specified index
100108
currentMessages.set(index, mergedMessage);
101-
109+
102110
return new AutoValue_OutputMessages(currentMessages);
103111
}
104112
}

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/Role.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
public enum Role {

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/SystemInstructions.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.annotation.JsonClassDescription;
@@ -7,9 +12,7 @@
712
import com.google.auto.value.AutoValue;
813
import java.util.List;
914

10-
/**
11-
* Represents the list of system instructions sent to the model.
12-
*/
15+
/** Represents the list of system instructions sent to the model. */
1316
@AutoValue
1417
@JsonClassDescription("System instructions")
1518
public abstract class SystemInstructions {

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/TextPart.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.annotation.JsonClassDescription;
49
import com.fasterxml.jackson.annotation.JsonProperty;
510
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
611
import com.google.auto.value.AutoValue;
712

8-
/**
9-
* Represents text content sent to or received from the model.
10-
*/
13+
/** Represents text content sent to or received from the model. */
1114
@AutoValue
1215
@JsonClassDescription("Text part")
1316
public abstract class TextPart implements MessagePart {

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/genai/messages/ToolCallRequestPart.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
16
package io.opentelemetry.instrumentation.api.incubator.semconv.genai.messages;
27

38
import com.fasterxml.jackson.annotation.JsonClassDescription;
@@ -6,9 +11,7 @@
611
import com.google.auto.value.AutoValue;
712
import javax.annotation.Nullable;
813

9-
/**
10-
* Represents a tool call requested by the model.
11-
*/
14+
/** Represents a tool call requested by the model. */
1215
@AutoValue
1316
@JsonClassDescription("Tool call request part")
1417
public abstract class ToolCallRequestPart implements MessagePart {

0 commit comments

Comments
 (0)