Skip to content

Go client bindings for the tiktoken gRPC service.

License

Notifications You must be signed in to change notification settings

yorinasub17/tiktoken-grpc-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tiktoken-grpc-go

LICENSE goreportcard pkg.go reference go.mod version latest release

tiktoken-grpc-go provides Go client bindings for the tiktoken gRPC service.

Usage

This example targets a tiktoken grpc service running locally. You can modify the host param in the NewClient call to target a different instance.

package main

import (
	"context"
	"fmt"

	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"

	tiktokengrpc "github.com/yorinasub17/tiktoken-grpc-go"
)

func main() {
	clt, err := tiktokengrpc.NewClient("localhost", 50051, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic(err)
	}
	defer clt.Close()

	ctx := context.Background()
	text := "antidisestablishmentarianism"

	cl100k, err := clt.NumTokens(ctx, tiktokengrpc.CL100kBase, text)
	if err != nil {
		panic(err)
	}
	fmt.Printf("cl100k_base: %d tokens\n", cl100k)

	p50k, err := clt.NumTokens(ctx, tiktokengrpc.P50kBase, text)
	if err != nil {
		panic(err)
	}
	fmt.Printf("p50k_base: %d tokens\n", p50k)

	gpt2, err := clt.NumTokens(ctx, tiktokengrpc.GPT2Encoding, text)
	if err != nil {
		panic(err)
	}
	fmt.Printf("gpt2: %d tokens\n", gpt2)
}

Installation

go get github.com/yorinasub17/tiktoken-grpc-go

About

Go client bindings for the tiktoken gRPC service.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages