Skip to content

Commit 860c198

Browse files
Fix deepseek structured output (#1380)
<!-- Thank you for opening a pull request! Please add a brief description of the proposed change here. Also, please tick the appropriate points in the checklist below. --> ## Motivation and Context <!-- Why is this change needed? What problem does it solve? --> [#1298](#1298) ## Breaking Changes <!-- Will users need to update their code or configurations? --> --- #### Type of the changes - [ ] New feature (non-breaking change which adds functionality) - [x] Bug fix (non-breaking change which fixes an issue) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Tests improvement - [ ] Refactoring - [ ] CI/CD changes - [ ] Dependencies update #### Checklist - [x] The pull request has a description of the proposed change - [x] I read the [Contributing Guidelines](https://github.com/JetBrains/koog/blob/main/CONTRIBUTING.md) before opening the pull request - [x] The pull request uses **`develop`** as the base branch - [ ] Tests for the changes have been added - [ ] All new and existing tests passed ##### Additional steps for pull requests adding a new feature - [x] An issue describing the proposed change exists - [ ] The pull request includes a link to the issue - [ ] The change was discussed and approved in the issue - [ ] Docs have been added / updated
1 parent 4f1ae06 commit 860c198

File tree

1 file changed

+10
-1
lines changed
  • prompt/prompt-executor/prompt-executor-clients/prompt-executor-deepseek-client/src/commonMain/kotlin/ai/koog/prompt/executor/clients/deepseek

1 file changed

+10
-1
lines changed

prompt/prompt-executor/prompt-executor-clients/prompt-executor-deepseek-client/src/commonMain/kotlin/ai/koog/prompt/executor/clients/deepseek/DeepSeekLLMClient.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ai.koog.prompt.executor.clients.deepseek.models.DeepSeekModelsResponse
1212
import ai.koog.prompt.executor.clients.openai.base.AbstractOpenAILLMClient
1313
import ai.koog.prompt.executor.clients.openai.base.OpenAIBaseSettings
1414
import ai.koog.prompt.executor.clients.openai.base.OpenAICompatibleToolDescriptorSchemaGenerator
15+
import ai.koog.prompt.executor.clients.openai.base.models.Content
1516
import ai.koog.prompt.executor.clients.openai.base.models.OpenAIMessage
1617
import ai.koog.prompt.executor.clients.openai.base.models.OpenAIResponseFormat
1718
import ai.koog.prompt.executor.clients.openai.base.models.OpenAITool
@@ -94,8 +95,16 @@ public class DeepSeekLLMClient @JvmOverloads constructor(
9495
val deepSeekParams = params.toDeepSeekParams()
9596
val responseFormat = createResponseFormat(params.schema, model)
9697

98+
val preparedMessages = if (params.schema != null) {
99+
// Add a message having the word `JSON` explicitly
100+
// it is required by the deepseek api for structured output
101+
messages + OpenAIMessage.Assistant(Content.Text("Respond with JSON"))
102+
} else {
103+
messages
104+
}
105+
97106
val request = DeepSeekChatCompletionRequest(
98-
messages = messages,
107+
messages = preparedMessages,
99108
model = model.id,
100109
frequencyPenalty = deepSeekParams.frequencyPenalty,
101110
logprobs = deepSeekParams.logprobs,

0 commit comments

Comments
 (0)