Skip to content

Commit

Permalink
Fiw role serialization, Ollama 2.5 + does not accept anymore in upper…
Browse files Browse the repository at this point in the history
… case.
  • Loading branch information
humcqc committed Jul 15, 2024
1 parent 7820be7 commit 4f8d05d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.quarkiverse.langchain4j.ollama;

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

import io.quarkiverse.langchain4j.ollama.runtime.jackson.RoleDeserializer;
import io.quarkiverse.langchain4j.ollama.runtime.jackson.RoleSerializer;

@JsonDeserialize(using = RoleDeserializer.class)
@JsonSerialize(using = RoleSerializer.class)
public enum Role {

SYSTEM,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkiverse.langchain4j.ollama.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 io.quarkiverse.langchain4j.ollama.Role;

public class RoleSerializer extends StdSerializer<Role> {
public RoleSerializer() {
super(Role.class);
}

@Override
public void serialize(Role role, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeString(role.toString().toLowerCase(Locale.ROOT));
}
}

0 comments on commit 4f8d05d

Please sign in to comment.