Haijun Platform Docs
EN

Haijun dapat memberikan kutipan terperinci saat menjawab pertanyaan tentang dokumen, membantu Anda melacak dan memverifikasi sumber di balik setiap respons.

Semua model aktif mendukung kutipan.

Tip: Bagikan umpan balik dan saran Anda tentang fitur kutipan menggunakan formulir umpan balik kutipan.

Contoh berikut menunjukkan cara mengaktifkan kutipan pada dokumen teks biasa dengan Messages API:

bash
  curl https://haijun.my.id/v1/messages \
    -H "content-type: application/json" \
    -H "x-api-key: $JUGLOW_API_KEY" \
    -H "juglow-version: 2023-06-01" \
    -d '{
      "model": "haijun-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "document",
              "source": {
                "type": "text",
                "media_type": "text/plain",
                "data": "The grass is green. The sky is blue."
              },
              "title": "My Document",
              "context": "This is a trustworthy document.",
              "citations": {"enabled": true}
            },
            {
              "type": "text",
              "text": "What color is the grass and sky?"
            }
          ]
        }
      ]
    }'
bash
  ant messages create <<'YAML'
  model: haijun-opus-5-5
  max_tokens: 1024
  messages:
    - role: user
      content:
        - type: document
          source:
            type: text
            media_type: text/plain
            data: The grass is green. The sky is blue.
          title: My Document
          context: This is a trustworthy document.
          citations:
            enabled: true
        - type: text
          text: What color is the grass and sky?
  YAML
python
  client = juglow.Juglow()

  response = client.messages.create(
      model="haijun-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document",
                      "source": {
                          "type": "text",
                          "media_type": "text/plain",
                          "data": "The grass is green. The sky is blue.",
                      },
                      "title": "My Document",
                      "context": "This is a trustworthy document.",
                      "citations": {"enabled": True},
                  },
                  {"type": "text", "text": "What color is the grass and sky?"},
              ],
          }
      ],
  )
  print(response)
typescript
  const client = new Juglow();

  const response = await client.messages.create({
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "text",
              media_type: "text/plain",
              data: "The grass is green. The sky is blue."
            },
            title: "My Document",
            context: "This is a trustworthy document.",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "What color is the grass and sky?"
          }
        ]
      }
    ]
  });
  console.log(response);
csharp
  var client = new JuglowClient();

  var response = await client.Messages.Create(
      new()
      {
          Model = Model.HaijunOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new()
              {
                  Role = Role.User,
                  Content = new MessageParamContent(new List<ContentBlockParam>
                  {
                      new ContentBlockParam(new DocumentBlockParam(
                          new DocumentBlockParamSource(new PlainTextSource()
                          {
                              Data = "The grass is green. The sky is blue.",
                          })
                      )
                      {
                          Title = "My Document",
                          Context = "This is a trustworthy document.",
                          Citations = new CitationsConfigParam { Enabled = true },
                      }),
                      new ContentBlockParam(new TextBlockParam("What color is the grass and sky?")),
                  }),
              },
          ],
      }
  );

  Console.WriteLine(response);
go
  client := juglow.NewClient()

  response, err := client.Messages.New(context.TODO(), juglow.MessageNewParams{
  	Model:     juglow.ModelHaijunOpus5_5,
  	MaxTokens: 1024,
  	Messages: []juglow.MessageParam{
  		juglow.NewUserMessage(
  			juglow.ContentBlockParamUnion{
  				OfDocument: &juglow.DocumentBlockParam{
  					Source: juglow.DocumentBlockParamSourceUnion{
  						OfText: &juglow.PlainTextSourceParam{
  							Data: "The grass is green. The sky is blue.",
  						},
  					},
  					Title:     juglow.String("My Document"),
  					Context:   juglow.String("This is a trustworthy document."),
  					Citations: juglow.CitationsConfigParam{Enabled: juglow.Bool(true)},
  				},
  			},
  			juglow.NewTextBlock("What color is the grass and sky?"),
  		),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response)
java
  JuglowClient client = JuglowOkHttpClient.fromEnv();

  PlainTextSource source = PlainTextSource.builder()
      .data("The grass is green. The sky is blue.")
      .build();

  DocumentBlockParam documentParam = DocumentBlockParam.builder()
      .source(source)
      .title("My Document")
      .context("This is a trustworthy document.")
      .citations(CitationsConfigParam.builder().enabled(true).build())
      .build();

  TextBlockParam textBlockParam = TextBlockParam.builder()
      .text("What color is the grass and sky?")
      .build();

  MessageCreateParams params = MessageCreateParams.builder()
      .model(Model.HAIJUN_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessageOfBlockParams(
          List.of(
              ContentBlockParam.ofDocument(documentParam),
              ContentBlockParam.ofText(textBlockParam)
          )
      )
      .build();

  Message message = client.messages().create(params);
  System.out.println(message);
php
  $client = new Client();

  $response = $client->messages->create(
      maxTokens: 1024,
      messages: [
          [
              'role' => 'user',
              'content' => [
                  [
                      'type' => 'document',
                      'source' => [
                          'type' => 'text',
                          'media_type' => 'text/plain',
                          'data' => 'The grass is green. The sky is blue.',
                      ],
                      'title' => 'My Document',
                      'context' => 'This is a trustworthy document.',
                      'citations' => ['enabled' => true],
                  ],
                  [
                      'type' => 'text',
                      'text' => 'What color is the grass and sky?',
                  ],
              ],
          ],
      ],
      model: 'haijun-opus-5-5',
  );

  echo json_encode($response, JSON_PRETTY_PRINT);
ruby
  client = Juglow::Client.new

  response = client.messages.create(
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "text",
              media_type: "text/plain",
              data: "The grass is green. The sky is blue."
            },
            title: "My Document",
            context: "This is a trustworthy document.",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "What color is the grass and sky?"
          }
        ]
      }
    ]
  )

  puts response

Tip: Perbandingan dengan pendekatan berbasis prompt Dibandingkan dengan meminta Haijun untuk mengutip sumber, fitur kutipan menawarkan keuntungan berikut: * Penghematan biaya: Jika pendekatan berbasis prompt Anda meminta Haijun untuk menghasilkan kutipan langsung, Anda mungkin melihat penghematan biaya karena cited_text tidak dihitung terhadap token output Anda. * Keandalan kutipan yang lebih baik: Karena API mengurai kutipan ke dalam format respons yang dijelaskan di bagian berikut dan mengekstrak cited_text secara langsung, kutipan dijamin berisi penunjuk yang valid ke dokumen yang disediakan. * Kualitas kutipan yang ditingkatkan: Dalam evaluasi Juglow, fitur kutipan secara signifikan lebih mungkin mengutip kutipan yang paling relevan dari dokumen dibandingkan pendekatan yang murni berbasis prompt.


