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 +4 -4
- data/lib/pplx_api/client.rb +36 -34
- data/lib/pplx_api/configuration.rb +11 -9
- data/lib/pplx_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3b5a7154c0b6d374d52e2375bc70d23402da6f4bc26b397dabf24232dfebf15
|
4
|
+
data.tar.gz: a195eeb01c658e3d796284f0054fdda32e15c4440129ea868fb77fa0b114bbb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 730498b6a5605df3c2b30a864db9feb6d8559fc975978fbef57d59fce41049d30bfdd000d57645c3f21f2a71703d135442ea2edf02c2d234f9f30e1eaa75b924
|
7
|
+
data.tar.gz: 26db3484d88b6194cfffd68c32c58cd3d6bc7d46e2e37fed14bdf56c71601d6f736a0b5d43739fd8cd34ee9620cc6f1c2e93cbce194ca635964c9691e62c92f3
|
data/lib/pplx_api/client.rb
CHANGED
@@ -1,43 +1,45 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module PplxApi
|
2
|
+
class Client
|
3
|
+
API_ENDPOINT = "https://api.perplexity.ai/chat/completions".freeze
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
28
|
+
request = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
|
29
|
+
request.body = body.to_json
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: true) do |http|
|
32
|
+
http.request(request)
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
2
|
-
|
3
|
-
|
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
|
-
|
9
|
-
end
|
8
|
+
def self.config
|
9
|
+
@config
|
10
|
+
end
|
10
11
|
|
11
|
-
def self.configure
|
12
|
-
|
12
|
+
def self.configure
|
13
|
+
yield(@config)
|
14
|
+
end
|
13
15
|
end
|
data/lib/pplx_api/version.rb
CHANGED