-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deepseek provider / models with two examples
- Loading branch information
1 parent
3893656
commit 7637b96
Showing
6 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
.../main/scala/io/cequence/openaiscala/examples/nonopenai/DeepseekCreateChatCompletion.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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.service.OpenAIChatCompletionService | ||
|
||
import scala.concurrent.Future | ||
|
||
/** | ||
* Requires `DEEPSEEK_API_KEY` environment variable to be set. | ||
*/ | ||
object DeepseekCreateChatCompletion extends ExampleBase[OpenAIChatCompletionService] { | ||
|
||
override val service: OpenAIChatCompletionService = ChatCompletionProvider.deepseek | ||
|
||
private val messages = Seq( | ||
SystemMessage("You are a helpful assistant."), | ||
UserMessage("What is the weather like in Norway?") | ||
) | ||
|
||
private val modelId = NonOpenAIModelId.deepseek_chat | ||
|
||
override protected def run: Future[_] = | ||
service | ||
.createChatCompletion( | ||
messages = messages, | ||
settings = CreateChatCompletionSettings( | ||
model = modelId, | ||
temperature = Some(0.1), | ||
max_tokens = Some(1024) | ||
) | ||
) | ||
.map(printMessageContent) | ||
} |
40 changes: 40 additions & 0 deletions
40
...ala/io/cequence/openaiscala/examples/nonopenai/DeepseekCreateChatCompletionStreamed.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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 | ||
|
||
import scala.concurrent.Future | ||
|
||
// requires `openai-scala-client-stream` as a dependency and `DEEPSEEK_API_KEY` environment variable to be set | ||
object DeepseekCreateChatCompletionStreamed | ||
extends ExampleBase[OpenAIChatCompletionStreamedServiceExtra] { | ||
|
||
override val service: OpenAIChatCompletionStreamedServiceExtra = ChatCompletionProvider.deepseekBeta | ||
|
||
private val messages = Seq( | ||
SystemMessage("You are a helpful assistant."), | ||
UserMessage("What is the weather like in Norway?") | ||
) | ||
|
||
private val modelId = NonOpenAIModelId.deepseek_chat | ||
|
||
override protected def run: Future[_] = | ||
service | ||
.createChatCompletionStreamed( | ||
messages = messages, | ||
settings = CreateChatCompletionSettings( | ||
model = modelId, | ||
temperature = Some(0.01), | ||
max_tokens = Some(512) | ||
) | ||
) | ||
.runWith( | ||
Sink.foreach { completion => | ||
val content = completion.choices.headOption.flatMap(_.delta.content) | ||
print(content.getOrElse("")) | ||
} | ||
) | ||
} |