Cara kerja kutipan

Integrasikan kutipan dengan Haijun dalam langkah-langkah berikut:

  1. Sediakan dokumen dan aktifkan kutipan
  • Atur citations.enabled=true pada setiap dokumen Anda. Saat ini, kutipan harus diaktifkan pada semua atau tidak sama sekali dari dokumen dalam sebuah permintaan.
  • Hanya kutipan teks yang saat ini didukung. Kutipan gambar belum memungkinkan.
  1. Dokumen diproses
  • Konten dokumen "dipotong" (chunked) untuk menentukan granularitas minimum dari kutipan yang mungkin. Misalnya, pemotongan kalimat memungkinkan Haijun mengutip satu kalimat atau merangkai beberapa kalimat berurutan untuk mengutip paragraf atau bagian yang lebih panjang.
  • Untuk PDF: Teks diekstrak seperti yang dijelaskan dalam dukungan PDF dan konten dipotong menjadi kalimat. Mengutip gambar dari PDF saat ini tidak didukung.
  • Untuk dokumen teks biasa: Konten dipotong menjadi kalimat yang dapat dikutip.
  • Untuk dokumen konten kustom: Blok konten yang Anda sediakan digunakan apa adanya dan tidak ada pemotongan lebih lanjut yang dilakukan.
  1. Haijun memberikan respons yang dikutip
  • Respons sekarang dapat mencakup beberapa blok teks di mana setiap blok teks dapat berisi klaim yang dibuat Haijun dan daftar kutipan yang mendukung klaim tersebut.
  • Kutipan merujuk ke lokasi tertentu dalam dokumen sumber. Format kutipan ini bergantung pada jenis dokumen yang dikutip.
  • Untuk PDF: Kutipan mencakup rentang nomor halaman (diindeks mulai dari 1).
  • Untuk dokumen teks biasa: Kutipan mencakup rentang indeks karakter (diindeks mulai dari 0).
  • Untuk dokumen konten kustom: Kutipan mencakup rentang indeks blok konten (diindeks mulai dari 0) yang sesuai dengan daftar konten asli yang disediakan.
  • Indeks dokumen disediakan untuk menunjukkan sumber referensi dan diindeks mulai dari 0 sesuai dengan daftar semua dokumen dalam permintaan asli Anda.

Tip: Pemotongan otomatis vs konten kustom Secara default, dokumen teks biasa dan PDF secara otomatis dipotong menjadi kalimat. Jika Anda memerlukan kontrol lebih atas granularitas kutipan (misalnya, untuk poin-poin atau transkrip), gunakan dokumen konten kustom sebagai gantinya. Lihat Jenis dokumen untuk detail lebih lanjut. Misalnya, jika Anda ingin Haijun dapat mengutip kalimat tertentu dari potongan RAG Anda, Anda harus menempatkan setiap potongan RAG ke dalam dokumen teks biasa. Jika tidak, jika Anda tidak ingin ada pemotongan lebih lanjut yang dilakukan, atau jika Anda ingin menyesuaikan pemotongan tambahan apa pun, Anda dapat menempatkan potongan RAG ke dalam dokumen konten kustom.

Konten yang dapat dikutip versus tidak dapat dikutip

  • Teks yang ditemukan dalam konten source dokumen dapat dikutip.
  • title dan context adalah bidang opsional yang diteruskan ke model tetapi tidak digunakan untuk konten yang dikutip.
  • title terbatas panjangnya, sehingga bidang context berguna untuk menyimpan metadata dokumen sebagai teks atau JSON yang distringifikasi.

Indeks kutipan

  • Indeks dokumen diindeks mulai dari 0 dari daftar semua blok konten dokumen dalam permintaan (mencakup semua pesan).
  • Indeks karakter diindeks mulai dari 0 dengan indeks akhir eksklusif.
  • Nomor halaman diindeks mulai dari 1 dengan nomor halaman akhir eksklusif.
  • Indeks blok konten diindeks mulai dari 0 dengan indeks akhir eksklusif dari daftar content yang disediakan dalam dokumen konten kustom.

Biaya token

  • Mengaktifkan kutipan menyebabkan sedikit peningkatan token input karena penambahan prompt sistem dan pemotongan dokumen.
  • Namun, fitur kutipan sangat efisien dengan token output. Secara internal, model menghasilkan kutipan dalam format standar yang kemudian diurai menjadi teks yang dikutip dan indeks lokasi dokumen. Bidang cited_text disediakan untuk kenyamanan dan tidak dihitung terhadap token output.
  • Ketika diteruskan kembali dalam giliran percakapan berikutnya, cited_text juga tidak dihitung terhadap token input.

Kompatibilitas fitur

Kutipan bekerja bersama dengan fitur API lainnya termasuk caching prompt, penghitungan token, dan pemrosesan batch.

Warning: Kutipan dan output terstruktur tidak kompatibel Kutipan tidak dapat digunakan bersama dengan output terstruktur. Jika Anda mengaktifkan kutipan pada dokumen yang disediakan pengguna (blok document atau blok search_result) dan juga menyertakan parameter output_config.format (atau parameter output_format yang sudah usang), API mengembalikan error 400. Ini karena kutipan memerlukan penyisipan blok kutipan dengan output teks, yang tidak kompatibel dengan batasan skema JSON yang ketat dari output terstruktur.

Menggunakan caching prompt dengan kutipan

Kutipan dan caching prompt dapat digunakan bersama secara efektif.

Blok kutipan yang dihasilkan dalam respons tidak dapat di-cache secara langsung, tetapi dokumen sumber yang dirujuknya dapat di-cache. Untuk mengoptimalkan kinerja, terapkan cache_control pada blok konten dokumen tingkat atas Anda.

bash
  curl https://haijun.my.id/v1/messages \
    -H "content-type: application/json" \
    -H "x-api-key: $JUGLOW_API_KEY" \
    -H "juglow-version: 2023-06-01" \
    -d '{
      "model": "haijun-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "document",
              "source": {
                "type": "text",
                "media_type": "text/plain",
                "data": "This is a very long document with thousands of words..."
              },
              "citations": {"enabled": true},
              "cache_control": {"type": "ephemeral"}
            },
            {
              "type": "text",
              "text": "What does this document say about API features?"
            }
          ]
        }
      ]
    }'
