File tree Expand file tree Collapse file tree 3 files changed +41
-4
lines changed
Expand file tree Collapse file tree 3 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 7171
7272PLATFORMS
7373 x86_64-darwin-19
74+ x86_64-darwin-21
7475 x86_64-linux
7576
7677DEPENDENCIES
Original file line number Diff line number Diff line change @@ -83,16 +83,16 @@ def classify(
8383 response . body
8484 end
8585
86- def tokenize ( text :)
86+ def tokenize ( text :, model : nil )
8787 response = connection . post ( "tokenize" ) do |req |
88- req . body = { text : text }
88+ req . body = model . nil? ? { text : text } : { text : text , model : model }
8989 end
9090 response . body
9191 end
9292
93- def detokenize ( tokens :)
93+ def detokenize ( tokens :, model : nil )
9494 response = connection . post ( "detokenize" ) do |req |
95- req . body = { tokens : tokens }
95+ req . body = model . nil? ? { tokens : tokens } : { tokens : tokens , model : model }
9696 end
9797 response . body
9898 end
Original file line number Diff line number Diff line change 9191 end
9292 end
9393
94+ describe "#tokenize_with_model" do
95+ let ( :tokenize_result ) { JSON . parse ( File . read ( "spec/fixtures/tokenize_result.json" ) ) }
96+ let ( :response ) { OpenStruct . new ( body : tokenize_result ) }
97+
98+ before do
99+ allow_any_instance_of ( Faraday ::Connection ) . to receive ( :post )
100+ . with ( "tokenize" )
101+ . and_return ( response )
102+ end
103+
104+ it "returns a response" do
105+ expect ( instance . tokenize (
106+ text : "Hello, world!" ,
107+ model : "base"
108+ ) . dig ( "tokens" ) ) . to eq ( [ 33555 , 1114 , 34 ] )
109+ end
110+ end
111+
94112 describe "#detokenize" do
95113 let ( :detokenize_result ) { JSON . parse ( File . read ( "spec/fixtures/detokenize_result.json" ) ) }
96114 let ( :response ) { OpenStruct . new ( body : detokenize_result ) }
108126 end
109127 end
110128
129+ describe "#detokenize_with_model" do
130+ let ( :detokenize_result ) { JSON . parse ( File . read ( "spec/fixtures/detokenize_result.json" ) ) }
131+ let ( :response ) { OpenStruct . new ( body : detokenize_result ) }
132+
133+ before do
134+ allow_any_instance_of ( Faraday ::Connection ) . to receive ( :post )
135+ . with ( "detokenize" )
136+ . and_return ( response )
137+ end
138+
139+ it "returns a response" do
140+ expect ( instance . detokenize (
141+ tokens : [ 33555 , 1114 , 34 ] ,
142+ model : "base"
143+ ) . dig ( "text" ) ) . to eq ( "hello world!" )
144+ end
145+ end
146+
111147 describe "#detect_language" do
112148 let ( :detect_language_result ) { JSON . parse ( File . read ( "spec/fixtures/detect_language_result.json" ) ) }
113149 let ( :response ) { OpenStruct . new ( body : detect_language_result ) }
You can’t perform that action at this time.
0 commit comments