pplx-api-ruby 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a69c3c1d912e83e05011f7b2700152fba3da470d13043d24abf8d509f78428c4
4
- data.tar.gz: 6021094fa697e64fedaa3e4dcf6a3afb27311c1560f1577f143b4b7d8fcdb124
3
+ metadata.gz: a3b5a7154c0b6d374d52e2375bc70d23402da6f4bc26b397dabf24232dfebf15
4
+ data.tar.gz: a195eeb01c658e3d796284f0054fdda32e15c4440129ea868fb77fa0b114bbb8
5
5
  SHA512:
6
- metadata.gz: f3de955ddabab0ad10c6681520b78c0adba858bc605bf50e2c5fba483c465c7bc9cbfeb7c21987d23f1112fb8a1079b3b32f663d7e0eafeaa898f5d788b23033
7
- data.tar.gz: 73b22b8ab14d4c25ffe59490a84192907683e07ee02b204dd711b6d4769386fdaa997f0543a77107957c1489902909ed2f7b336dae8db05894f219433edb2628
6
+ metadata.gz: 730498b6a5605df3c2b30a864db9feb6d8559fc975978fbef57d59fce41049d30bfdd000d57645c3f21f2a71703d135442ea2edf02c2d234f9f30e1eaa75b924
7
+ data.tar.gz: 26db3484d88b6194cfffd68c32c58cd3d6bc7d46e2e37fed14bdf56c71601d6f736a0b5d43739fd8cd34ee9620cc6f1c2e93cbce194ca635964c9691e62c92f3
@@ -1,43 +1,45 @@
1
- class Client
2
- API_ENDPOINT = "https://api.perplexity.ai/chat/completions".freeze
1
+ module PplxApi
2
+ class Client
3
+ API_ENDPOINT = "https://api.perplexity.ai/chat/completions".freeze
3
4
 
4
- def initialize(api_key: nil)
5
- @uri = URI(API_ENDPOINT)
6
- @api_key = api_key || PplxApi.config.api_key
7
- end
5
+ def initialize(api_key: nil)
6
+ @uri = URI(API_ENDPOINT)
7
+ @api_key = api_key || PplxApi.config.api_key
8
+ end
8
9
 
9
- def generate_response(model: 'mistral-7b-instruct', messages:, max_tokens: nil, temperature: nil, top_p: nil, top_k: nil, stream: false, presence_penalty: nil, frequency_penalty: nil)
10
- headers = {
11
- "Content-Type" => "application/json",
12
- "Authorization" => "Bearer #{@api_key}"
13
- }
10
+ def generate_response(model: 'mistral-7b-instruct', messages:, max_tokens: nil, temperature: nil, top_p: nil, top_k: nil, stream: false, presence_penalty: nil, frequency_penalty: nil)
11
+ headers = {
12
+ "Content-Type" => "application/json",
13
+ "Authorization" => "Bearer #{@api_key}"
14
+ }
14
15
 
15
- body = {
16
- model: model,
17
- messages: messages,
18
- max_tokens: max_tokens,
19
- temperature: temperature,
20
- top_p: top_p,
21
- top_k: top_k,
22
- stream: stream,
23
- presence_penalty: presence_penalty,
24
- frequency_penalty: frequency_penalty
25
- }.compact
16
+ body = {
17
+ model: model,
18
+ messages: messages,
19
+ max_tokens: max_tokens,
20
+ temperature: temperature,
21
+ top_p: top_p,
22
+ top_k: top_k,
23
+ stream: stream,
24
+ presence_penalty: presence_penalty,
25
+ frequency_penalty: frequency_penalty
26
+ }.compact
26
27
 
27
- request = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
28
- request.body = body.to_json
28
+ request = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
29
+ request.body = body.to_json
29
30
 
30
- response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: true) do |http|
31
- http.request(request)
32
- end
31
+ response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: true) do |http|
32
+ http.request(request)
33
+ end
33
34
 
34
- case response
35
- when Net::HTTPSuccess
36
- JSON.parse(response.body)
37
- when Net::HTTPUnprocessableEntity
38
- raise "Validation Error"
39
- else
40
- raise "Unknown Error: #{response.code}"
35
+ case response
36
+ when Net::HTTPSuccess
37
+ JSON.parse(response.body)
38
+ when Net::HTTPUnprocessableEntity
39
+ raise "Validation Error"
40
+ else
41
+ raise "Unknown Error: #{response.code}"
42
+ end
41
43
  end
42
44
  end
43
45
  end
@@ -1,13 +1,15 @@
1
- class Configuration
2
- attr_accessor :api_key
3
- end
1
+ module PplxApi
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ end
4
5
 
5
- @config = Configuration.new
6
+ @config = Configuration.new
6
7
 
7
- def self.config
8
- @config
9
- end
8
+ def self.config
9
+ @config
10
+ end
10
11
 
11
- def self.configure
12
- yield(@config)
12
+ def self.configure
13
+ yield(@config)
14
+ end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module PplxApi
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pplx-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Paul