Files
fil/docs/snippets/go/api/client_chunk_text.md
Henrik Jess Nielsen b4c07d3693
All checks were successful
Deploy fil (kreuzberg) / deploy (push) Successful in 49s
Nomad changes
2026-06-01 23:40:55 +02:00

895 B

package main

import (
	"bytes"
	"encoding/json"
	"io"
	"log"
	"net/http"
)

func main() {
	client := &http.Client{}

	payload := map[string]interface{}{
		"text":          "Your long text content here...",
		"chunker_type":  "text",
		"config": map[string]interface{}{
			"max_characters": 1000,
			"overlap":        50,
			"trim":           true,
		},
	}

	data, _ := json.Marshal(payload)
	resp, err := client.Post("http://localhost:8000/chunk", "application/json", bytes.NewBuffer(data))
	if err != nil {
		log.Fatalf("request failed: %v", err)
	}
	defer resp.Body.Close()

	var result map[string]interface{}
	json.NewDecoder(resp.Body).Decode(&result)

	chunks := result["chunks"].([]interface{})
	log.Printf("Created %d chunks", len(chunks))
	for _, chunk := range chunks {
		c := chunk.(map[string]interface{})
		println("Chunk content:", c["content"].(string))
	}
}