Skip to content

Commit

Permalink
Merge pull request #334 from quarkiverse/#333
Browse files Browse the repository at this point in the history
Add Content serialization support
  • Loading branch information
geoand authored Feb 29, 2024
2 parents 623c0a4 + fc328cc commit 8ba24bb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkiverse.langchain4j.openai.runtime.jackson;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import dev.ai4j.openai4j.chat.Content;
import io.quarkus.jackson.JacksonMixin;

@JacksonMixin(Content.class)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
public abstract class ContentMixin {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkiverse.langchain4j.openai.runtime.jackson;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import dev.ai4j.openai4j.chat.ContentType;
import io.quarkus.jackson.JacksonMixin;

@JacksonMixin(ContentType.class)
@JsonSerialize(using = ContentTypeSerializer.class)
public abstract class ContentTypeMixin {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkiverse.langchain4j.openai.runtime.jackson;

import java.io.IOException;
import java.util.Locale;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import dev.ai4j.openai4j.chat.ContentType;

public class ContentTypeSerializer extends StdSerializer<ContentType> {
public ContentTypeSerializer() {
super(ContentType.class);
}

@Override
public void serialize(ContentType value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeString(value.toString().toLowerCase(Locale.ROOT));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.quarkiverse.langchain4j.openai.runtime.jackson;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import dev.ai4j.openai4j.chat.ImageUrl;
import io.quarkus.jackson.JacksonMixin;

@JacksonMixin(ImageUrl.class)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY, getterVisibility = JsonAutoDetect.Visibility.NONE, setterVisibility = JsonAutoDetect.Visibility.NONE)
public abstract class ImageUrlMixin {
}

0 comments on commit 8ba24bb

Please sign in to comment.