bash
  ant messages create --model haijun-opus-5-5 --max-tokens 1024 <<'YAML'
  messages:
    - role: user
      content:
        - type: document
          source:
            type: text
            media_type: text/plain
            data: This is a very long document with thousands of words...
          citations:
            enabled: true
          cache_control:
            type: ephemeral
        - type: text
          text: What does this document say about API features?
  YAML
python
  client = juglow.Juglow()

  # Konten dokumen panjang (misalnya, dokumentasi teknis)
  long_document = (
      "This is a very long document with thousands of words..." + " ... " * 1000
  )  # Minimum cacheable length

  response = client.messages.create(
      model="haijun-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document",
                      "source": {
                          "type": "text",
                          "media_type": "text/plain",
                          "data": long_document,
                      },
                      "citations": {"enabled": True},
                      "cache_control": {
                          "type": "ephemeral"
                      },  # Cache the document content
                  },
                  {
                      "type": "text",
                      "text": "What does this document say about API features?",
                  },
              ],
          }
      ],
  )
  print(response)
typescript
  const client = new Juglow();

  // Konten dokumen panjang (misalnya, dokumentasi teknis)
  const longDocument =
    "This is a very long document with thousands of words..." + " ... ".repeat(1000); // Minimum cacheable length

  const response = await client.messages.create({
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "text",
              media_type: "text/plain",
              data: longDocument
            },
            citations: { enabled: true },
            cache_control: { type: "ephemeral" } // Cache the document content
          },
          {
            type: "text",
            text: "What does this document say about API features?"
          }
        ]
      }
    ]
  });
  console.log(response);
csharp
  var client = new JuglowClient();

  // Konten dokumen panjang (misalnya, dokumentasi teknis)
  var longDocument =
      "This is a very long document with thousands of words..."
      + string.Concat(Enumerable.Repeat(" ... ", 1000)); // Minimum cacheable length

  var response = await client.Messages.Create(
      new()
      {
          Model = Model.HaijunOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new()
              {
                  Role = Role.User,
                  Content = new MessageParamContent(new List<ContentBlockParam>
                  {
                      new ContentBlockParam(new DocumentBlockParam(
                          new DocumentBlockParamSource(new PlainTextSource() { Data = longDocument })
                      )
                      {
                          Citations = new CitationsConfigParam { Enabled = true },
                          CacheControl = new CacheControlEphemeral(), // Cache the document content
                      }),
                      new ContentBlockParam(new TextBlockParam("What does this document say about API features?")),
                  }),
              },
          ],
      }
  );

  Console.WriteLine(response);
go
  client := juglow.NewClient()

  // Konten dokumen panjang (misalnya, dokumentasi teknis)
  longDocument := "This is a very long document with thousands of words..." +
  	strings.Repeat(" ... ", 1000) // Minimum cacheable length

  response, err := client.Messages.New(context.TODO(), juglow.MessageNewParams{
  	Model:     juglow.ModelHaijunOpus5_5,
  	MaxTokens: 1024,
  	Messages: []juglow.MessageParam{
  		juglow.NewUserMessage(
  			juglow.ContentBlockParamUnion{
  				OfDocument: &juglow.DocumentBlockParam{
  					Source: juglow.DocumentBlockParamSourceUnion{
  						OfText: &juglow.PlainTextSourceParam{Data: longDocument},
  					},
  					Citations:    juglow.CitationsConfigParam{Enabled: juglow.Bool(true)},
  					CacheControl: juglow.NewCacheControlEphemeralParam(), // Cache the document content
  				},
  			},
  			juglow.NewTextBlock("What does this document say about API features?"),
  		),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response)
java
  JuglowClient client = JuglowOkHttpClient.fromEnv();

  // Konten dokumen panjang (misalnya, dokumentasi teknis)
  String longDocument =
      "This is a very long document with thousands of words..."
          + " ... ".repeat(1000); // Minimum cacheable length

  DocumentBlockParam documentParam = DocumentBlockParam.builder()
      .source(PlainTextSource.builder().data(longDocument).build())
      .citations(CitationsConfigParam.builder().enabled(true).build())
      .cacheControl(CacheControlEphemeral.builder().build()) // Cache the document content
      .build();

  TextBlockParam textBlockParam = TextBlockParam.builder()
      .text("What does this document say about API features?")
      .build();

  MessageCreateParams params = MessageCreateParams.builder()
      .model(Model.HAIJUN_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessageOfBlockParams(
          List.of(
              ContentBlockParam.ofDocument(documentParam),
              ContentBlockParam.ofText(textBlockParam)
          )
      )
      .build();

  Message message = client.messages().create(params);
  System.out.println(message);
php
  $client = new Client();

  // Konten dokumen panjang (misalnya, dokumentasi teknis)
  $longDocument =
      'This is a very long document with thousands of words...'
      . str_repeat(' ... ', 1000); // Minimum cacheable length

  $response = $client->messages->create(
      maxTokens: 1024,
      messages: [
          [
              'role' => 'user',
              'content' => [
                  [
                      'type' => 'document',
                      'source' => [
                          'type' => 'text',
                          'media_type' => 'text/plain',
                          'data' => $longDocument,
                      ],
                      'citations' => ['enabled' => true],
                      'cache_control' => ['type' => 'ephemeral'], // Cache the document content
                  ],
                  [
                      'type' => 'text',
                      'text' => 'What does this document say about API features?',
                  ],
              ],
          ],
      ],
      model: 'haijun-opus-5-5',
  );

  echo json_encode($response, JSON_PRETTY_PRINT);
ruby
  client = Juglow::Client.new

  # Konten dokumen panjang (misalnya, dokumentasi teknis)
  long_document =
    "This is a very long document with thousands of words..." +
    " ... " * 1000 # Minimum cacheable length

  response = client.messages.create(
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "text",
              media_type: "text/plain",
              data: long_document
            },
            citations: { enabled: true },
            cache_control: { type: "ephemeral" } # Cache the document content
          },
          {
            type: "text",
            text: "What does this document say about API features?"
          }
        ]
      }
    ]
  )

  puts response

Dalam contoh ini:

  • Konten dokumen di-cache menggunakan cache_control pada blok dokumen.
  • Kutipan diaktifkan pada dokumen.
  • Haijun dapat menghasilkan respons dengan kutipan sambil memanfaatkan konten dokumen yang di-cache.
  • Permintaan berikutnya yang menggunakan dokumen yang sama memanfaatkan konten yang di-cache.

Jenis dokumen

Memilih jenis dokumen

