当启用引用功能发送文档时,Claude 的响应会包含对源文档特定部分的回溯引用。这让您可以验证声明并追溯信息来源。
在文档内容块上将 CitationsEnabled 设置为 True。引用必须在请求中的所有文档上全部启用或全部禁用。
oDocBlock := TsgcAnthropicClass_Request_Content_Block.Create;
oDocBlock.ContentType := 'document';
oDocBlock.SourceType := 'base64';
oDocBlock.MediaType := 'application/pdf';
oDocBlock.Data := sgcBase64Encode(LoadFileToBytes('report.pdf'));
oDocBlock.CitationsEnabled := True; // Enable citations
响应中的文本内容块可能包含带有源引用的 Citations 数组。
oResponse := Anthropic.CreateMessage(oRequest);
Try
for i := 0 to Length(oResponse.Content) - 1 do
begin
if oResponse.Content[i].ContentType = 'text' then
begin
WriteLn(oResponse.Content[i].Text);
// Process citations
for j := 0 to Length(oResponse.Content[i].Citations) - 1 do
begin
oCitation := oResponse.Content[i].Citations[j];
WriteLn(Format(' Citation [%s]: "%s"',
[oCitation.CitationType, oCitation.CitedText]));
if oCitation.CitationType = 'page_location' then
WriteLn(Format(' Pages %d-%d of "%s"',
[oCitation.StartPageNumber, oCitation.EndPageNumber,
oCitation.DocumentTitle]));
end;
end;
end;
Finally
oResponse.Free;
End;