Class: Cohere::Client
Instance Method Summary collapse
- #classify(model:, options:) ⇒ Object
- #embed(model:, options:) ⇒ Object
- #generate(model:, options:) ⇒ Object
-
#initialize(access_token: nil, version: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(access_token: nil, version: nil) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/cohere/client.rb', line 6 def initialize(access_token: nil, version: nil) @access_token = access_token @version = version || "2021-11-08"; # currently latest, update when we version better end |
Instance Method Details
#classify(model:, options:) ⇒ Object
11 12 13 |
# File 'lib/cohere/client.rb', line 11 def classify(model:, options:) serialize post(endpoint: "classify", model: model, body: DEFAULT_CLASSIFY_PARAMS.merge()) end |
#embed(model:, options:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cohere/client.rb', line 15 def (model:, options:) threads = [] = DEFAULT_EMBED_PARAMS.merge() return OpenStruct.new(code: 400, body: { embeddings: [], ids: [] }) if [:texts].empty? [:texts].each_slice(1) do |batch| threads << threded_post(model: model, endpoint: "embed", body: .merge(texts: batch)) end results = threads.each(&:join).map(&:value) (results) end |
#generate(model:, options:) ⇒ Object
28 29 30 |
# File 'lib/cohere/client.rb', line 28 def generate(model:, options:) serialize post(endpoint: "generate", model: model, body: DEFAULT_GENERATE_PARAMS.merge()) end |