|
| 1 | +package com.genexus.util.saia; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.annotation.JsonInclude; |
| 4 | +import com.fasterxml.jackson.annotation.JsonProperty; |
| 5 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 6 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 7 | +import com.genexus.diagnostics.core.ILogger; |
| 8 | +import com.genexus.diagnostics.core.LogManager; |
| 9 | + |
| 10 | +import java.time.LocalDateTime; |
| 11 | +import java.time.format.DateTimeFormatter; |
| 12 | + |
| 13 | +@JsonInclude(JsonInclude.Include.NON_NULL) |
| 14 | +public class SaiaEvents { |
| 15 | + private static final ILogger logger = LogManager.getLogger(SaiaEvents.class); |
| 16 | + |
| 17 | + @JsonProperty("event") |
| 18 | + private String event; |
| 19 | + |
| 20 | + @JsonProperty("data") |
| 21 | + private Data data; |
| 22 | + |
| 23 | + public String getEvent() { |
| 24 | + return event; |
| 25 | + } |
| 26 | + |
| 27 | + public void setEvent(String event) { |
| 28 | + this.event = event; |
| 29 | + } |
| 30 | + |
| 31 | + public Data getData() { |
| 32 | + return data; |
| 33 | + } |
| 34 | + |
| 35 | + public void setData(Data data) { |
| 36 | + this.data = data; |
| 37 | + } |
| 38 | + |
| 39 | + @JsonInclude(JsonInclude.Include.NON_NULL) |
| 40 | + public static class Data { |
| 41 | + |
| 42 | + @JsonProperty("toolId") |
| 43 | + private String toolId; |
| 44 | + |
| 45 | + @JsonProperty("toolName") |
| 46 | + private String toolName; |
| 47 | + |
| 48 | + @JsonProperty("timestamp") |
| 49 | + private String timestamp; |
| 50 | + |
| 51 | + @JsonProperty("toolDescription") |
| 52 | + private String toolDescription; |
| 53 | + |
| 54 | + @JsonProperty("toolStatus") |
| 55 | + private String toolStatus; |
| 56 | + |
| 57 | + @JsonProperty("toolResponse") |
| 58 | + private String toolResponse; |
| 59 | + |
| 60 | + @JsonProperty("executionId") |
| 61 | + private String executionId; |
| 62 | + |
| 63 | + public String getToolId() { |
| 64 | + return toolId; |
| 65 | + } |
| 66 | + |
| 67 | + public void setToolId(String toolId) { |
| 68 | + this.toolId = toolId; |
| 69 | + } |
| 70 | + |
| 71 | + public String getToolName() { |
| 72 | + return toolName; |
| 73 | + } |
| 74 | + |
| 75 | + public void setToolName(String toolName) { |
| 76 | + this.toolName = toolName; |
| 77 | + } |
| 78 | + |
| 79 | + public String getTimestamp() { |
| 80 | + return timestamp; |
| 81 | + } |
| 82 | + |
| 83 | + public void setTimestamp(String timestamp) { |
| 84 | + this.timestamp = timestamp; |
| 85 | + } |
| 86 | + |
| 87 | + public String getToolDescription() { |
| 88 | + return toolDescription; |
| 89 | + } |
| 90 | + |
| 91 | + public void setToolDescription(String toolDescription) { |
| 92 | + this.toolDescription = toolDescription; |
| 93 | + } |
| 94 | + |
| 95 | + public String getToolResponse() { |
| 96 | + return toolResponse; |
| 97 | + } |
| 98 | + |
| 99 | + public void setToolResponse(String toolResponse) { |
| 100 | + this.toolResponse = toolResponse; |
| 101 | + } |
| 102 | + |
| 103 | + public String getToolStatus() { |
| 104 | + return toolStatus; |
| 105 | + } |
| 106 | + |
| 107 | + public void setToolStatus(String toolStatus) { |
| 108 | + this.toolStatus = toolStatus; |
| 109 | + } |
| 110 | + |
| 111 | + public String getExecutionId() { |
| 112 | + return executionId; |
| 113 | + } |
| 114 | + |
| 115 | + public void setExecutionId(String executionId) { |
| 116 | + this.executionId = executionId; |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + public String serializeSaiaEvent(OpenAIResponse.ToolCall toolCall, String event, String tollStatus, String result) { |
| 121 | + SaiaEvents.Data saiaToolStartedData = new SaiaEvents.Data(); |
| 122 | + saiaToolStartedData.setToolName(toolCall.getFunction().getName()); |
| 123 | + saiaToolStartedData.setTimestamp(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"))); |
| 124 | + saiaToolStartedData.setToolStatus(tollStatus); |
| 125 | + saiaToolStartedData.setToolResponse(result); |
| 126 | + saiaToolStartedData.setExecutionId(toolCall.getId()); |
| 127 | + setEvent(event); |
| 128 | + setData(saiaToolStartedData); |
| 129 | + |
| 130 | + try { |
| 131 | + ObjectMapper mapper = new ObjectMapper(); |
| 132 | + return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(this); |
| 133 | + } |
| 134 | + catch (JsonProcessingException e) { |
| 135 | + logger.error("Serializing Saia Event", e); |
| 136 | + return null; |
| 137 | + } |
| 138 | + } |
| 139 | +} |
0 commit comments