1
0
mirror of https://github.com/coalaura/whiskr.git synced 2025-12-02 20:22:52 +00:00
Files
whiskr/tokenize.go

33 lines
585 B
Go
Raw Normal View History

2025-09-17 22:52:22 +02:00
package main
import (
"encoding/json"
"net/http"
)
type TokenizeRequest struct {
String string `json:"string"`
}
func HandleTokenize(tokenizer *Tokenizer) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
debug("parsing tokenize")
var raw TokenizeRequest
if err := json.NewDecoder(r.Body).Decode(&raw); err != nil {
RespondJson(w, http.StatusBadRequest, map[string]any{
"error": err.Error(),
})
return
}
tokens := tokenizer.Encode(raw.String)
RespondJson(w, http.StatusOK, map[string]any{
"tokens": len(tokens),
})
}
}