Tiga jenis dokumen didukung untuk kutipan. Dokumen dapat disediakan langsung dalam pesan (base64, teks, atau URL) atau diunggah melalui Files API dan dirujuk dengan file_id:

JenisTerbaik untukPemotonganFormat kutipan
Teks biasaDokumen teks sederhana, prosaKalimatIndeks karakter (diindeks mulai dari 0)
PDFFile PDF dengan konten teksKalimatNomor halaman (diindeks mulai dari 1)
Konten kustomDaftar, transkrip, pemformatan khusus, kutipan yang lebih granularTidak ada pemotongan tambahanIndeks blok (diindeks mulai dari 0)

Note: Untuk jenis file yang tidak didukung oleh blok document (misalnya, .docx dan .xlsx), konversikan file ke teks biasa dan sertakan konten langsung dalam konten pesan. File yang sudah berupa teks biasa, seperti file .csv dan .md, juga dapat diunggah dengan tipe konten text/plain yang eksplisit. Lihat Bekerja dengan format file lain.

Dokumen teks biasa

Dokumen teks biasa secara otomatis dipotong menjadi kalimat. Anda dapat menyediakannya secara inline atau dengan referensi menggunakan file_id mereka:

Teks inline

Contoh pengantar di bagian atas halaman ini menunjukkan permintaan teks biasa yang lengkap di setiap SDK. Blok dokumen menggunakan sumber text:

json
{
  "type": "document",
  "source": {
    "type": "text",
    "media_type": "text/plain",
    "data": "Plain text content..."
  },
  "title": "Document Title",
  "context": "Context about the document that will not be cited from",
  "citations": { "enabled": true }
}

Files API

Contoh-contoh ini merujuk ke file yang diunggah melalui Files API sebagai sumber document.

bash
  curl -X POST https://haijun.my.id/v1/messages \
    -H "x-api-key: $JUGLOW_API_KEY" \
    -H "juglow-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d @- <<EOF
  {
    "model": "haijun-opus-5-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "document",
            "source": {"type": "file", "file_id": "$FILE_ID"},
            "title": "Document Title",
            "context": "Context about the document that will not be cited from",
            "citations": {"enabled": true}
          },
          {
            "type": "text",
            "text": "Summarize this document."
          }
        ]
      }
    ]
  }
  EOF
bash
  ant messages create <<YAML
  model: haijun-opus-5-5
  max_tokens: 1024
  messages:
    - role: user
      content:
        - type: document
          source:
            type: file
            file_id: $FILE_ID
          title: Document Title
          context: Context about the document that will not be cited from
          citations:
            enabled: true
        - type: text
          text: Summarize this document.
  YAML
python
  cited_response = client.messages.create(
      model="haijun-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document",
                      "source": {"type": "file", "file_id": file_id},
                      "title": "Document Title",
                      "context": "Context about the document that will not be cited from",
                      "citations": {"enabled": True},
                  },
                  {"type": "text", "text": "Summarize this document."},
              ],
          }
      ],
  )
  print(cited_response)
typescript
  const citedResponse = await client.messages.create({
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: { type: "file", file_id: uploaded.id },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true },
          },
          {
            type: "text",
            text: "Summarize this document.",
          },
        ],
      },
    ],
  });
  console.log(citedResponse);
csharp
  var citedResponse = await client.Messages.Create(
      new MessageCreateParams
      {
          Model = Model.HaijunOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new MessageParam
              {
                  Role = Role.User,
                  Content = new List<ContentBlockParam>
                  {
                      new DocumentBlockParam
                      {
                          Source = new FileDocumentSource { FileID = fileId },
                          Title = "Document Title",
                          Context = "Context about the document that will not be cited from",
                          Citations = new CitationsConfigParam { Enabled = true },
                      },
                      new TextBlockParam { Text = "Summarize this document." },
                  }
              }
          ]
      });

  Console.WriteLine(citedResponse);
go
  citedMsg, err := client.Messages.New(context.Background(),
  	juglow.MessageNewParams{
  		Model:     juglow.ModelHaijunOpus5_5,
  		MaxTokens: 1024,
  		Messages: []juglow.MessageParam{
  			juglow.NewUserMessage(
  				juglow.ContentBlockParamUnion{
  					OfDocument: &juglow.DocumentBlockParam{
  						Source: juglow.DocumentBlockParamSourceUnion{
  							OfFile: &juglow.FileDocumentSourceParam{FileID: fileID},
  						},
  						Title:     juglow.String("Document Title"),
  						Context:   juglow.String("Context about the document that will not be cited from"),
  						Citations: juglow.CitationsConfigParam{Enabled: juglow.Bool(true)},
  					},
  				},
  				juglow.NewTextBlock("Summarize this document."),
  			),
  		},
  	})
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(citedMsg)
java
  MessageCreateParams citedParams = MessageCreateParams.builder()
      .model(Model.HAIJUN_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessageOfBlockParams(List.of(
          ContentBlockParam.ofDocument(DocumentBlockParam.builder()
              .fileSource(fileId)
              .title("Document Title")
              .context("Context about the document that will not be cited from")
              .citations(CitationsConfigParam.builder().enabled(true).build())
              .build()),
          ContentBlockParam.ofText(TextBlockParam.builder()
              .text("Summarize this document.")
              .build())
      ))
      .build();

  Message citedMessage = client.messages().create(citedParams);
  System.out.println(citedMessage);
php
  $citedResponse = $client->messages->create(
      maxTokens: 1024,
      messages: [
          [
              'role' => 'user',
              'content' => [
                  [
                      'type' => 'document',
                      'source' => ['type' => 'file', 'fileID' => $fileId],
                      'title' => 'Document Title',
                      'context' => 'Context about the document that will not be cited from',
                      'citations' => ['enabled' => true],
                  ],
                  ['type' => 'text', 'text' => 'Summarize this document.'],
              ],
          ],
      ],
      model: 'haijun-opus-5-5',
  );

  echo $citedResponse;
ruby
  cited_response = client.messages.create(
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: { type: "file", file_id: file_id },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  )

  puts cited_response

Contoh kutipan teks biasa

json
  {
    "type": "char_location",
    "cited_text": "The exact text being cited", // not counted toward output tokens
    "document_index": 0,
    "document_title": "Document Title",
    "start_char_index": 0, // 0-indexed
    "end_char_index": 50 // exclusive
  }

Dokumen PDF

Dokumen PDF dapat disediakan sebagai data yang dikodekan base64, URL, atau dengan file_id. Teks PDF diekstrak dan dipotong menjadi kalimat. Karena kutipan gambar belum didukung, PDF yang merupakan hasil pindaian dokumen dan tidak mengandung teks yang dapat diekstrak tidak dapat dikutip.

Base64

bash
  PDF_BASE64=$(base64 /path/to/document.pdf | tr -d '\n')

  curl https://haijun.my.id/v1/messages \
    -H "content-type: application/json" \
    -H "x-api-key: $JUGLOW_API_KEY" \
    -H "juglow-version: 2023-06-01" \
    -d '{
      "model": "haijun-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "document",
              "source": {
                "type": "base64",
                "media_type": "application/pdf",
                "data": "'"$PDF_BASE64"'"
              },
              "title": "Document Title",
              "context": "Context about the document that will not be cited from",
              "citations": {"enabled": true}
            },
            {
              "type": "text",
              "text": "Summarize this document."
            }
          ]
        }
      ]
    }'
