From 3b48c226af2f780cc2154114144d59ffbe66085b Mon Sep 17 00:00:00 2001 From: Peter Banda Date: Tue, 26 Nov 2024 16:36:23 +0100 Subject: [PATCH] JsonSchema object - switching properties to Seq instead of Map to have deterministic serialization --- .../scala/io/cequence/openaiscala/domain/JsonSchema.scala | 7 ++++++- .../openaiscala/service/adapter/ServiceWrapper.scala | 2 +- .../examples/nonopenai/AnthropicCreateSystemMessage.scala | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openai-core/src/main/scala/io/cequence/openaiscala/domain/JsonSchema.scala b/openai-core/src/main/scala/io/cequence/openaiscala/domain/JsonSchema.scala index 93b28804..a2986d8d 100644 --- a/openai-core/src/main/scala/io/cequence/openaiscala/domain/JsonSchema.scala +++ b/openai-core/src/main/scala/io/cequence/openaiscala/domain/JsonSchema.scala @@ -12,12 +12,17 @@ object JsonSchema { import java.lang.{String => JString} case class Object( - properties: Map[JString, JsonSchema], + properties: Seq[(JString, JsonSchema)], required: Seq[JString] = Nil ) extends JsonSchema { override val `type` = JsonType.Object } + def Object( + properties: Map[JString, JsonSchema], + required: Seq[JString] = Nil + ): Object = Object(properties.toSeq, required) + case class String( description: Option[JString] = None, `enum`: Seq[JString] = Nil diff --git a/openai-core/src/main/scala/io/cequence/openaiscala/service/adapter/ServiceWrapper.scala b/openai-core/src/main/scala/io/cequence/openaiscala/service/adapter/ServiceWrapper.scala index 4ecd3661..2a246d40 100644 --- a/openai-core/src/main/scala/io/cequence/openaiscala/service/adapter/ServiceWrapper.scala +++ b/openai-core/src/main/scala/io/cequence/openaiscala/service/adapter/ServiceWrapper.scala @@ -7,7 +7,7 @@ import io.cequence.openaiscala.service.OpenAIChatCompletionService import io.cequence.openaiscala.service.adapter.ServiceWrapperTypes._ import io.cequence.wsclient.service.CloseableService import io.cequence.wsclient.service.adapter.ServiceWrapperTypes.CloseableServiceWrapper -import io.cequence.wsclient.service.adapter.{DelegatedCloseableServiceWrapper, ServiceWrapper} +import io.cequence.wsclient.service.adapter.DelegatedCloseableServiceWrapper import scala.concurrent.Future diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateSystemMessage.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateSystemMessage.scala index c9cc22b4..ba09abfb 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateSystemMessage.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateSystemMessage.scala @@ -1,8 +1,8 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.anthropic.domain.Content.ContentBlock.TextBlock -import io.cequence.openaiscala.anthropic.domain.Content.{ContentBlockBase, SingleString} -import io.cequence.openaiscala.anthropic.domain.{Content, Message} +import io.cequence.openaiscala.anthropic.domain.Content.ContentBlockBase +import io.cequence.openaiscala.anthropic.domain.Message import io.cequence.openaiscala.anthropic.domain.Message.{SystemMessage, UserMessage} import io.cequence.openaiscala.anthropic.domain.response.CreateMessageResponse import io.cequence.openaiscala.anthropic.domain.settings.AnthropicCreateMessageSettings