pplx-api-ruby 0.3.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 +7 -0
- data/lib/pplx_api/client.rb +43 -0
- data/lib/pplx_api/configuration.rb +13 -0
- metadata +63 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fc5b50652bf8d4622aca8f4aaa8fec78b35c74aa7e3685a673b55343e5e3cfed
|
4
|
+
data.tar.gz: 14a0cf1d709a231c2e5f9b59972a9c8e17ab70f56e5fc59cae6439a86c919e9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de45182af9a65838961b1638115caf3cdff39e62ec4c207d8142cf8ed11456631e3dea462204db9a150948361e738341aa2dc2229b9a83578fe7a704f00decea
|
7
|
+
data.tar.gz: 1aba8a8502cdb39ebf476a23a9e8fc655114f575922f7b3b0d6f66ebcda1ab4ebb97c693ae3d6c26ba5bc67afc7ebbb2200b431de1d28f7b84a7eb7c058b721f
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Client
|
2
|
+
API_ENDPOINT = "https://api.perplexity.ai/chat/completions".freeze
|
3
|
+
|
4
|
+
def initialize(api_key: nil)
|
5
|
+
@uri = URI(API_ENDPOINT)
|
6
|
+
@api_key = api_key || PplxApi.config.api_key
|
7
|
+
end
|
8
|
+
|
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
|
+
}
|
14
|
+
|
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
|
26
|
+
|
27
|
+
request = Net::HTTP::Post.new(@uri, 'Content-Type' => 'application/json')
|
28
|
+
request.body = body.to_json
|
29
|
+
|
30
|
+
response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: true) do |http|
|
31
|
+
http.request(request)
|
32
|
+
end
|
33
|
+
|
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}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pplx-api-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Paul
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: One of the fastest ways to access Mistral 7B, Llama2 13B, Code Llama
|
28
|
+
34B, Llama2 70B, replit-code-v1.5-3b models.
|
29
|
+
email:
|
30
|
+
- johnarpaul@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- lib/pplx_api/client.rb
|
36
|
+
- lib/pplx_api/configuration.rb
|
37
|
+
homepage: https://github.com/Hyperaide/pplx-api-ruby
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata:
|
41
|
+
homepage_uri: https://github.com/Hyperaide/pplx-api-ruby
|
42
|
+
source_code_uri: https://github.com/Hyperaide/pplx-api-ruby
|
43
|
+
changelog_uri: https://github.com/Hyperaide/pplx-api-ruby
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.6.0
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubygems_version: 3.2.15
|
60
|
+
signing_key:
|
61
|
+
specification_version: 4
|
62
|
+
summary: API wrapper for pplx-api.
|
63
|
+
test_files: []
|