bash
  ant messages create <<'YAML'
  model: haijun-opus-5-5
  max_tokens: 1024
  messages:
    - role: user
      content:
        - type: document
          source:
            type: base64
            media_type: application/pdf
            data: "@/path/to/document.pdf"
          title: Document Title
          context: Context about the document that will not be cited from
          citations:
            enabled: true
        - type: text
          text: Summarize this document.
  YAML
python
  client = juglow.Juglow()

  pdf_base64 = base64.standard_b64encode(
      pathlib.Path("/path/to/document.pdf").read_bytes()
  ).decode()

  response = client.messages.create(
      model="haijun-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document",
                      "source": {
                          "type": "base64",
                          "media_type": "application/pdf",
                          "data": pdf_base64,
                      },
                      "title": "Document Title",
                      "context": "Context about the document that will not be cited from",
                      "citations": {"enabled": True},
                  },
                  {"type": "text", "text": "Summarize this document."},
              ],
          }
      ],
  )
  print(response)
typescript
  const client = new Juglow();

  const pdfBase64 = Buffer.from(await readFile("/path/to/document.pdf")).toString("base64");

  const response = await client.messages.create({
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "base64",
              media_type: "application/pdf",
              data: pdfBase64
            },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  });
  console.log(response);
csharp
  var client = new JuglowClient();

  var pdfBase64 = Convert.ToBase64String(await File.ReadAllBytesAsync("/path/to/document.pdf"));

  var response = await client.Messages.Create(
      new()
      {
          Model = Model.HaijunOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new()
              {
                  Role = Role.User,
                  Content = new MessageParamContent(new List<ContentBlockParam>
                  {
                      new ContentBlockParam(new DocumentBlockParam(
                          new DocumentBlockParamSource(new Base64PdfSource() { Data = pdfBase64 })
                      )
                      {
                          Title = "Document Title",
                          Context = "Context about the document that will not be cited from",
                          Citations = new CitationsConfigParam { Enabled = true },
                      }),
                      new ContentBlockParam(new TextBlockParam("Summarize this document.")),
                  }),
              },
          ],
      }
  );

  Console.WriteLine(response);
go
  client := juglow.NewClient()

  pdfBytes, err := os.ReadFile("/path/to/document.pdf")
  if err != nil {
  	log.Fatal(err)
  }
  pdfBase64 := base64.StdEncoding.EncodeToString(pdfBytes)

  response, err := client.Messages.New(context.TODO(), juglow.MessageNewParams{
  	Model:     juglow.ModelHaijunOpus5_5,
  	MaxTokens: 1024,
  	Messages: []juglow.MessageParam{
  		juglow.NewUserMessage(
  			juglow.ContentBlockParamUnion{
  				OfDocument: &juglow.DocumentBlockParam{
  					Source: juglow.DocumentBlockParamSourceUnion{
  						OfBase64: &juglow.Base64PDFSourceParam{
  							Data: pdfBase64,
  						},
  					},
  					Title:     juglow.String("Document Title"),
  					Context:   juglow.String("Context about the document that will not be cited from"),
  					Citations: juglow.CitationsConfigParam{Enabled: juglow.Bool(true)},
  				},
  			},
  			juglow.NewTextBlock("Summarize this document."),
  		),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response)
java
  JuglowClient client = JuglowOkHttpClient.fromEnv();

  byte[] pdfBytes = Files.readAllBytes(Path.of("/path/to/document.pdf"));
  String pdfBase64 = Base64.getEncoder().encodeToString(pdfBytes);

  DocumentBlockParam documentParam = DocumentBlockParam.builder()
      .source(Base64PdfSource.builder().data(pdfBase64).build())
      .title("Document Title")
      .context("Context about the document that will not be cited from")
      .citations(CitationsConfigParam.builder().enabled(true).build())
      .build();

  MessageCreateParams params = MessageCreateParams.builder()
      .model(Model.HAIJUN_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessageOfBlockParams(
          List.of(
              ContentBlockParam.ofDocument(documentParam),
              ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())
          )
      )
      .build();

  Message message = client.messages().create(params);
  System.out.println(message);
php
  $client = new Client();

  $pdfBase64 = base64_encode(file_get_contents('/path/to/document.pdf'));

  $response = $client->messages->create(
      maxTokens: 1024,
      messages: [
          [
              'role' => 'user',
              'content' => [
                  [
                      'type' => 'document',
                      'source' => [
                          'type' => 'base64',
                          'media_type' => 'application/pdf',
                          'data' => $pdfBase64,
                      ],
                      'title' => 'Document Title',
                      'context' => 'Context about the document that will not be cited from',
                      'citations' => ['enabled' => true],
                  ],
                  [
                      'type' => 'text',
                      'text' => 'Summarize this document.',
                  ],
              ],
          ],
      ],
      model: 'haijun-opus-5-5',
  );

  echo json_encode($response, JSON_PRETTY_PRINT);
ruby
  client = Juglow::Client.new

  pdf_base64 = Base64.strict_encode64(File.binread("/path/to/document.pdf"))

  response = client.messages.create(
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "base64",
              media_type: "application/pdf",
              data: pdf_base64
            },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  )

  puts response

URL

bash
  curl https://haijun.my.id/v1/messages \
    -H "content-type: application/json" \
    -H "x-api-key: $JUGLOW_API_KEY" \
    -H "juglow-version: 2023-06-01" \
    -d '{
      "model": "haijun-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "document",
              "source": {
                "type": "url",
                "url": "https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf"
              },
              "title": "Document Title",
              "context": "Context about the document that will not be cited from",
              "citations": {"enabled": true}
            },
            {
              "type": "text",
              "text": "Summarize this document."
            }
          ]
        }
      ]
    }'
