Skip to content

DefaultUsage#nativeUsage can crash SimpleLoggingAdvisor #2535

@mands

Description

@mands

The nativeUsage object within DefaultUsage may not be JSON serialisable and hence causes a crash when using SimpleLoggingAdvisor.

I've hit this when using VertexAI, where the nativeUsage instance, which is cast as an Object, is a protobuf of type GenerateContentRepsonse$UsageMetadata.

This can't be serialised for pretty printing within the SimpleLoggerAdvisor repsonse code, which calls ModelOptionsUtils#toJsonStringPrettyPrinter and thus throws an Exception.

	public static String toJsonStringPrettyPrinter(Object object) {
		try {
			return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(object);
		}
		catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	}

I think simplest solution would be to add a @JsonIgnore to DefaultUsage#getNativeUsage as it's not always obvious if it can be logged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions