diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/ChatCompletionProvider.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/ChatCompletionProvider.scala new file mode 100644 index 00000000..3e1ddada --- /dev/null +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/ChatCompletionProvider.scala @@ -0,0 +1,126 @@ +package io.cequence.openaiscala.examples + +import akka.stream.Materializer +import io.cequence.openaiscala.anthropic.service.AnthropicServiceFactory +import io.cequence.openaiscala.service.{ + OpenAIChatCompletionService, + OpenAIChatCompletionServiceFactory, + OpenAIChatCompletionStreamedServiceExtra, + OpenAIChatCompletionStreamedServiceFactory +} +import io.cequence.openaiscala.vertexai.service.VertexAIServiceFactory +import io.cequence.wsclient.domain.WsRequestContext + +import scala.concurrent.ExecutionContext + +object ChatCompletionProvider { + case class ProviderSettings( + coreUrl: String, + apiKeyEnvVariable: String + ) + + val Cerebras = ProviderSettings("https://api.cerebras.ai/v1/", "CEREBRAS_API_KEY") + val Groq = ProviderSettings("https://api.groq.com/openai/v1/", "GROQ_API_KEY") + val Fireworks = + ProviderSettings("https://api.fireworks.ai/inference/v1/", "FIREWORKS_API_KEY") + val Mistral = ProviderSettings("https://api.mistral.ai/v1/", "MISTRAL_API_KEY") + val OctoML = ProviderSettings("https://text.octoai.run/v1/", "OCTOAI_TOKEN") + val TogetherAI = ProviderSettings("https://api.together.xyz/v1/", "TOGETHERAI_API_KEY") + + def cerebras( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionService = provide(Cerebras) + + def groq( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionService = provide(Groq) + + def fireworks( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionService = provide(Fireworks) + + def mistral( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionService = provide(Mistral) + + def octoML( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionService = provide(OctoML) + + def togetherAI( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionService = provide(TogetherAI) + + def vertexAI( + implicit ec: ExecutionContext, + m: Materializer + ) = VertexAIServiceFactory.asOpenAI() + + def anthropic( + implicit ec: ExecutionContext, + m: Materializer + ) = AnthropicServiceFactory.asOpenAI() + + object streamed { + def cerebras( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionStreamedServiceExtra = provideStreamed(Cerebras) + + def groq( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionStreamedServiceExtra = provideStreamed(Groq) + + def fireworks( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionStreamedServiceExtra = provideStreamed(Fireworks) + + def mistral( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionStreamedServiceExtra = provideStreamed(Mistral) + + def octoML( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionStreamedServiceExtra = provideStreamed(OctoML) + + def togetherAI( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionStreamedServiceExtra = provideStreamed(TogetherAI) + } + + private def provide( + settings: ProviderSettings + )( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionService = OpenAIChatCompletionServiceFactory( + coreUrl = settings.coreUrl, + WsRequestContext(authHeaders = + Seq(("Authorization", s"Bearer ${sys.env(settings.apiKeyEnvVariable)}")) + ) + ) + + private def provideStreamed( + settings: ProviderSettings + )( + implicit ec: ExecutionContext, + m: Materializer + ): OpenAIChatCompletionStreamedServiceExtra = OpenAIChatCompletionStreamedServiceFactory( + coreUrl = settings.coreUrl, + WsRequestContext(authHeaders = + Seq(("Authorization", s"Bearer ${sys.env(settings.apiKeyEnvVariable)}")) + ) + ) + +} diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionStreamedWithOpenAIAdapter.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionStreamedWithOpenAIAdapter.scala index 3c692289..498ea0e5 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionStreamedWithOpenAIAdapter.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionStreamedWithOpenAIAdapter.scala @@ -6,7 +6,7 @@ import io.cequence.openaiscala.OpenAIScalaClientException import io.cequence.openaiscala.anthropic.service.AnthropicServiceFactory import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings import io.cequence.openaiscala.domain.{NonOpenAIModelId, SystemMessage, UserMessage} -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.StreamedServiceTypes.OpenAIChatCompletionStreamedService import org.slf4j.LoggerFactory @@ -20,7 +20,7 @@ object AnthropicCreateChatCompletionStreamedWithOpenAIAdapter private val logger = LoggerFactory.getLogger(this.getClass) override val service: OpenAIChatCompletionStreamedService = - AnthropicServiceFactory.asOpenAI() + ChatCompletionProvider.anthropic private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionWithOpenAIAdapter.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionWithOpenAIAdapter.scala index cc8fb043..49c594ab 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionWithOpenAIAdapter.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/AnthropicCreateChatCompletionWithOpenAIAdapter.scala @@ -3,7 +3,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.anthropic.service.AnthropicServiceFactory import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings import io.cequence.openaiscala.domain.{NonOpenAIModelId, SystemMessage, UserMessage} -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.OpenAIChatCompletionService import scala.concurrent.Future @@ -12,7 +12,8 @@ import scala.concurrent.Future object AnthropicCreateChatCompletionWithOpenAIAdapter extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionService = AnthropicServiceFactory.asOpenAI() + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.anthropic private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletion.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletion.scala index 5f4c081a..b5e8e7b8 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletion.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletion.scala @@ -2,7 +2,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionService, OpenAIChatCompletionServiceFactory @@ -16,12 +16,8 @@ import scala.concurrent.Future */ object CerebrasCreateChatCompletion extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionService = OpenAIChatCompletionServiceFactory( - coreUrl = "https://api.cerebras.ai/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("CEREBRAS_API_KEY")}")) - ) - ) + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.cerebras private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletionStreamed.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletionStreamed.scala index 356852b3..36031d83 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletionStreamed.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/CerebrasCreateChatCompletionStreamed.scala @@ -3,11 +3,8 @@ package io.cequence.openaiscala.examples.nonopenai import akka.stream.scaladsl.Sink import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase -import io.cequence.openaiscala.service.{ - OpenAIChatCompletionStreamedServiceExtra, - OpenAIChatCompletionStreamedServiceFactory -} +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} +import io.cequence.openaiscala.service.{OpenAIChatCompletionStreamedServiceExtra, OpenAIChatCompletionStreamedServiceFactory} import io.cequence.wsclient.domain.WsRequestContext import scala.concurrent.Future @@ -17,12 +14,7 @@ object CerebrasCreateChatCompletionStreamed extends ExampleBase[OpenAIChatCompletionStreamedServiceExtra] { override val service: OpenAIChatCompletionStreamedServiceExtra = - OpenAIChatCompletionStreamedServiceFactory( - coreUrl = "https://api.cerebras.ai/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("CEREBRAS_API_KEY")}")) - ) - ) + ChatCompletionProvider.streamed.cerebras private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletion.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletion.scala index e4d08728..0a05ad4b 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletion.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletion.scala @@ -2,7 +2,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionService, OpenAIChatCompletionServiceFactory @@ -20,12 +20,8 @@ import scala.concurrent.Future object FireworksAICreateChatCompletion extends ExampleBase[OpenAIChatCompletionService] { private val fireworksModelPrefix = "accounts/fireworks/models/" - override val service: OpenAIChatCompletionService = OpenAIChatCompletionServiceFactory( - coreUrl = "https://api.fireworks.ai/inference/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("FIREWORKS_API_KEY")}")) - ) - ) + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.fireworks private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletionStreamed.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletionStreamed.scala index 76adbe9d..f17bb51f 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletionStreamed.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/FireworksAICreateChatCompletionStreamed.scala @@ -3,7 +3,7 @@ package io.cequence.openaiscala.examples.nonopenai import akka.stream.scaladsl.Sink import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionStreamedServiceExtra, OpenAIChatCompletionStreamedServiceFactory @@ -18,12 +18,7 @@ object FireworksAICreateChatCompletionStreamed private val fireworksModelPrefix = "accounts/fireworks/models/" override val service: OpenAIChatCompletionStreamedServiceExtra = - OpenAIChatCompletionStreamedServiceFactory( - coreUrl = "https://api.fireworks.ai/inference/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("FIREWORKS_API_KEY")}")) - ) - ) + ChatCompletionProvider.streamed.fireworks private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletion.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletion.scala index 5c0ccf10..14b12356 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletion.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletion.scala @@ -2,7 +2,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionService, OpenAIChatCompletionServiceFactory @@ -16,12 +16,8 @@ import scala.concurrent.Future */ object GroqCreateChatCompletion extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionService = OpenAIChatCompletionServiceFactory( - coreUrl = "https://api.groq.com/openai/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("GROQ_API_KEY")}")) - ) - ) + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.groq private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletionStreamed.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletionStreamed.scala index 75a241bf..08815ad8 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletionStreamed.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/GroqCreateChatCompletionStreamed.scala @@ -3,7 +3,7 @@ package io.cequence.openaiscala.examples.nonopenai import akka.stream.scaladsl.Sink import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionStreamedServiceExtra, OpenAIChatCompletionStreamedServiceFactory @@ -17,12 +17,7 @@ object GroqCreateChatCompletionStreamed extends ExampleBase[OpenAIChatCompletionStreamedServiceExtra] { override val service: OpenAIChatCompletionStreamedServiceExtra = - OpenAIChatCompletionStreamedServiceFactory( - coreUrl = "https://api.groq.com/openai/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("GROQ_API_KEY")}")) - ) - ) + ChatCompletionProvider.streamed.groq private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletion.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletion.scala index fc51f522..836d8ce2 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletion.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletion.scala @@ -2,7 +2,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionService, OpenAIChatCompletionServiceFactory @@ -14,12 +14,8 @@ import scala.concurrent.Future // requires `MISTRAL_API_KEY` environment variable to be set object MistralCreateChatCompletion extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionService = OpenAIChatCompletionServiceFactory( - coreUrl = "https://api.mistral.ai/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("MISTRAL_API_KEY")}")) - ) - ) + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.mistral private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletionStreamed.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletionStreamed.scala index addcd22f..1bbba069 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletionStreamed.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/MistralCreateChatCompletionStreamed.scala @@ -3,7 +3,7 @@ package io.cequence.openaiscala.examples.nonopenai import akka.stream.scaladsl.Sink import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionStreamedServiceExtra, OpenAIChatCompletionStreamedServiceFactory @@ -17,12 +17,7 @@ object MistralCreateChatCompletionStreamed extends ExampleBase[OpenAIChatCompletionStreamedServiceExtra] { override val service: OpenAIChatCompletionStreamedServiceExtra = - OpenAIChatCompletionStreamedServiceFactory( - coreUrl = "https://api.mistral.ai/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("MISTRAL_API_KEY")}")) - ) - ) + ChatCompletionProvider.streamed.mistral private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletion.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletion.scala index 81504ee0..91d17760 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletion.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletion.scala @@ -2,7 +2,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionService, OpenAIChatCompletionServiceFactory @@ -14,12 +14,8 @@ import scala.concurrent.Future // requires `OCTOAI_TOKEN` environment variable to be set object OctoMLCreateChatCompletion extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionService = OpenAIChatCompletionServiceFactory( - coreUrl = "https://text.octoai.run/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("OCTOAI_TOKEN")}")) - ) - ) + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.octoML private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletionStreamed.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletionStreamed.scala index ecb99790..833cddbb 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletionStreamed.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/OctoMLCreateChatCompletionStreamed.scala @@ -3,7 +3,7 @@ package io.cequence.openaiscala.examples.nonopenai import akka.stream.scaladsl.Sink import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionStreamedServiceExtra, OpenAIChatCompletionStreamedServiceFactory @@ -17,12 +17,7 @@ object OctoMLCreateChatCompletionStreamed extends ExampleBase[OpenAIChatCompletionStreamedServiceExtra] { override val service: OpenAIChatCompletionStreamedServiceExtra = - OpenAIChatCompletionStreamedServiceFactory( - coreUrl = "https://text.octoai.run/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("OCTOAI_TOKEN")}")) - ) - ) + ChatCompletionProvider.streamed.octoML private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/TogetherAICreateChatCompletion.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/TogetherAICreateChatCompletion.scala index 6300bbdf..3a2cb1c2 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/TogetherAICreateChatCompletion.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/TogetherAICreateChatCompletion.scala @@ -2,7 +2,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.domain._ import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.{ OpenAIChatCompletionService, OpenAIChatCompletionServiceFactory @@ -16,12 +16,8 @@ import scala.concurrent.Future */ object TogetherAICreateChatCompletion extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionService = OpenAIChatCompletionServiceFactory( - coreUrl = "https://api.together.xyz/v1/", - WsRequestContext(authHeaders = - Seq(("Authorization", s"Bearer ${sys.env("TOGETHERAI_API_KEY")}")) - ) - ) + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.togetherAI private val messages = Seq( SystemMessage("You are a helpful assistant."), diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionStreamedWithOpenAIAdapter.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionStreamedWithOpenAIAdapter.scala index 4b0686f8..36a1d636 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionStreamedWithOpenAIAdapter.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionStreamedWithOpenAIAdapter.scala @@ -3,7 +3,7 @@ package io.cequence.openaiscala.examples.nonopenai import akka.stream.scaladsl.Sink import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings import io.cequence.openaiscala.domain.{NonOpenAIModelId, SystemMessage, UserMessage} -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.OpenAIChatCompletionService import io.cequence.openaiscala.service.StreamedServiceTypes.OpenAIChatCompletionStreamedService import io.cequence.openaiscala.vertexai.service.VertexAIServiceFactory @@ -14,7 +14,8 @@ import scala.concurrent.Future object VertexAICreateChatCompletionStreamedWithOpenAIAdapter extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionStreamedService = VertexAIServiceFactory.asOpenAI() + override val service: OpenAIChatCompletionStreamedService = + ChatCompletionProvider.vertexAI private val model = NonOpenAIModelId.gemini_1_5_flash_001 diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionWithOpenAIAdapter.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionWithOpenAIAdapter.scala index a9a27498..e5e23f87 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionWithOpenAIAdapter.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/nonopenai/VertexAICreateChatCompletionWithOpenAIAdapter.scala @@ -2,7 +2,7 @@ package io.cequence.openaiscala.examples.nonopenai import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings import io.cequence.openaiscala.domain.{NonOpenAIModelId, SystemMessage, UserMessage} -import io.cequence.openaiscala.examples.ExampleBase +import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase} import io.cequence.openaiscala.service.OpenAIChatCompletionService import io.cequence.openaiscala.vertexai.service.VertexAIServiceFactory @@ -12,7 +12,8 @@ import scala.concurrent.Future object VertexAICreateChatCompletionWithOpenAIAdapter extends ExampleBase[OpenAIChatCompletionService] { - override val service: OpenAIChatCompletionService = VertexAIServiceFactory.asOpenAI() + override val service: OpenAIChatCompletionService = + ChatCompletionProvider.vertexAI private val model = NonOpenAIModelId.gemini_1_5_pro_001