-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathCreateLLMObsExperimentEvents.java
More file actions
81 lines (77 loc) · 4.31 KB
/
CreateLLMObsExperimentEvents.java
File metadata and controls
81 lines (77 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Push events for an LLM Observability experiment returns "Accepted" response
import com.datadog.api.client.ApiClient;
import com.datadog.api.client.ApiException;
import com.datadog.api.client.v2.api.LlmObservabilityApi;
import com.datadog.api.client.v2.model.LLMObsEventType;
import com.datadog.api.client.v2.model.LLMObsExperimentEventsDataAttributesRequest;
import com.datadog.api.client.v2.model.LLMObsExperimentEventsDataRequest;
import com.datadog.api.client.v2.model.LLMObsExperimentEventsRequest;
import com.datadog.api.client.v2.model.LLMObsExperimentMetric;
import com.datadog.api.client.v2.model.LLMObsExperimentMetricError;
import com.datadog.api.client.v2.model.LLMObsExperimentSpan;
import com.datadog.api.client.v2.model.LLMObsExperimentSpanError;
import com.datadog.api.client.v2.model.LLMObsExperimentSpanMeta;
import com.datadog.api.client.v2.model.LLMObsExperimentSpanStatus;
import com.datadog.api.client.v2.model.LLMObsMetricAssessment;
import com.datadog.api.client.v2.model.LLMObsMetricScoreType;
import java.util.Collections;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = ApiClient.getDefaultApiClient();
defaultClient.setUnstableOperationEnabled("v2.createLLMObsExperimentEvents", true);
LlmObservabilityApi apiInstance = new LlmObservabilityApi(defaultClient);
LLMObsExperimentEventsRequest body =
new LLMObsExperimentEventsRequest()
.data(
new LLMObsExperimentEventsDataRequest()
.attributes(
new LLMObsExperimentEventsDataAttributesRequest()
.metrics(
Collections.singletonList(
new LLMObsExperimentMetric()
.assessment(LLMObsMetricAssessment.PASS)
.error(new LLMObsExperimentMetricError())
.label("faithfulness")
.metricType(LLMObsMetricScoreType.SCORE)
.spanId("span-7a1b2c3d")
.timestampMs(1705314600000L)))
.spans(
Collections.singletonList(
new LLMObsExperimentSpan()
.datasetId("9f64e5c7-dc5a-45c8-a17c-1b85f0bec97d")
.duration(1500000000L)
.meta(
new LLMObsExperimentSpanMeta()
.error(
new LLMObsExperimentSpanError()
.message("Model response timed out")
.stack(
"""
Traceback (most recent call last):
File "main.py", line 10, in <module>
response = model.generate(input)
File "model.py", line 45, in generate
raise TimeoutError("Model response timed out")
TimeoutError: Model response timed out
""")
.type("TimeoutError"))
.input(null)
.output(null))
.name("llm_call")
.projectId("a33671aa-24fd-4dcd-9b33-a8ec7dde7751")
.spanId("span-7a1b2c3d")
.startNs(1705314600000000000L)
.status(LLMObsExperimentSpanStatus.OK)
.traceId("abc123def456"))))
.type(LLMObsEventType.EVENTS));
try {
apiInstance.createLLMObsExperimentEvents("3fd6b5e0-8910-4b1c-a7d0-5b84de329012", body);
} catch (ApiException e) {
System.err.println("Exception when calling LlmObservabilityApi#createLLMObsExperimentEvents");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}