Skip to content

Commit

Permalink
Migrate to the JsonSchemaElement API
Browse files Browse the repository at this point in the history
  • Loading branch information
edeandrea committed Nov 25, 2024
1 parent 0dd1268 commit 2ae7fb0
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 267 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import io.quarkiverse.langchain4j.runtime.tool.JsonNumberSchemaObjectSubstitution;
import io.quarkiverse.langchain4j.runtime.tool.JsonObjectSchemaObjectSubstitution;
import io.quarkiverse.langchain4j.runtime.tool.JsonReferenceSchemaObjectSubstitution;
import io.quarkiverse.langchain4j.runtime.tool.JsonSchemaElementObjectSubstitution;
import io.quarkiverse.langchain4j.runtime.tool.JsonStringSchemaObjectSubstitution;
import io.quarkiverse.langchain4j.runtime.tool.ToolInvoker;
import io.quarkiverse.langchain4j.runtime.tool.ToolMethodCreateInfo;
Expand Down Expand Up @@ -358,8 +357,6 @@ public ToolsMetadataBuildItem filterOutRemovedTools(
recorderContext.registerSubstitution(JsonReferenceSchema.class,
JsonReferenceSchemaObjectSubstitution.Serialized.class,
JsonReferenceSchemaObjectSubstitution.class);
recorderContext.registerSubstitution(JsonSchemaElement.class, JsonSchemaElementObjectSubstitution.Serialized.class,
JsonSchemaElementObjectSubstitution.class);
recorderContext.registerSubstitution(JsonStringSchema.class, JsonStringSchemaObjectSubstitution.Serialized.class,
JsonStringSchemaObjectSubstitution.class);
Map<String, List<ToolMethodCreateInfo>> metadataWithoutRemovedBeans = beforeRemoval.getMetadata().entrySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,27 @@

import dev.langchain4j.model.chat.request.json.JsonArraySchema;
import dev.langchain4j.model.chat.request.json.JsonSchemaElement;
import io.quarkus.runtime.ObjectSubstitution;
import io.quarkus.runtime.annotations.RecordableConstructor;

public final class JsonArraySchemaObjectSubstitution extends JsonSchemaElementObjectSubstitution {
public class JsonArraySchemaObjectSubstitution
implements ObjectSubstitution<JsonArraySchema, JsonArraySchemaObjectSubstitution.Serialized> {
@Override
public JsonArraySchemaObjectSubstitution.Serialized serialize(JsonSchemaElement obj) {
var a = (JsonArraySchema) obj;
return new Serialized(a.description(), a.items());
public Serialized serialize(JsonArraySchema obj) {
return new Serialized(obj.description(), obj.items());
}

@Override
public JsonArraySchema deserialize(JsonSchemaElementObjectSubstitution.Serialized obj) {
var a = (JsonArraySchemaObjectSubstitution.Serialized) obj;
public JsonArraySchema deserialize(Serialized obj) {
return JsonArraySchema.builder()
.description(a.description)
.items(a.items)
.description(obj.description)
.items(obj.items)
.build();
}

public static final class Serialized extends JsonSchemaElementObjectSubstitution.Serialized {
private final String description;
private final JsonSchemaElement items;

public record Serialized(String description, JsonSchemaElement items) {
@RecordableConstructor
public Serialized(String description, JsonSchemaElement items) {
this.description = description;
this.items = items;
}

public String getDescription() {
return description;
}

public JsonSchemaElement getItems() {
return items;
public Serialized {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
package io.quarkiverse.langchain4j.runtime.tool;

import dev.langchain4j.model.chat.request.json.JsonBooleanSchema;
import dev.langchain4j.model.chat.request.json.JsonSchemaElement;
import io.quarkus.runtime.ObjectSubstitution;
import io.quarkus.runtime.annotations.RecordableConstructor;

public final class JsonBooleanSchemaObjectSubstitution extends JsonSchemaElementObjectSubstitution {
public class JsonBooleanSchemaObjectSubstitution
implements ObjectSubstitution<JsonBooleanSchema, JsonBooleanSchemaObjectSubstitution.Serialized> {
@Override
public JsonBooleanSchemaObjectSubstitution.Serialized serialize(JsonSchemaElement obj) {
var b = (JsonBooleanSchema) obj;
return new Serialized(b.description());
public Serialized serialize(JsonBooleanSchema obj) {
return new Serialized(obj.description());
}

@Override
public JsonBooleanSchema deserialize(JsonSchemaElementObjectSubstitution.Serialized obj) {
var b = (JsonBooleanSchemaObjectSubstitution.Serialized) obj;
public JsonBooleanSchema deserialize(Serialized obj) {
return JsonBooleanSchema.builder()
.description(b.description)
.description(obj.description)
.build();
}

public static final class Serialized extends JsonSchemaElementObjectSubstitution.Serialized {
private final String description;

public record Serialized(String description) {
@RecordableConstructor
public Serialized(String description) {
this.description = description;
}

public String getDescription() {
return description;
public Serialized {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,27 @@
import java.util.List;

import dev.langchain4j.model.chat.request.json.JsonEnumSchema;
import dev.langchain4j.model.chat.request.json.JsonSchemaElement;
import io.quarkus.runtime.ObjectSubstitution;
import io.quarkus.runtime.annotations.RecordableConstructor;

public final class JsonEnumSchemaObjectSubstitution extends JsonSchemaElementObjectSubstitution {
public class JsonEnumSchemaObjectSubstitution
implements ObjectSubstitution<JsonEnumSchema, JsonEnumSchemaObjectSubstitution.Serialized> {
@Override
public JsonEnumSchemaObjectSubstitution.Serialized serialize(JsonSchemaElement obj) {
var e = (JsonEnumSchema) obj;
return new Serialized(e.description(), e.enumValues());
public Serialized serialize(JsonEnumSchema obj) {
return new Serialized(obj.description(), obj.enumValues());
}

@Override
public JsonEnumSchema deserialize(JsonSchemaElementObjectSubstitution.Serialized obj) {
var e = (JsonEnumSchemaObjectSubstitution.Serialized) obj;
public JsonEnumSchema deserialize(Serialized obj) {
return JsonEnumSchema.builder()
.description(e.description)
.enumValues(e.enumValues)
.description(obj.description)
.enumValues(obj.enumValues)
.build();
}

public static final class Serialized extends JsonSchemaElementObjectSubstitution.Serialized {
private final String description;
private final List<String> enumValues;

public record Serialized(String description, List<String> enumValues) {
@RecordableConstructor
public Serialized(String description, List<String> enumValues) {
this.description = description;
this.enumValues = enumValues;
}

public String getDescription() {
return description;
}

public List<String> getEnumValues() {
return enumValues;
public Serialized {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
package io.quarkiverse.langchain4j.runtime.tool;

import dev.langchain4j.model.chat.request.json.JsonIntegerSchema;
import dev.langchain4j.model.chat.request.json.JsonSchemaElement;
import io.quarkus.runtime.ObjectSubstitution;
import io.quarkus.runtime.annotations.RecordableConstructor;

public final class JsonIntegerSchemaObjectSubstitution extends JsonSchemaElementObjectSubstitution {
public final class JsonIntegerSchemaObjectSubstitution
implements ObjectSubstitution<JsonIntegerSchema, JsonIntegerSchemaObjectSubstitution.Serialized> {
@Override
public JsonIntegerSchemaObjectSubstitution.Serialized serialize(JsonSchemaElement obj) {
var i = (JsonIntegerSchema) obj;
return new Serialized(i.description());
public Serialized serialize(JsonIntegerSchema obj) {
return new Serialized(obj.description());
}

@Override
public JsonIntegerSchema deserialize(JsonSchemaElementObjectSubstitution.Serialized obj) {
var i = (JsonIntegerSchemaObjectSubstitution.Serialized) obj;
public JsonIntegerSchema deserialize(Serialized obj) {
return JsonIntegerSchema.builder()
.description(i.description)
.description(obj.description)
.build();
}

public static final class Serialized extends JsonSchemaElementObjectSubstitution.Serialized {
private final String description;

public record Serialized(String description) {
@RecordableConstructor
public Serialized(String description) {
this.description = description;
}

public String getDescription() {
return description;
public Serialized {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
package io.quarkiverse.langchain4j.runtime.tool;

import dev.langchain4j.model.chat.request.json.JsonNumberSchema;
import dev.langchain4j.model.chat.request.json.JsonSchemaElement;
import io.quarkus.runtime.ObjectSubstitution;
import io.quarkus.runtime.annotations.RecordableConstructor;

public final class JsonNumberSchemaObjectSubstitution extends JsonSchemaElementObjectSubstitution {
public class JsonNumberSchemaObjectSubstitution
implements ObjectSubstitution<JsonNumberSchema, JsonNumberSchemaObjectSubstitution.Serialized> {
@Override
public JsonNumberSchemaObjectSubstitution.Serialized serialize(JsonSchemaElement obj) {
var n = (JsonNumberSchema) obj;
return new Serialized(n.description());
public Serialized serialize(JsonNumberSchema obj) {
return new Serialized(obj.description());
}

@Override
public JsonNumberSchema deserialize(JsonSchemaElementObjectSubstitution.Serialized obj) {
var n = (JsonNumberSchemaObjectSubstitution.Serialized) obj;
public JsonNumberSchema deserialize(Serialized obj) {
return JsonNumberSchema.builder()
.description(n.description)
.description(obj.description)
.build();
}

public static final class Serialized extends JsonSchemaElementObjectSubstitution.Serialized {
private final String description;

public record Serialized(String description) {
@RecordableConstructor
public Serialized(String description) {
this.description = description;
}

public String getDescription() {
return description;
public Serialized {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,32 @@

import dev.langchain4j.model.chat.request.json.JsonObjectSchema;
import dev.langchain4j.model.chat.request.json.JsonSchemaElement;
import io.quarkus.runtime.ObjectSubstitution;
import io.quarkus.runtime.annotations.RecordableConstructor;

public final class JsonObjectSchemaObjectSubstitution extends JsonSchemaElementObjectSubstitution {
public class JsonObjectSchemaObjectSubstitution
implements ObjectSubstitution<JsonObjectSchema, JsonObjectSchemaObjectSubstitution.Serialized> {
@Override
public JsonObjectSchemaObjectSubstitution.Serialized serialize(JsonSchemaElement obj) {
var o = (JsonObjectSchema) obj;
return new Serialized(o.description(), o.properties(), o.required(), o.additionalProperties(), o.definitions());
public Serialized serialize(JsonObjectSchema obj) {
return new Serialized(obj.description(), obj.properties(), obj.required(), obj.additionalProperties(),
obj.definitions());
}

@Override
public JsonObjectSchema deserialize(JsonSchemaElementObjectSubstitution.Serialized obj) {
var o = (JsonObjectSchemaObjectSubstitution.Serialized) obj;
public JsonObjectSchema deserialize(Serialized obj) {
return JsonObjectSchema.builder()
.description(o.description)
.properties(o.properties)
.required(o.required)
.additionalProperties(o.additionalProperties)
.definitions(o.definitions)
.description(obj.description)
.properties(obj.properties)
.required(obj.required)
.additionalProperties(obj.additionalProperties)
.definitions(obj.definitions)
.build();
}

public static final class Serialized extends JsonSchemaElementObjectSubstitution.Serialized {
private final String description;
private final Map<String, JsonSchemaElement> properties;
private final List<String> required;
private final Boolean additionalProperties;
private final Map<String, JsonSchemaElement> definitions;

public record Serialized(String description, Map<String, JsonSchemaElement> properties, List<String> required,
Boolean additionalProperties, Map<String, JsonSchemaElement> definitions) {
@RecordableConstructor
public Serialized(String description, Map<String, JsonSchemaElement> properties, List<String> required,
Boolean additionalProperties, Map<String, JsonSchemaElement> definitions) {
this.description = description;
this.properties = properties;
this.required = required;
this.additionalProperties = additionalProperties;
this.definitions = definitions;
}

public String getDescription() {
return description;
}

public Map<String, JsonSchemaElement> getProperties() {
return properties;
}

public List<String> getRequired() {
return required;
}

public Boolean getAdditionalProperties() {
return additionalProperties;
}

public Map<String, JsonSchemaElement> getDefinitions() {
return definitions;
public Serialized {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,24 @@
package io.quarkiverse.langchain4j.runtime.tool;

import dev.langchain4j.model.chat.request.json.JsonReferenceSchema;
import dev.langchain4j.model.chat.request.json.JsonSchemaElement;
import io.quarkus.runtime.ObjectSubstitution;
import io.quarkus.runtime.annotations.RecordableConstructor;

public final class JsonReferenceSchemaObjectSubstitution extends JsonSchemaElementObjectSubstitution {
public JsonReferenceSchemaObjectSubstitution.Serialized serialize(JsonSchemaElement obj) {
var r = (JsonReferenceSchema) obj;
return new Serialized(r.reference());
public class JsonReferenceSchemaObjectSubstitution
implements ObjectSubstitution<JsonReferenceSchema, JsonReferenceSchemaObjectSubstitution.Serialized> {
public Serialized serialize(JsonReferenceSchema obj) {
return new Serialized(obj.reference());
}

public JsonReferenceSchema deserialize(JsonSchemaElementObjectSubstitution.Serialized obj) {
var r = (JsonReferenceSchemaObjectSubstitution.Serialized) obj;
public JsonReferenceSchema deserialize(Serialized obj) {
return JsonReferenceSchema.builder()
.reference(r.reference)
.reference(obj.reference)
.build();
}

public static final class Serialized extends JsonSchemaElementObjectSubstitution.Serialized {
private final String reference;

public record Serialized(String reference) {
@RecordableConstructor
public Serialized(String reference) {
this.reference = reference;
}

public String getReference() {
return reference;
public Serialized {
}
}
}
Loading

0 comments on commit 2ae7fb0

Please sign in to comment.