bash
  ant messages create <<'YAML'
  model: haijun-opus-5-5
  max_tokens: 1024
  messages:
    - role: user
      content:
        - type: document
          source:
            type: url
            url: https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf
          title: Document Title
          context: Context about the document that will not be cited from
          citations:
            enabled: true
        - type: text
          text: Summarize this document.
  YAML
python
  client = juglow.Juglow()

  response = client.messages.create(
      model="haijun-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document",
                      "source": {
                          "type": "url",
                          "url": "https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf",
                      },
                      "title": "Document Title",
                      "context": "Context about the document that will not be cited from",
                      "citations": {"enabled": True},
                  },
                  {"type": "text", "text": "Summarize this document."},
              ],
          }
      ],
  )
  print(response)
typescript
  const client = new Juglow();

  const response = await client.messages.create({
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "url",
              url: "https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf"
            },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  });
  console.log(response);
csharp
  var client = new JuglowClient();

  var response = await client.Messages.Create(
      new()
      {
          Model = Model.HaijunOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new()
              {
                  Role = Role.User,
                  Content = new MessageParamContent(new List<ContentBlockParam>
                  {
                      new ContentBlockParam(new DocumentBlockParam(
                          new DocumentBlockParamSource(new UrlPdfSource()
                          {
                              Url = "https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf",
                          })
                      )
                      {
                          Title = "Document Title",
                          Context = "Context about the document that will not be cited from",
                          Citations = new CitationsConfigParam { Enabled = true },
                      }),
                      new ContentBlockParam(new TextBlockParam("Summarize this document.")),
                  }),
              },
          ],
      }
  );

  Console.WriteLine(response);
go
  client := juglow.NewClient()

  response, err := client.Messages.New(context.TODO(), juglow.MessageNewParams{
  	Model:     juglow.ModelHaijunOpus5_5,
  	MaxTokens: 1024,
  	Messages: []juglow.MessageParam{
  		juglow.NewUserMessage(
  			juglow.ContentBlockParamUnion{
  				OfDocument: &juglow.DocumentBlockParam{
  					Source: juglow.DocumentBlockParamSourceUnion{
  						OfURL: &juglow.URLPDFSourceParam{
  							URL: "https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf",
  						},
  					},
  					Title:     juglow.String("Document Title"),
  					Context:   juglow.String("Context about the document that will not be cited from"),
  					Citations: juglow.CitationsConfigParam{Enabled: juglow.Bool(true)},
  				},
  			},
  			juglow.NewTextBlock("Summarize this document."),
  		),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response)
java
  JuglowClient client = JuglowOkHttpClient.fromEnv();

  DocumentBlockParam documentParam = DocumentBlockParam.builder()
      .source(UrlPdfSource.builder()
          .url("https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf")
          .build())
      .title("Document Title")
      .context("Context about the document that will not be cited from")
      .citations(CitationsConfigParam.builder().enabled(true).build())
      .build();

  MessageCreateParams params = MessageCreateParams.builder()
      .model(Model.HAIJUN_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessageOfBlockParams(
          List.of(
              ContentBlockParam.ofDocument(documentParam),
              ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())
          )
      )
      .build();

  Message message = client.messages().create(params);
  System.out.println(message);
php
  $client = new Client();

  $response = $client->messages->create(
      maxTokens: 1024,
      messages: [
          [
              'role' => 'user',
              'content' => [
                  [
                      'type' => 'document',
                      'source' => [
                          'type' => 'url',
                          'url' => 'https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf',
                      ],
                      'title' => 'Document Title',
                      'context' => 'Context about the document that will not be cited from',
                      'citations' => ['enabled' => true],
                  ],
                  [
                      'type' => 'text',
                      'text' => 'Summarize this document.',
                  ],
              ],
          ],
      ],
      model: 'haijun-opus-5-5',
  );

  echo json_encode($response, JSON_PRETTY_PRINT);
ruby
  client = Juglow::Client.new

  response = client.messages.create(
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "url",
              url: "https://assets.juglow.com/m/1cd9d098ac3e6467/original/Haijun-3-Model-Card-October-Addendum.pdf"
            },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  )

  puts response

Files API

Contoh-contoh ini merujuk ke file yang diunggah melalui Files API sebagai sumber document.

bash
  curl -X POST https://haijun.my.id/v1/messages \
    -H "x-api-key: $JUGLOW_API_KEY" \
    -H "juglow-version: 2023-06-01" \
    -H "content-type: application/json" \
    -d @- <<EOF
  {
    "model": "haijun-opus-5-5",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "document",
            "source": {"type": "file", "file_id": "$FILE_ID"},
            "title": "Document Title",
            "context": "Context about the document that will not be cited from",
            "citations": {"enabled": true}
          },
          {
            "type": "text",
            "text": "Summarize this document."
          }
        ]
      }
    ]
  }
  EOF
bash
  ant messages create <<YAML
  model: haijun-opus-5-5
  max_tokens: 1024
  messages:
    - role: user
      content:
        - type: document
          source:
            type: file
            file_id: $FILE_ID
          title: Document Title
          context: Context about the document that will not be cited from
          citations:
            enabled: true
        - type: text
          text: Summarize this document.
  YAML
python
  cited_response = client.messages.create(
      model="haijun-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document",
                      "source": {"type": "file", "file_id": file_id},
                      "title": "Document Title",
                      "context": "Context about the document that will not be cited from",
                      "citations": {"enabled": True},
                  },
                  {"type": "text", "text": "Summarize this document."},
              ],
          }
      ],
  )
  print(cited_response)
typescript
  const citedResponse = await client.messages.create({
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: { type: "file", file_id: uploaded.id },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true },
          },
          {
            type: "text",
            text: "Summarize this document.",
          },
        ],
      },
    ],
  });
  console.log(citedResponse);
csharp
  var citedResponse = await client.Messages.Create(
      new MessageCreateParams
      {
          Model = Model.HaijunOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new MessageParam
              {
                  Role = Role.User,
                  Content = new List<ContentBlockParam>
                  {
                      new DocumentBlockParam
                      {
                          Source = new FileDocumentSource { FileID = fileId },
                          Title = "Document Title",
                          Context = "Context about the document that will not be cited from",
                          Citations = new CitationsConfigParam { Enabled = true },
                      },
                      new TextBlockParam { Text = "Summarize this document." },
                  }
              }
          ]
      });

  Console.WriteLine(citedResponse);
