Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for OpenAI developer messages #539

Merged
merged 5 commits into from
Feb 12, 2025

Conversation

JonasKunz
Copy link
Contributor

Closes #532 . For now, these messages will simply be reported as gen_ai.system.message events with role set to developer, which seems to be kind of sem conv compliant. We'll have to revisit later anyway for future semconv changes (e.g. open-telemetry/semantic-conventions#1851), but this at least keeps things working for now.

@@ -102,7 +115,8 @@ public static void emitPromptLogEvents(
bodyBuilder.put("id", toolMsg.toolCallId());
}
} else {
throw new IllegalStateException("Unhandled type : " + msg.getClass().getName());
LOG.log(Level.WARNING, "Unhandled OpenAI message type will be dropped: {0}", msg);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would previously cause the instrumentation to fail, which is a bit too strict.

@@ -228,7 +255,7 @@ private static LogRecordBuilder newEvent(String name) {
private static Value<?> buildToolCallEventObject(ChatCompletionMessageToolCall call) {
Map<String, Value<?>> result = new HashMap<>();
result.put("id", Value.of(call.id()));
result.put("type", Value.of(call._type().toString()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not detected by muzzle: In some versions inbetween _type() was not present in the openAI lib.

} else if (val.isResponseFormatJsonSchema()) {
return val.asResponseFormatJsonSchema()._type().toString();
return "json_schema";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some versions _type() returns null here, so I instead hardcoded the strings for these older versions.

@JonasKunz
Copy link
Contributor Author

I'm giving up on muzzle, the checks for 8e050f4 should have failed but did not: In that commit muzzle should have checked against the 0.2.0 version and fail, because DeveloperMessages are not present in that version. I tried debugging why it doesn't work, but eventually gave up because I think it's not worth spending more time here.

For now we should not trust muzzle being green, but rather as a additional safety net which might catch additional problems (or not...)

@JonasKunz JonasKunz marked this pull request as ready for review February 11, 2025 14:22
@JonasKunz JonasKunz requested a review from a team February 11, 2025 14:54
ChatCompletionDeveloperMessageParam sysMsg =
(ChatCompletionDeveloperMessageParam) concreteMessageParam;
eventType = "gen_ai.system.message";
putIfNotEmpty(bodyBuilder, "role", "developer");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. where the SDK isn't explicit in how these map to json, we make a good guess

@codefromthecrypt codefromthecrypt merged commit 5fedd11 into elastic:main Feb 12, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for OpenAI "Developer Messages" introduced in openAI java client 0.8
2 participants