Skip to content

feat: deepseek anthropic adaptive thinking#1505

Merged
looplj merged 1 commit into
unstablefrom
dev-tmp
Apr 26, 2026
Merged

feat: deepseek anthropic adaptive thinking#1505
looplj merged 1 commit into
unstablefrom
dev-tmp

Conversation

@looplj

@looplj looplj commented Apr 26, 2026

Copy link
Copy Markdown
Owner

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for DeepSeek's thinking blocks within the Anthropic transformer, ensuring assistant messages include a thinking block when thinking is enabled. It also updates the platform configuration to support output_config for DeepSeek and adds comprehensive unit tests. Feedback suggests optimizing the ensureAssistantThinkingBlocks function by moving variable definitions outside the loop and using more efficient slice manipulation techniques.

Comment on lines +39 to +71
func ensureAssistantThinkingBlocks(messages []MessageParam) {
for i, msg := range messages {
if msg.Role != "assistant" {
continue
}
if hasThinkingBlock(msg) {
continue
}

emptyThinking := ""
thinkingBlock := MessageContentBlock{
Type: "thinking",
Thinking: &emptyThinking,
}

if msg.Content.Content != nil {
// Convert simple string content to multiple content with thinking + text
textBlock := MessageContentBlock{
Type: "text",
Text: msg.Content.Content,
}
messages[i].Content = MessageContent{
MultipleContent: []MessageContentBlock{thinkingBlock, textBlock},
}
} else {
// Prepend thinking block to existing multiple content
messages[i].Content.MultipleContent = append(
[]MessageContentBlock{thinkingBlock},
messages[i].Content.MultipleContent...,
)
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ensureAssistantThinkingBlocks function can be optimized by moving the emptyThinking variable definition outside the loop. Additionally, for prepending the thinking block to MultipleContent, using a pre-allocated slice or slices.Insert (if using Go 1.21+) would be more efficient than the current append pattern which creates multiple intermediate slices.

func ensureAssistantThinkingBlocks(messages []MessageParam) {
	emptyThinking := ""
	for i, msg := range messages {
		if msg.Role != "assistant" {
			continue
		}
		if hasThinkingBlock(msg) {
			continue
		}

		thinkingBlock := MessageContentBlock{
			Type:     "thinking",
			Thinking: &emptyThinking,
		}

		if msg.Content.Content != nil {
			// Convert simple string content to multiple content with thinking + text
			textBlock := MessageContentBlock{
				Type: "text",
				Text: msg.Content.Content,
			}
			messages[i].Content = MessageContent{
				MultipleContent: []MessageContentBlock{thinkingBlock, textBlock},
			}
		} else {
			// Prepend thinking block to existing multiple content
			newContent := make([]MessageContentBlock, 0, len(messages[i].Content.MultipleContent)+1)
			newContent = append(newContent, thinkingBlock)
			newContent = append(newContent, messages[i].Content.MultipleContent...)
			messages[i].Content.MultipleContent = newContent
		}
	}
}

@looplj looplj merged commit 383ef93 into unstable Apr 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant