Last active
October 3, 2024 23:30
-
-
Save lmolkova/1e7aae49483e411a5c7e633490202ee9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) throws IOException { | |
var logProvider = SdkLoggerProvider.builder() | |
.addLogRecordProcessor(SimpleLogRecordProcessor.create(OtlpGrpcLogRecordExporter.getDefault())).build(); | |
EventLoggerProvider eventLoggerProvider = SdkEventLoggerProvider.create(logProvider); | |
var logger = eventLoggerProvider.get("test-logger"); | |
var event = new GenAIChoice() | |
.setId(1) | |
.setFinishReasons(new String[]{"stop", "length"}) | |
.setMessage(new GenAIMessage().setContent("test content")); | |
logger.builder("test-event") | |
.put("id", Value.of(event.getId())) | |
.put("finishReasons", Value.of(Arrays.stream(event.getFinishReasons()).map(Value::of).toArray(Value[]::new))) | |
.put("message", event.getMessage().toValue()) | |
.emit(); | |
/*logger.builder("test-event") | |
.put(event.toValue()) | |
.emit();*/ | |
} | |
static class GenAIChoice { | |
private int id; | |
private String[] finishReasons; | |
private GenAIMessage message; | |
public int getId() { | |
return id; | |
} | |
public GenAIChoice setId(int id) { | |
this.id = id; | |
return this; | |
} | |
public String[] getFinishReasons() { | |
return finishReasons; | |
} | |
public GenAIChoice setFinishReasons(String[] finishReasons) { | |
this.finishReasons = finishReasons; | |
return this; | |
} | |
public GenAIMessage getMessage() { | |
return message; | |
} | |
public GenAIChoice setMessage(GenAIMessage message) { | |
this.message = message; | |
return this; | |
} | |
public Value<List<KeyValue>> toValue() { | |
Map<String, Value<?>> fields = new HashMap<>(1); | |
fields.put("id", Value.of(id)); | |
fields.put("finishReasons", Value.of(Arrays.stream(finishReasons).map(Value::of).toArray(Value[]::new))); | |
fields.put("message", Value.of(message.toValue())); | |
return Value.of(fields); | |
} | |
} | |
static class GenAIMessage { | |
private String content; | |
public String getContent() { | |
return content; | |
} | |
public GenAIMessage setContent(String content) { | |
this.content = content; | |
return this; | |
} | |
public Value<List<KeyValue>> toValue() { | |
return Value.of(Collections.singletonMap("content", Value.of(content))); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment