cohere-ruby 0.9.7 → 0.9.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f3e839b9a7eb9b33711cd3f909dec96c85b9402a9d43f173c8350f666bde182
4
- data.tar.gz: 5c549985ee0e26b99e5f20e2baefad46ab39f3ad300e8f928c69355f1caa847b
3
+ metadata.gz: 35acc85a1ec589048eae603675fd23afeec9c66c0ce8c14954c20916c099b93b
4
+ data.tar.gz: e48ea97c36afafa8ca134c240a19ff159af1086643e99efba0aaf5aaed225cca
5
5
  SHA512:
6
- metadata.gz: '08b9d5b439fe3bf4a64a52d65535635e044d52051af213dddcb216aa0efaf9ecd982b6f80b20dcde7916f41d52b5ae21e5c825083bbb139baf9fe787afc8e093'
7
- data.tar.gz: 58a85830e7564db2eafa1dc833f7d6d516451fedf50fbd968f202e9243b47cb738e54ed15f6fc88841382181b9331ef1c40cbfc8ec6a57b101fccef759742adb
6
+ metadata.gz: eb6700a2088e5b37842fb6a601e160bbc6e8a6e8c15a7dd52b42f74cc0ce5fc71c77d789d9eaa20a440b1a3c4b4bab46088a5117b84d0a5027531acbfaf28067
7
+ data.tar.gz: 4e759bd938560031412e4602ee86321e3953e61dfa9c368c843b0d1b71e0676b061007dda48514b8ef5e9df072f7df3b5c817452f06a72553864bf77a679b492
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.9.9] - 2024-04-05
4
+ - Adding missing parameters to endpoints
5
+
6
+ ## [0.9.8] - 2024-02-10
7
+ - Adding method for /chat endpoint
8
+
3
9
  ## [0.1.0] - 2023-04-23
4
10
 
5
11
  - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cohere-ruby (0.9.7)
4
+ cohere-ruby (0.9.9)
5
5
  faraday (>= 2.0.1, < 3.0)
6
6
 
7
7
  GEM
@@ -67,6 +67,7 @@ GEM
67
67
  unicode-display_width (2.4.2)
68
68
 
69
69
  PLATFORMS
70
+ arm64-darwin-23
70
71
  x86_64-darwin-19
71
72
  x86_64-darwin-21
72
73
  x86_64-linux
data/README.md CHANGED
@@ -29,21 +29,71 @@ If bundler is not being used to manage dependencies, install the gem by executin
29
29
  ## Usage
30
30
 
31
31
  ### Instantiating API client
32
+
32
33
  ```ruby
33
34
  require "cohere"
34
35
 
35
36
  client = Cohere::Client.new(
36
- api_key: ENV['COHERE_API_KEY']
37
+ ENV['COHERE_API_KEY']
37
38
  )
38
39
  ```
40
+
39
41
  ### Generate
42
+
40
43
  ```ruby
41
44
  client.generate(
42
45
  prompt: "Once upon a time in a magical land called"
43
46
  )
44
47
  ```
45
48
 
49
+ ### Chat
50
+
51
+ ```ruby
52
+ client.chat(
53
+ message: "Hey! How are you?"
54
+ )
55
+ ```
56
+
57
+ `chat` supports a streaming option. You can pass a block to the `chat` method and it will yield a new chunk as soon as it is received.
58
+
59
+ ```ruby
60
+ client.chat(message: "Hey! How are you?", stream: true) do |chunk, overall_received_bytes|
61
+ puts "Received #{overall_received_bytes} bytes: #{chunk.force_encoding(Encoding::UTF_8)}"
62
+ end
63
+ ```
64
+
65
+ `force_encoding` is preferred to avoid JSON parsing issue when Cohere returns emoticon.
66
+
67
+ `chat` supports Tool use (function calling).
68
+
69
+ ```ruby
70
+ tools = [
71
+ {
72
+ name: "query_daily_sales_report",
73
+ description: "Connects to a database to retrieve overall sales volumes and sales information for a given day.",
74
+ parameter_definitions: {
75
+ day: {
76
+ description: "Retrieves sales data for this day, formatted as YYYY-MM-DD.",
77
+ type: "str",
78
+ required: true
79
+ }
80
+ }
81
+ }
82
+ ]
83
+
84
+ message = "Can you provide a sales summary for 29th September 2023, and also give me some details about the products in the 'Electronics' category, for example their prices and stock levels?"
85
+
86
+ client.chat(
87
+ model: model,
88
+ message: message,
89
+ tools: tools,
90
+ )
91
+ ```
92
+
93
+
94
+
46
95
  ### Embed
96
+
47
97
  ```ruby
48
98
  client.embed(
49
99
  texts: ["hello!"]
@@ -51,6 +101,7 @@ client.embed(
51
101
  ```
52
102
 
53
103
  ### Classify
104
+
54
105
  ```ruby
55
106
  examples = [
56
107
  { text: "Dermatologists don't like her!", label: "Spam" },
@@ -77,6 +128,7 @@ client.classify(
77
128
  ```
78
129
 
79
130
  ### Tokenize
131
+
80
132
  ```ruby
81
133
  client.tokenize(
82
134
  text: "hello world!"
@@ -84,6 +136,7 @@ client.tokenize(
84
136
  ```
85
137
 
86
138
  ### Detokenize
139
+
87
140
  ```ruby
88
141
  client.detokenize(
89
142
  tokens: [33555, 1114 , 34]
@@ -91,6 +144,7 @@ client.detokenize(
91
144
  ```
92
145
 
93
146
  ### Detect language
147
+
94
148
  ```ruby
95
149
  client.detect_language(
96
150
  texts: ["Здравствуй, Мир"]
@@ -98,6 +152,7 @@ client.detect_language(
98
152
  ```
99
153
 
100
154
  ### Summarize
155
+
101
156
  ```ruby
102
157
  client.summarize(
103
158
  text: "..."
data/lib/cohere/client.rb CHANGED
@@ -12,6 +12,55 @@ module Cohere
12
12
  @api_key = api_key
13
13
  end
14
14
 
15
+ def chat(
16
+ message:,
17
+ model: nil,
18
+ stream: false,
19
+ preamble: nil,
20
+ preamble_override: nil,
21
+ chat_history: [],
22
+ conversation_id: nil,
23
+ prompt_truncation: nil,
24
+ connectors: [],
25
+ search_queries_only: false,
26
+ documents: [],
27
+ citation_quality: nil,
28
+ temperature: nil,
29
+ max_tokens: nil,
30
+ k: nil,
31
+ p: nil,
32
+ frequency_penalty: nil,
33
+ presence_penalty: nil,
34
+ tools: [],
35
+ &block
36
+ )
37
+ response = connection.post("chat") do |req|
38
+ req.body = {message: message}
39
+ req.body[:model] = model if model
40
+ if stream || block
41
+ req.body[:stream] = true
42
+ req.options.on_data = block if block
43
+ end
44
+ req.body[:preamble] = preamble if preamble
45
+ req.body[:preamble_override] = preamble_override if preamble_override
46
+ req.body[:chat_history] = chat_history if chat_history
47
+ req.body[:conversation_id] = conversation_id if conversation_id
48
+ req.body[:prompt_truncation] = prompt_truncation if prompt_truncation
49
+ req.body[:connectors] = connectors if connectors
50
+ req.body[:search_queries_only] = search_queries_only if search_queries_only
51
+ req.body[:documents] = documents if documents
52
+ req.body[:citation_quality] = citation_quality if citation_quality
53
+ req.body[:temperature] = temperature if temperature
54
+ req.body[:max_tokens] = max_tokens if max_tokens
55
+ req.body[:k] = k if k
56
+ req.body[:p] = p if p
57
+ req.body[:frequency_penalty] = frequency_penalty if frequency_penalty
58
+ req.body[:presence_penalty] = presence_penalty if presence_penalty
59
+ req.body[:tools] = tools if tools
60
+ end
61
+ response.body
62
+ end
63
+
15
64
  # This endpoint generates realistic text conditioned on a given input.
16
65
  def generate(
17
66
  prompt:,
@@ -53,11 +102,13 @@ module Cohere
53
102
  def embed(
54
103
  texts:,
55
104
  model: nil,
105
+ input_type: nil,
56
106
  truncate: nil
57
107
  )
58
108
  response = connection.post("embed") do |req|
59
109
  req.body = {texts: texts}
60
110
  req.body[:model] = model if model
111
+ req.body[:input_type] = input_type if input_type
61
112
  req.body[:truncate] = truncate if truncate
62
113
  end
63
114
  response.body
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cohere
4
- VERSION = "0.9.7"
4
+ VERSION = "0.9.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cohere-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.7
4
+ version: 0.9.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Bondarev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-17 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0'
72
72
  requirements: []
73
- rubygems_version: 3.2.3
73
+ rubygems_version: 3.4.1
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Cohere API client for Ruby.