Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return token_strings in the response for Tokenize #30

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,10 @@ func Tokenize(opts TokenizeOptions) (*TokenizeResponse, error) {
if err != nil {
return nil, err
}

ret := &TokenizeResponse{encoder.Encode(opts.Text)}
tokens, tokenStrings := encoder.Encode(opts.Text)
ret := &TokenizeResponse{
Tokens: tokens,
TokenStrings: tokenStrings,
}
return ret, nil
}
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/cohere-ai/cohere-go"
cohere "github.com/cohere-ai/cohere-go"
)

func main() {
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module github.com/cohere-ai/cohere-go
go 1.17

retract ( // retract all v1 releases, use v0 instead
v1.0.0
v1.1.0
v1.2.0
v1.2.1
v1.2.0
v1.1.0
v1.0.0
lfayoux marked this conversation as resolved.
Show resolved Hide resolved
)

require (
github.com/cohere-ai/tokenizer v1.0.4
github.com/cohere-ai/tokenizer v1.1.1
github.com/stretchr/testify v1.7.1
)

Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/cohere-ai/tokenizer v1.0.4 h1:x0ThSj6RiPA78CYHDKdfN9f6VwajW36DlOwXUvYn5Cs=
github.com/cohere-ai/tokenizer v1.0.4/go.mod h1:9MNFPd9j1fuiEK3ua2HSCUxxcrfGMlSqpa93livg/C0=
github.com/cohere-ai/tokenizer v1.1.1 h1:wCtmCj07O82TMrIiA/CORhIlEYsvMMM8ey+sUdEapHc=
github.com/cohere-ai/tokenizer v1.1.1/go.mod h1:9MNFPd9j1fuiEK3ua2HSCUxxcrfGMlSqpa93livg/C0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E=
Expand All @@ -9,10 +9,10 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
10 changes: 8 additions & 2 deletions tokenize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ package cohere

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestTokenize(t *testing.T) {
t.Run("TokenizeSuccess", func(t *testing.T) {
text := "tokenize me!"
text := "hello world"

_, err := Tokenize(TokenizeOptions{
res, err := Tokenize(TokenizeOptions{
Text: text,
})
if err != nil {
t.Errorf("Expected result, got error: %s", err.Error())
}
expectedTokens := []int64{33555, 1114}
expectedTokenStrings := []string{"hello", " world"}
assert.Equal(t, expectedTokens, res.Tokens)
assert.Equal(t, expectedTokenStrings, res.TokenStrings)
})

t.Run("TokenizeEmptyText", func(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ type TokenizeOptions struct {
}

type TokenizeResponse struct {
// The tokens.
// The tokens
Tokens []int64 `json:"tokens"`
// String representations of the tokens
TokenStrings []string `json:"tokenStrings"`
}
4 changes: 2 additions & 2 deletions vendor/github.com/cohere-ai/tokenizer/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions vendor/github.com/cohere-ai/tokenizer/bpe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 62 additions & 41 deletions vendor/github.com/cohere-ai/tokenizer/encoder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# github.com/cohere-ai/tokenizer v1.0.4
# github.com/cohere-ai/tokenizer v1.1.1
## explicit; go 1.17
github.com/cohere-ai/tokenizer
# github.com/davecgh/go-spew v1.1.0
Expand Down