Genişletilmiş düşünme, Claude'a bir yanıt sağlamadan önce karmaşık problemleri adım adım düşünme yeteneği verir. Etkinleştirildiğinde, Claude matematik, kodlama, analiz ve diğer karmaşık görevler için yanıtların kalitesini artıran dahili akıl yürütme (düşünme blokları) oluşturur.
Convenience yöntemini kullanarak genişletilmiş düşünme etkin olarak bir mesaj gönderin. Sıcaklık otomatik olarak 1.0'a ayarlanır (düşünme etkinleştirildiğinde API tarafından gerekir).
Anthropic := TsgcHTTP_API_Anthropic.Create(nil);
Anthropic.AnthropicOptions.ApiKey := 'API_KEY';
WriteLn(Anthropic._CreateMessageWithThinking('claude-sonnet-4-20250514',
'How many r''s are in the word strawberry?', 10000));
Tam kontrol için türlenmiş istek/yanıt sınıflarını kullanın. ThinkingType'ı 'enabled' ve ThinkingBudgetTokens'ı istenen token bütçesine (minimum 1024) ayarlayın. Yanıt, thinking ve text içerik blokları içerir.
Anthropic := TsgcHTTP_API_Anthropic.Create(nil);
Anthropic.AnthropicOptions.ApiKey := 'API_KEY';
oRequest := TsgcAnthropicClass_Request_Messages.Create;
Try
oRequest.Model := 'claude-sonnet-4-20250514';
oRequest.MaxTokens := 16384;
oRequest.ThinkingType := 'enabled';
oRequest.ThinkingBudgetTokens := 10000;
oMessage := TsgcAnthropicClass_Request_Message.Create;
oMessage.Role := 'user';
oMessage.Content := 'Explain the proof that there are infinitely many primes.';
oMessages := oRequest.Messages;
SetLength(oMessages, 1);
oMessages[0] := oMessage;
oRequest.Messages := oMessages;
oResponse := Anthropic.CreateMessage(oRequest);
Try
for i := 0 to Length(oResponse.Content) - 1 do
begin
if oResponse.Content[i].ContentType = 'thinking' then
WriteLn('Thinking: ' + oResponse.Content[i].Thinking)
else if oResponse.Content[i].ContentType = 'text' then
WriteLn('Response: ' + oResponse.Content[i].Text);
end;
Finally
oResponse.Free;
End;
Finally
oMessage.Free;
oRequest.Free;
End;
Çok turlu konuşmalarda extended thinking kullanırken, önceki yanıtlardan gelen thinking ve redacted_thinking blokları konuşmaya geri aktarılmalıdır. Bu blokları dahil etmek için ContentBlocks dizisini kullanın.
// Pass back thinking blocks from a previous response
oBlock := TsgcAnthropicClass_Request_Content_Block.Create;
oBlock.ContentType := 'thinking';
oBlock.Text := oPrevThinkingBlock.Thinking; // thinking text
oBlock.Signature := oPrevThinkingBlock.Signature; // signature string
// Pass back redacted thinking blocks
oBlock := TsgcAnthropicClass_Request_Content_Block.Create;
oBlock.ContentType := 'redacted_thinking';
oBlock.Data := oPrevRedactedBlock.Data;