perplexity_api 0.1.0 → 0.1.1
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/perplexity_api/configuration.rb +46 -3
- data/lib/perplexity_api/version.rb +1 -1
- data/lib/perplexity_api.rb +5 -8
- 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: 821bf76a4e00f4a38efd595687006831daf4b0bbd5166df367dd9435b0a05869
|
4
|
+
data.tar.gz: 6d0e5e40ed4e61ea77f41b731b7586e201448defabd51f47715942f3e4aebff5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23add32739947a021034a449583aeecd09e446ff2b5f109669a767785894e8b75387ad778293433538dc3f6309fbbd57200c06c7acbd4746de9a839c0c4b7763
|
7
|
+
data.tar.gz: 511c3f2abd79b85b49d9f9c7c4c22fc66b021d2dd266785693e0e6018c75171683de4ddcb2a7ff00014f99eebb9cb33689e0ba89b22eac4b65feddea4854c772
|
@@ -1,8 +1,34 @@
|
|
1
1
|
module PerplexityApi
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :api_key, :api_base, :default_model, :default_options
|
3
|
+
attr_accessor :api_key, :api_base, :default_model, :default_options, :debug_mode
|
4
4
|
|
5
|
-
def initialize
|
5
|
+
def initialize(load_env: true, debug_mode: false)
|
6
|
+
@debug_mode = debug_mode
|
7
|
+
|
8
|
+
# Load .env file if dotenv is available and load_env is true
|
9
|
+
if load_env
|
10
|
+
load_dotenv
|
11
|
+
end
|
12
|
+
|
13
|
+
# Load configuration from environment variables
|
14
|
+
load_from_env
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_dotenv
|
18
|
+
begin
|
19
|
+
require "dotenv"
|
20
|
+
if File.exist?(".env")
|
21
|
+
Dotenv.load
|
22
|
+
debug_log "Loaded .env file"
|
23
|
+
else
|
24
|
+
debug_log ".env file not found"
|
25
|
+
end
|
26
|
+
rescue LoadError
|
27
|
+
debug_log "dotenv gem not available. Install it with: gem install dotenv"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_from_env
|
6
32
|
@api_key = ENV["PERPLEXITY_API_KEY"]
|
7
33
|
@api_base = ENV["PERPLEXITY_API_BASE"] || "https://api.perplexity.ai"
|
8
34
|
@default_model = ENV["PERPLEXITY_DEFAULT_MODEL"] || "sonar"
|
@@ -12,11 +38,22 @@ module PerplexityApi
|
|
12
38
|
top_p: ENV["PERPLEXITY_TOP_P"] ? ENV["PERPLEXITY_TOP_P"].to_f : 0.9,
|
13
39
|
top_k: ENV["PERPLEXITY_TOP_K"] ? ENV["PERPLEXITY_TOP_K"].to_i : 0
|
14
40
|
}
|
41
|
+
|
42
|
+
debug_log "Configuration loaded from environment variables"
|
43
|
+
debug_log "API Key: #{@api_key ? 'Set' : 'Not set'}"
|
44
|
+
debug_log "API Base: #{@api_base}"
|
45
|
+
debug_log "Default Model: #{@default_model}"
|
15
46
|
end
|
16
|
-
|
47
|
+
|
17
48
|
def validate!
|
18
49
|
raise Error, "API key is not set." unless api_key
|
19
50
|
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def debug_log(message)
|
55
|
+
puts "[PerplexityApi] #{message}" if @debug_mode
|
56
|
+
end
|
20
57
|
end
|
21
58
|
|
22
59
|
class << self
|
@@ -27,5 +64,11 @@ module PerplexityApi
|
|
27
64
|
def configure
|
28
65
|
yield(configuration) if block_given?
|
29
66
|
end
|
67
|
+
|
68
|
+
def load_dotenv(debug_mode: false)
|
69
|
+
configuration.debug_mode = debug_mode
|
70
|
+
configuration.load_dotenv
|
71
|
+
configuration.load_from_env
|
72
|
+
end
|
30
73
|
end
|
31
74
|
end
|
data/lib/perplexity_api.rb
CHANGED
@@ -2,14 +2,6 @@ require "perplexity_api/version"
|
|
2
2
|
require "perplexity_api/configuration"
|
3
3
|
require "perplexity_api/client"
|
4
4
|
|
5
|
-
# Load dotenv if available
|
6
|
-
begin
|
7
|
-
require "dotenv"
|
8
|
-
Dotenv.load
|
9
|
-
rescue LoadError
|
10
|
-
# dotenv is not available, continue without it
|
11
|
-
end
|
12
|
-
|
13
5
|
module PerplexityApi
|
14
6
|
class Error < StandardError; end
|
15
7
|
|
@@ -29,4 +21,9 @@ module PerplexityApi
|
|
29
21
|
client = Client.new(api_key: api_key)
|
30
22
|
client.models
|
31
23
|
end
|
24
|
+
|
25
|
+
# Helper method to explicitly load .env file
|
26
|
+
def self.load_env(debug_mode: false)
|
27
|
+
load_dotenv(debug_mode: debug_mode)
|
28
|
+
end
|
32
29
|
end
|