Skip to content

Commit eacb44d

Browse files
committed
Cerebras, Groq, and TogetherAI examples updated to use Llama4 models
1 parent 097f074 commit eacb44d

7 files changed

+79
-7
lines changed

openai-examples/src/main/scala/io/cequence/openaiscala/examples/cerebras/CerebrasCreateChatCompletion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object CerebrasCreateChatCompletion extends ExampleBase[OpenAIChatCompletionServ
2525
)
2626

2727
// private val modelId = NonOpenAIModelId.deepseek_r1_distill_llama_70b
28-
private val modelId = NonOpenAIModelId.llama_3_3_70b
28+
private val modelId = NonOpenAIModelId.cerebras_llama_4_scout_17b_16e_instruct
2929

3030
override protected def run: Future[_] =
3131
service
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package io.cequence.openaiscala.examples.cerebras
2+
3+
import io.cequence.openaiscala.domain._
4+
import io.cequence.openaiscala.domain.settings.GroqCreateChatCompletionSettingsOps._
5+
import io.cequence.openaiscala.domain.settings.{
6+
ChatCompletionResponseFormatType,
7+
CreateChatCompletionSettings,
8+
JsonSchemaDef
9+
}
10+
import io.cequence.openaiscala.examples.{ChatCompletionProvider, ExampleBase}
11+
import io.cequence.openaiscala.service.OpenAIChatCompletionExtra.OpenAIChatCompletionImplicits
12+
import io.cequence.openaiscala.service.OpenAIChatCompletionService
13+
import play.api.libs.json.{JsObject, Json}
14+
15+
import scala.concurrent.Future
16+
17+
/**
18+
* Requires `CEREBRAS_API_KEY` environment variable to be set.
19+
*/
20+
object CerebrasCreateChatCompletionJSON
21+
extends ExampleBase[OpenAIChatCompletionService] {
22+
23+
override val service: OpenAIChatCompletionService = ChatCompletionProvider.cerebras
24+
25+
private val jsonSchema: JsonSchema = JsonSchema.Object(
26+
properties = Seq(
27+
"response" -> JsonSchema.Array(
28+
items = JsonSchema.Object(
29+
properties = Seq(
30+
"city" -> JsonSchema.String(),
31+
"temperature" -> JsonSchema.String(),
32+
"weather" -> JsonSchema.String()
33+
),
34+
required = Seq("city", "temperature", "weather")
35+
)
36+
)
37+
),
38+
required = Seq("response")
39+
)
40+
41+
private val messages = Seq(
42+
SystemMessage("You are a helpful weather assistant that responds in JSON."),
43+
UserMessage("What is the weather like in Norway?")
44+
)
45+
46+
private val modelId = NonOpenAIModelId.cerebras_llama_4_scout_17b_16e_instruct
47+
48+
// TODO: Cerebras should support JSON schema response format (without a conversion to "json mode")
49+
override protected def run: Future[_] =
50+
service
51+
.createChatCompletionWithJSON[JsObject](
52+
messages = messages,
53+
settings = CreateChatCompletionSettings(
54+
model = modelId,
55+
temperature = Some(0.1),
56+
response_format_type = Some(ChatCompletionResponseFormatType.json_schema),
57+
jsonSchema = Some(
58+
JsonSchemaDef(
59+
name = "weather_response",
60+
strict = true,
61+
structure = jsonSchema
62+
)
63+
)
64+
).setMaxCompletionTokens(4000)
65+
)
66+
.map(json => println(Json.prettyPrint(json)))
67+
}

openai-examples/src/main/scala/io/cequence/openaiscala/examples/cerebras/CerebrasCreateChatCompletionStreamed.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object CerebrasCreateChatCompletionStreamed
2525
UserMessage("What is the weather like in Norway?")
2626
)
2727

28-
private val modelId = NonOpenAIModelId.llama3_1_70b
28+
private val modelId = NonOpenAIModelId.cerebras_llama_4_scout_17b_16e_instruct
2929

3030
override protected def run: Future[_] =
3131
service

openai-examples/src/main/scala/io/cequence/openaiscala/examples/groq/GroqCreateChatCompletion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object GroqCreateChatCompletion extends ExampleBase[OpenAIChatCompletionService]
1919
UserMessage("What is the weather like in Norway?")
2020
)
2121

22-
private val modelId = NonOpenAIModelId.llama_4_scout_17b_16e_instruct
22+
private val modelId = NonOpenAIModelId.groq_llama_4_scout_17b_16e_instruct
2323

2424
override protected def run: Future[_] =
2525
service

openai-examples/src/main/scala/io/cequence/openaiscala/examples/groq/GroqCreateChatCompletionJSONWithDeepseekR1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ object GroqCreateChatCompletionJSONWithDeepseekR1
4343
UserMessage("What is the weather like in Norway?")
4444
)
4545

46-
private val modelId = NonOpenAIModelId.deepseek_r1_distill_llama_70b
46+
private val modelId = NonOpenAIModelId.deepseek_r1_distill_qwen_32b // deepseek_r1_distill_llama_70b
4747

4848
override protected def run: Future[_] =
4949
service

openai-examples/src/main/scala/io/cequence/openaiscala/examples/sonar/SonarCreateChatCompletionStreamedWithOpenAIAdapter.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import io.cequence.openaiscala.service.OpenAIChatCompletionStreamedServiceExtra
88

99
import scala.concurrent.Future
1010
import io.cequence.openaiscala.examples.ChatCompletionProvider
11+
import io.cequence.openaiscala.perplexity.service.SonarServiceConsts
1112

1213
// requires `openai-scala-client-stream` as a dependency and `SONAR_API_KEY` environment variable to be set
1314
object SonarCreateChatCompletionStreamedWithOpenAIAdapter
14-
extends ExampleBase[OpenAIChatCompletionStreamedServiceExtra] {
15+
extends ExampleBase[OpenAIChatCompletionStreamedServiceExtra]
16+
with SonarServiceConsts {
1517

1618
override val service: OpenAIChatCompletionStreamedServiceExtra =
1719
ChatCompletionProvider.sonar
@@ -30,7 +32,10 @@ object SonarCreateChatCompletionStreamedWithOpenAIAdapter
3032
settings = CreateChatCompletionSettings(
3133
model = modelId,
3234
temperature = Some(0.01),
33-
max_tokens = Some(512)
35+
max_tokens = Some(512),
36+
extra_params = Map(
37+
includeCitationsInTextResponseParam -> true
38+
)
3439
)
3540
)
3641
.runWith(

openai-examples/src/main/scala/io/cequence/openaiscala/examples/togetherai/TogetherAICreateChatCompletion.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object TogetherAICreateChatCompletion extends ExampleBase[OpenAIChatCompletionSe
2121

2222
// deepseek_ai_deepseek_r1_distill_llama_70b_free // deepseek_ai_deepseek_v3
2323
private val modelId =
24-
NonOpenAIModelId.llama_4_maverick_17B_128E_instruct_fp8
24+
NonOpenAIModelId.meta_llama_llama_4_maverick_17b_128e_instruct_fp8
2525

2626
override protected def run: Future[_] =
2727
service

0 commit comments

Comments
 (0)