go
  citedMsg, err := client.Messages.New(context.Background(),
  	juglow.MessageNewParams{
  		Model:     juglow.ModelHaijunOpus5_5,
  		MaxTokens: 1024,
  		Messages: []juglow.MessageParam{
  			juglow.NewUserMessage(
  				juglow.ContentBlockParamUnion{
  					OfDocument: &juglow.DocumentBlockParam{
  						Source: juglow.DocumentBlockParamSourceUnion{
  							OfFile: &juglow.FileDocumentSourceParam{FileID: fileID},
  						},
  						Title:     juglow.String("Document Title"),
  						Context:   juglow.String("Context about the document that will not be cited from"),
  						Citations: juglow.CitationsConfigParam{Enabled: juglow.Bool(true)},
  					},
  				},
  				juglow.NewTextBlock("Summarize this document."),
  			),
  		},
  	})
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(citedMsg)
java
  MessageCreateParams citedParams = MessageCreateParams.builder()
      .model(Model.HAIJUN_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessageOfBlockParams(List.of(
          ContentBlockParam.ofDocument(DocumentBlockParam.builder()
              .fileSource(fileId)
              .title("Document Title")
              .context("Context about the document that will not be cited from")
              .citations(CitationsConfigParam.builder().enabled(true).build())
              .build()),
          ContentBlockParam.ofText(TextBlockParam.builder()
              .text("Summarize this document.")
              .build())
      ))
      .build();

  Message citedMessage = client.messages().create(citedParams);
  System.out.println(citedMessage);
php
  $citedResponse = $client->messages->create(
      maxTokens: 1024,
      messages: [
          [
              'role' => 'user',
              'content' => [
                  [
                      'type' => 'document',
                      'source' => ['type' => 'file', 'fileID' => $fileId],
                      'title' => 'Document Title',
                      'context' => 'Context about the document that will not be cited from',
                      'citations' => ['enabled' => true],
                  ],
                  ['type' => 'text', 'text' => 'Summarize this document.'],
              ],
          ],
      ],
      model: 'haijun-opus-5-5',
  );

  echo $citedResponse;
ruby
  cited_response = client.messages.create(
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: { type: "file", file_id: file_id },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  )

  puts cited_response

Contoh kutipan PDF

json
  {
    "type": "page_location",
    "cited_text": "The exact text being cited", // not counted toward output tokens
    "document_index": 0,
    "document_title": "Document Title",
    "start_page_number": 1, // 1-indexed
    "end_page_number": 2 // exclusive
  }

Dokumen konten kustom

Dokumen konten kustom memberi Anda kontrol atas granularitas kutipan. Tidak ada pemotongan tambahan yang dilakukan dan potongan disediakan ke model sesuai dengan blok konten yang disediakan.

bash
  curl https://haijun.my.id/v1/messages \
    -H "content-type: application/json" \
    -H "x-api-key: $JUGLOW_API_KEY" \
    -H "juglow-version: 2023-06-01" \
    -d '{
      "model": "haijun-opus-5-5",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": [
            {
              "type": "document",
              "source": {
                "type": "content",
                "content": [
                  {"type": "text", "text": "First chunk"},
                  {"type": "text", "text": "Second chunk"}
                ]
              },
              "title": "Document Title",
              "context": "Context about the document that will not be cited from",
              "citations": {"enabled": true}
            },
            {
              "type": "text",
              "text": "Summarize this document."
            }
          ]
        }
      ]
    }'
bash
  ant messages create <<'YAML'
  model: haijun-opus-5-5
  max_tokens: 1024
  messages:
    - role: user
      content:
        - type: document
          source:
            type: content
            content:
              - type: text
                text: First chunk
              - type: text
                text: Second chunk
          title: Document Title
          context: Context about the document that will not be cited from
          citations:
            enabled: true
        - type: text
          text: Summarize this document.
  YAML
python
  client = juglow.Juglow()

  response = client.messages.create(
      model="haijun-opus-5-5",
      max_tokens=1024,
      messages=[
          {
              "role": "user",
              "content": [
                  {
                      "type": "document",
                      "source": {
                          "type": "content",
                          "content": [
                              {"type": "text", "text": "First chunk"},
                              {"type": "text", "text": "Second chunk"},
                          ],
                      },
                      "title": "Document Title",
                      "context": "Context about the document that will not be cited from",
                      "citations": {"enabled": True},
                  },
                  {"type": "text", "text": "Summarize this document."},
              ],
          }
      ],
  )
  print(response)
typescript
  const client = new Juglow();

  const response = await client.messages.create({
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "content",
              content: [
                { type: "text", text: "First chunk" },
                { type: "text", text: "Second chunk" }
              ]
            },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  });
  console.log(response);
csharp
  var client = new JuglowClient();

  var response = await client.Messages.Create(
      new()
      {
          Model = Model.HaijunOpus5_5,
          MaxTokens = 1024,
          Messages =
          [
              new()
              {
                  Role = Role.User,
                  Content = new MessageParamContent(new List<ContentBlockParam>
                  {
                      new ContentBlockParam(new DocumentBlockParam(
                          new DocumentBlockParamSource(new ContentBlockSource()
                          {
                              Content = new ContentBlockSourceContent(new List<MessageContentBlockSourceContent>
                              {
                                  new TextBlockParam("First chunk"),
                                  new TextBlockParam("Second chunk"),
                              }),
                          })
                      )
                      {
                          Title = "Document Title",
                          Context = "Context about the document that will not be cited from",
                          Citations = new CitationsConfigParam { Enabled = true },
                      }),
                      new ContentBlockParam(new TextBlockParam("Summarize this document.")),
                  }),
              },
          ],
      }
  );

  Console.WriteLine(response);
go
  client := juglow.NewClient()

  response, err := client.Messages.New(context.TODO(), juglow.MessageNewParams{
  	Model:     juglow.ModelHaijunOpus5_5,
  	MaxTokens: 1024,
  	Messages: []juglow.MessageParam{
  		juglow.NewUserMessage(
  			juglow.ContentBlockParamUnion{
  				OfDocument: &juglow.DocumentBlockParam{
  					Source: juglow.DocumentBlockParamSourceUnion{
  						OfContent: &juglow.ContentBlockSourceParam{
  							Content: juglow.ContentBlockSourceContentUnionParam{
  								OfContentBlockSourceContent: []juglow.ContentBlockSourceContentItemUnionParam{
  									{OfText: &juglow.TextBlockParam{Text: "First chunk"}},
  									{OfText: &juglow.TextBlockParam{Text: "Second chunk"}},
  								},
  							},
  						},
  					},
  					Title:     juglow.String("Document Title"),
  					Context:   juglow.String("Context about the document that will not be cited from"),
  					Citations: juglow.CitationsConfigParam{Enabled: juglow.Bool(true)},
  				},
  			},
  			juglow.NewTextBlock("Summarize this document."),
  		),
  	},
  })
  if err != nil {
  	log.Fatal(err)
  }
  fmt.Println(response)
