Skip to content

Commit

Permalink
Chat completion o1 example
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbanda committed Jan 3, 2025
1 parent ceda68c commit 1ad4529
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object ChatCompletionSettingsConversions {
settings.response_format_type.isDefined && settings.response_format_type.get != ChatCompletionResponseFormatType.text,
_.copy(response_format_type = None),
Some(
"O1 models don't support json object/schema response format, converting to None."
"O1 (preview) models don't support json object/schema response format, converting to None."
),
warning = true
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.cequence.openaiscala.examples

import io.cequence.openaiscala.domain._
import io.cequence.openaiscala.domain.settings.{
ChatCompletionResponseFormatType,
CreateChatCompletionSettings
}

import scala.concurrent.Future

object CreateChatCompletionWithO1 extends Example {

private val messages = Seq(
// system message still works for O1 models but moving forward DeveloperMessage should be used instead
SystemMessage("You are a helpful weather assistant who likes to make jokes."),
UserMessage("What is the weather like in Norway per major cities? Answer in json format.")
)

override protected def run: Future[_] =
service
.createChatCompletion(
messages = messages,
settings = CreateChatCompletionSettings(
model = ModelId.o1,
temperature = Some(0.1),
response_format_type = Some(ChatCompletionResponseFormatType.json_object),
max_tokens = Some(4000)
)
)
.map { content =>
printMessageContent(content)
}
}

0 comments on commit 1ad4529

Please sign in to comment.