forked from quarkiverse/quarkus-langchain4j
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to the JsonSchemaElement API
Closes quarkiverse#1054
- Loading branch information
Showing
14 changed files
with
364 additions
and
102 deletions.
There are no files selected for viewing
184 changes: 111 additions & 73 deletions
184
core/deployment/src/main/java/io/quarkiverse/langchain4j/deployment/ToolProcessor.java
Large diffs are not rendered by default.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
.../main/java/io/quarkiverse/langchain4j/runtime/tool/JsonArraySchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
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 class JsonArraySchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonArraySchema, JsonArraySchemaObjectSubstitution.Serialized> { | ||
@Override | ||
public Serialized serialize(JsonArraySchema obj) { | ||
return new Serialized(obj.description(), obj.items()); | ||
} | ||
|
||
@Override | ||
public JsonArraySchema deserialize(Serialized obj) { | ||
return JsonArraySchema.builder() | ||
.description(obj.description) | ||
.items(obj.items) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String description, JsonSchemaElement items) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ain/java/io/quarkiverse/langchain4j/runtime/tool/JsonBooleanSchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
import dev.langchain4j.model.chat.request.json.JsonBooleanSchema; | ||
import io.quarkus.runtime.ObjectSubstitution; | ||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
public class JsonBooleanSchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonBooleanSchema, JsonBooleanSchemaObjectSubstitution.Serialized> { | ||
@Override | ||
public Serialized serialize(JsonBooleanSchema obj) { | ||
return new Serialized(obj.description()); | ||
} | ||
|
||
@Override | ||
public JsonBooleanSchema deserialize(Serialized obj) { | ||
return JsonBooleanSchema.builder() | ||
.description(obj.description) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String description) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...c/main/java/io/quarkiverse/langchain4j/runtime/tool/JsonEnumSchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
import java.util.List; | ||
|
||
import dev.langchain4j.model.chat.request.json.JsonEnumSchema; | ||
import io.quarkus.runtime.ObjectSubstitution; | ||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
public class JsonEnumSchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonEnumSchema, JsonEnumSchemaObjectSubstitution.Serialized> { | ||
@Override | ||
public Serialized serialize(JsonEnumSchema obj) { | ||
return new Serialized(obj.description(), obj.enumValues()); | ||
} | ||
|
||
@Override | ||
public JsonEnumSchema deserialize(Serialized obj) { | ||
return JsonEnumSchema.builder() | ||
.description(obj.description) | ||
.enumValues(obj.enumValues) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String description, List<String> enumValues) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...ain/java/io/quarkiverse/langchain4j/runtime/tool/JsonIntegerSchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
import dev.langchain4j.model.chat.request.json.JsonIntegerSchema; | ||
import io.quarkus.runtime.ObjectSubstitution; | ||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
public final class JsonIntegerSchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonIntegerSchema, JsonIntegerSchemaObjectSubstitution.Serialized> { | ||
@Override | ||
public Serialized serialize(JsonIntegerSchema obj) { | ||
return new Serialized(obj.description()); | ||
} | ||
|
||
@Override | ||
public JsonIntegerSchema deserialize(Serialized obj) { | ||
return JsonIntegerSchema.builder() | ||
.description(obj.description) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String description) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...main/java/io/quarkiverse/langchain4j/runtime/tool/JsonNumberSchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
import dev.langchain4j.model.chat.request.json.JsonNumberSchema; | ||
import io.quarkus.runtime.ObjectSubstitution; | ||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
public class JsonNumberSchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonNumberSchema, JsonNumberSchemaObjectSubstitution.Serialized> { | ||
@Override | ||
public Serialized serialize(JsonNumberSchema obj) { | ||
return new Serialized(obj.description()); | ||
} | ||
|
||
@Override | ||
public JsonNumberSchema deserialize(Serialized obj) { | ||
return JsonNumberSchema.builder() | ||
.description(obj.description) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String description) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...main/java/io/quarkiverse/langchain4j/runtime/tool/JsonObjectSchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
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 class JsonObjectSchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonObjectSchema, JsonObjectSchemaObjectSubstitution.Serialized> { | ||
@Override | ||
public Serialized serialize(JsonObjectSchema obj) { | ||
return new Serialized(obj.description(), obj.properties(), obj.required(), obj.additionalProperties(), | ||
obj.definitions()); | ||
} | ||
|
||
@Override | ||
public JsonObjectSchema deserialize(Serialized obj) { | ||
return JsonObjectSchema.builder() | ||
.description(obj.description) | ||
.properties(obj.properties) | ||
.required(obj.required) | ||
.additionalProperties(obj.additionalProperties) | ||
.definitions(obj.definitions) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String description, Map<String, JsonSchemaElement> properties, List<String> required, | ||
Boolean additionalProperties, Map<String, JsonSchemaElement> definitions) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...n/java/io/quarkiverse/langchain4j/runtime/tool/JsonReferenceSchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
import dev.langchain4j.model.chat.request.json.JsonReferenceSchema; | ||
import io.quarkus.runtime.ObjectSubstitution; | ||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
public class JsonReferenceSchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonReferenceSchema, JsonReferenceSchemaObjectSubstitution.Serialized> { | ||
public Serialized serialize(JsonReferenceSchema obj) { | ||
return new Serialized(obj.reference()); | ||
} | ||
|
||
public JsonReferenceSchema deserialize(Serialized obj) { | ||
return JsonReferenceSchema.builder() | ||
.reference(obj.reference) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String reference) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...main/java/io/quarkiverse/langchain4j/runtime/tool/JsonStringSchemaObjectSubstitution.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkiverse.langchain4j.runtime.tool; | ||
|
||
import dev.langchain4j.model.chat.request.json.JsonStringSchema; | ||
import io.quarkus.runtime.ObjectSubstitution; | ||
import io.quarkus.runtime.annotations.RecordableConstructor; | ||
|
||
public final class JsonStringSchemaObjectSubstitution | ||
implements ObjectSubstitution<JsonStringSchema, JsonStringSchemaObjectSubstitution.Serialized> { | ||
@Override | ||
public Serialized serialize(JsonStringSchema obj) { | ||
return new Serialized(obj.description()); | ||
} | ||
|
||
@Override | ||
public JsonStringSchema deserialize(Serialized obj) { | ||
return JsonStringSchema.builder() | ||
.description(obj.description) | ||
.build(); | ||
} | ||
|
||
public record Serialized(String description) { | ||
@RecordableConstructor | ||
public Serialized { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters