Skip to content

Commit c75df4b

Browse files
committed
add llm message class to support llm spans
1 parent cb95fbb commit c75df4b

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

dd-trace-api/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ excludedClassesCoverage += [
3232
'datadog.trace.api.profiling.ProfilingContext',
3333
'datadog.trace.api.profiling.ProfilingContextAttribute.NoOp',
3434
'datadog.trace.api.llmobs.LLMObs',
35+
'datadog.trace.api.llmobs.LLMObs.LLMMessage',
36+
'datadog.trace.api.llmobs.LLMObs.ToolCall',
3537
'datadog.trace.api.llmobs.LLMObsSpan',
3638
'datadog.trace.api.llmobs.noop.NoOpLLMObsSpan',
3739
'datadog.trace.api.llmobs.noop.NoOpLLMObsSpanFactory',

dd-trace-api/src/main/java/datadog/trace/api/llmobs/LLMObs.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package datadog.trace.api.llmobs;
22

33
import datadog.trace.api.llmobs.noop.NoOpLLMObsSpanFactory;
4+
import java.util.List;
5+
import java.util.Map;
46
import javax.annotation.Nullable;
57

68
public class LLMObs {
@@ -57,4 +59,63 @@ LLMObsSpan startLLMSpan(
5759
LLMObsSpan startWorkflowSpan(
5860
String spanName, @Nullable String mlApp, @Nullable String sessionID);
5961
}
62+
63+
public static class ToolCall {
64+
private String name;
65+
private String type;
66+
private String toolID;
67+
private Map<String, Object> arguments;
68+
69+
public ToolCall(String name, String type, String toolID, Map<String, Object> arguments) {
70+
this.name = name;
71+
this.type = type;
72+
this.toolID = toolID;
73+
this.arguments = arguments;
74+
}
75+
76+
public String getName() {
77+
return name;
78+
}
79+
80+
public String getType() {
81+
return type;
82+
}
83+
84+
public String getToolID() {
85+
return toolID;
86+
}
87+
88+
public Map<String, Object> getArguments() {
89+
return arguments;
90+
}
91+
}
92+
93+
public static class LLMMessage {
94+
private String role;
95+
private String content;
96+
private List<ToolCall> toolCalls;
97+
98+
public LLMMessage(String role, String content, List<ToolCall> toolCalls) {
99+
this.role = role;
100+
this.content = content;
101+
this.toolCalls = toolCalls;
102+
}
103+
104+
public LLMMessage(String role, String content) {
105+
this.role = role;
106+
this.content = content;
107+
}
108+
109+
public String getRole() {
110+
return role;
111+
}
112+
113+
public String getContent() {
114+
return content;
115+
}
116+
117+
public List<ToolCall> getToolCalls() {
118+
return toolCalls;
119+
}
120+
}
60121
}

dd-trace-api/src/main/java/datadog/trace/api/llmobs/LLMObsSpan.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
public interface LLMObsSpan {
88

99
/**
10-
* Annotate the span with inputs and outputs
10+
* Annotate the span with inputs and outputs for LLM spans
1111
*
12-
* @param inputData The input data of the span in the form of a list, for example a list of input
13-
* messages
14-
* @param outputData The output data of the span in the form of a list, for example a list of
15-
* output messages
12+
* @param inputMessages The input messages of the span in the form of a list
13+
* @param outputMessages The output messages of the span in the form of a list
1614
*/
17-
void annotateIO(List<Map<String, Object>> inputData, List<Map<String, Object>> outputData);
15+
void annotateIO(List<LLMObs.LLMMessage> inputMessages, List<LLMObs.LLMMessage> outputMessages);
1816

1917
/**
2018
* Annotate the span with inputs and outputs

dd-trace-api/src/main/java/datadog/trace/api/llmobs/noop/NoOpLLMObsSpan.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.api.llmobs.noop;
22

3+
import datadog.trace.api.llmobs.LLMObs;
34
import datadog.trace.api.llmobs.LLMObsSpan;
45
import java.util.List;
56
import java.util.Map;
@@ -8,8 +9,7 @@ public class NoOpLLMObsSpan implements LLMObsSpan {
89
public static final LLMObsSpan INSTANCE = new NoOpLLMObsSpan();
910

1011
@Override
11-
public void annotateIO(
12-
List<Map<String, Object>> inputData, List<Map<String, Object>> outputData) {}
12+
public void annotateIO(List<LLMObs.LLMMessage> inputData, List<LLMObs.LLMMessage> outputData) {}
1313

1414
@Override
1515
public void annotateIO(String inputData, String outputData) {}

0 commit comments

Comments
 (0)