java
  JuglowClient client = JuglowOkHttpClient.fromEnv();

  DocumentBlockParam documentParam = DocumentBlockParam.builder()
      .source(ContentBlockSource.builder()
          .contentOfBlockSource(
              List.of(
                  ContentBlockSourceContent.ofText(TextBlockParam.builder().text("First chunk").build()),
                  ContentBlockSourceContent.ofText(TextBlockParam.builder().text("Second chunk").build())
              )
          )
          .build())
      .title("Document Title")
      .context("Context about the document that will not be cited from")
      .citations(CitationsConfigParam.builder().enabled(true).build())
      .build();

  MessageCreateParams params = MessageCreateParams.builder()
      .model(Model.HAIJUN_OPUS_5_5)
      .maxTokens(1024)
      .addUserMessageOfBlockParams(
          List.of(
              ContentBlockParam.ofDocument(documentParam),
              ContentBlockParam.ofText(TextBlockParam.builder().text("Summarize this document.").build())
          )
      )
      .build();

  Message message = client.messages().create(params);
  System.out.println(message);
php
  $client = new Client();

  $response = $client->messages->create(
      maxTokens: 1024,
      messages: [
          [
              'role' => 'user',
              'content' => [
                  [
                      'type' => 'document',
                      'source' => [
                          'type' => 'content',
                          'content' => [
                              ['type' => 'text', 'text' => 'First chunk'],
                              ['type' => 'text', 'text' => 'Second chunk'],
                          ],
                      ],
                      'title' => 'Document Title',
                      'context' => 'Context about the document that will not be cited from',
                      'citations' => ['enabled' => true],
                  ],
                  [
                      'type' => 'text',
                      'text' => 'Summarize this document.',
                  ],
              ],
          ],
      ],
      model: 'haijun-opus-5-5',
  );

  echo json_encode($response, JSON_PRETTY_PRINT);
ruby
  client = Juglow::Client.new

  response = client.messages.create(
    model: "haijun-opus-5-5",
    max_tokens: 1024,
    messages: [
      {
        role: "user",
        content: [
          {
            type: "document",
            source: {
              type: "content",
              content: [
                { type: "text", text: "First chunk" },
                { type: "text", text: "Second chunk" }
              ]
            },
            title: "Document Title",
            context: "Context about the document that will not be cited from",
            citations: { enabled: true }
          },
          {
            type: "text",
            text: "Summarize this document."
          }
        ]
      }
    ]
  )

  puts response

Contoh kutipan

json
  {
    "type": "content_block_location",
    "cited_text": "The exact text being cited", // not counted toward output tokens
    "document_index": 0,
    "document_title": "Document Title",
    "start_block_index": 0, // 0-indexed
    "end_block_index": 1 // exclusive
  }

Struktur respons

Ketika kutipan diaktifkan, respons mencakup beberapa blok teks dengan kutipan:

json
{
  "content": [
    { "type": "text", "text": "According to the document, " },
    {
      "type": "text",
      "text": "the grass is green",
      "citations": [
        {
          "type": "char_location",
          "cited_text": "The grass is green.",
          "document_index": 0,
          "document_title": "Example Document",
          "start_char_index": 0,
          "end_char_index": 20
        }
      ]
    },
    { "type": "text", "text": " and " },
    {
      "type": "text",
      "text": "the sky is blue",
      "citations": [
        {
          "type": "char_location",
          "cited_text": "The sky is blue.",
          "document_index": 0,
          "document_title": "Example Document",
          "start_char_index": 20,
          "end_char_index": 36
        }
      ]
    },
    {
      "type": "text",
      "text": ". Information from page 5 states that "
    },
    {
      "type": "text",
      "text": "water is essential",
      "citations": [
        {
          "type": "page_location",
          "cited_text": "Water is essential for life.",
          "document_index": 1,
          "document_title": "PDF Document",
          "start_page_number": 5,
          "end_page_number": 6
        }
      ]
    },
    {
      "type": "text",
      "text": ". The custom document mentions "
    },
    {
      "type": "text",
      "text": "important findings",
      "citations": [
        {
          "type": "content_block_location",
          "cited_text": "These are important findings.",
          "document_index": 2,
          "document_title": "Custom Content Document",
          "start_block_index": 0,
          "end_block_index": 1
        }
      ]
    }
  ]
}

Dukungan streaming

Untuk respons streaming, kutipan tiba sebagai tipe delta citations_delta di dalam event content_block_delta. Setiap delta berisi satu kutipan untuk ditambahkan ke daftar citations pada blok konten text saat ini.

#### Contoh event streaming

sse
    event: message_start
    data: {"type": "message_start", ...}

    event: content_block_start
    data: {"type": "content_block_start", "index": 0, ...}

    event: content_block_delta
    data: {"type": "content_block_delta", "index": 0,
           "delta": {"type": "text_delta", "text": "According to..."}}

    event: content_block_delta
    data: {"type": "content_block_delta", "index": 0,
           "delta": {"type": "citations_delta",
                     "citation": {
                         "type": "char_location",
                         "cited_text": "...",
                         "document_index": 0,
                         ...
                     }}}

    event: content_block_stop
    data: {"type": "content_block_stop", "index": 0}

    event: message_stop
    data: {"type": "message_stop"}

Langkah selanjutnya

Tangani tipe delta citations_delta bersama dengan delta teks untuk merender respons yang dikutip saat mereka di-stream.

Teruskan hasil pencarian dari pipeline RAG Anda sebagai blok konten kelas satu dengan dukungan kutipan bawaan.

Pelajari bagaimana Haijun mengekstrak teks dari PDF dan bagaimana kutipan berbasis halaman dipetakan kembali ke file sumber Anda.

Unggah dokumen sekali dan rujuk dengan file_id di beberapa permintaan kutipan.

On this page
Cara kerja kutipanKonten yang dapat dikutip versus tidak dapat dikutipIndeks kutipanBiaya tokenKompatibilitas fiturMenggunakan caching prompt dengan kutipanJenis dokumenMemilih jenis dokumenDokumen teks biasaContoh kutipan teks biasaDokumen PDFContoh kutipan PDFDokumen konten kustomContoh kutipanStruktur responsDukungan streamingLangkah selanjutnya