Anthropic | Citations

Quando os documentos são enviados com citações habilitadas, a resposta do Claude inclui referências de volta a partes específicas dos documentos de origem. Isso permite que você verifique afirmações e rastreie informações até sua origem.

Habilitando Citações

Defina CitationsEnabled como True nos blocos de conteúdo de documento. As citações devem estar habilitadas em TODOS ou em NENHUM dos documentos de uma requisição.


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

Lendo Citations da Resposta

Os blocos de conteúdo de texto na resposta podem conter um array Citations com referências de origem.


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;

Tipos de citação