From 452eaafaa3ad60c6da4ff5575a14e8504892a0b7 Mon Sep 17 00:00:00 2001 From: Peter Banda Date: Tue, 17 Sep 2024 14:28:44 +0200 Subject: [PATCH] Special handling for O1 models (chat completion) --- openai-count-tokens/README.md | 2 +- .../openaiscala/examples/CreateChatCompletion.scala | 8 ++++---- .../scala/io/cequence/openaiscala/examples/Example.scala | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/openai-count-tokens/README.md b/openai-count-tokens/README.md index 011e013b..30cedccb 100755 --- a/openai-count-tokens/README.md +++ b/openai-count-tokens/README.md @@ -12,7 +12,7 @@ The currently supported Scala versions are **2.12, 2.13**, and **3**. To pull the library you have to add the following dependency to your *build.sbt* ``` -"io.cequence" %% "openai-scala-count-tokens" % "1.0.0" +"io.cequence" %% "openai-scala-count-tokens" % "1.1.0" ``` or to *pom.xml* (if you use maven) diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/CreateChatCompletion.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/CreateChatCompletion.scala index 099232d0..8da2c72d 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/CreateChatCompletion.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/CreateChatCompletion.scala @@ -1,6 +1,6 @@ package io.cequence.openaiscala.examples -import io.cequence.openaiscala.domain.settings.CreateChatCompletionSettings +import io.cequence.openaiscala.domain.settings.{ChatCompletionResponseFormatType, CreateChatCompletionSettings} import io.cequence.openaiscala.domain._ import scala.concurrent.Future @@ -8,7 +8,7 @@ import scala.concurrent.Future object CreateChatCompletion extends Example { private val messages = Seq( - SystemMessage("You are a helpful assistant."), + SystemMessage("You are a helpful weather assistant."), UserMessage("What is the weather like in Norway?") ) @@ -17,9 +17,9 @@ object CreateChatCompletion extends Example { .createChatCompletion( messages = messages, settings = CreateChatCompletionSettings( - model = ModelId.gpt_4o_2024_05_13, + model = ModelId.o1_mini, temperature = Some(0), - max_tokens = Some(100) + max_tokens = Some(4000) ) ) .map { content => diff --git a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/Example.scala b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/Example.scala index ec290c21..6a5124b7 100644 --- a/openai-examples/src/main/scala/io/cequence/openaiscala/examples/Example.scala +++ b/openai-examples/src/main/scala/io/cequence/openaiscala/examples/Example.scala @@ -40,4 +40,7 @@ trait ExampleBase[T <: CloseableService] { protected def printMessageContent(response: ChatCompletionResponse): Unit = println(response.choices.head.message.content) + + protected def messageContent(response: ChatCompletionResponse): String = + response.choices.head.message.content }