perplexity_api 0.1.0 → 0.2.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: e4890f02cef8111904b2e427ef9196eefd7a55e107fa8f56cd0cceba0eec3cbf
4
- data.tar.gz: b3074af0a14e6e715015ba0d8b753f5ca23a806a0f3642c0d5ba52a8d2b5bd3d
3
+ metadata.gz: a1fb38e349b1dec664c558b497eb1cfebb13db32a2dfe8b73235c67d1d60a8da
4
+ data.tar.gz: 65c6e01e0fc38d3709b74928931804a1cd2894c5c1e2f1229f2efa12347c2a24
5
5
  SHA512:
6
- metadata.gz: 57050c2753a57e1b4de5149b692ed455bf2e0504b15497a9a78b96210365d16759be024f8f7add6926c7b9be8e5756db89135c6c50408c83fa8345cd6629c721
7
- data.tar.gz: cb135987f010d46daf1af7fafcb599a475b3af8989b8e5e1f1f7eed4a73d53d254d64579aaa6d882e9f14697c5e83b551f604c077289f99b40ce55555f77a5a6
6
+ metadata.gz: cbf92894516bd532e9027e64d100d98559610d14f879d4e6e346998d3adf85ba5f4dbc3c108db9c62773dd8a935ddd95df6c2e1c75fabc3ccd1efe8c85e3fd2d
7
+ data.tar.gz: 5cb07fc82fad69e9f4c0b483db88e6f010250360f9aff30ab3e02152dd28eb6d9a08a901f98ae066b3eeddf1aa9c860060fe0cdbfaba00d0263073ec41ce6043
data/.rspec_status ADDED
@@ -0,0 +1,24 @@
1
+ example_id | status | run_time |
2
+ ---------------------------------------------------- | ------ | --------------- |
3
+ ./spec/perplexity_api/client_spec.rb[1:1:1:1] | passed | 0.0228 seconds |
4
+ ./spec/perplexity_api/client_spec.rb[1:1:2:1] | passed | 0.0001 seconds |
5
+ ./spec/perplexity_api/client_spec.rb[1:2:1] | passed | 0.00063 seconds |
6
+ ./spec/perplexity_api/client_spec.rb[1:2:2] | passed | 0.00161 seconds |
7
+ ./spec/perplexity_api/client_spec.rb[1:2:3:1] | passed | 0.0053 seconds |
8
+ ./spec/perplexity_api/client_spec.rb[1:2:4:1] | passed | 0.00045 seconds |
9
+ ./spec/perplexity_api/configuration_spec.rb[1:1:1:1] | passed | 0.0081 seconds |
10
+ ./spec/perplexity_api/configuration_spec.rb[1:1:2:1] | passed | 0.00034 seconds |
11
+ ./spec/perplexity_api/configuration_spec.rb[1:1:3:1] | passed | 0.00192 seconds |
12
+ ./spec/perplexity_api/configuration_spec.rb[1:2:1] | passed | 0.00362 seconds |
13
+ ./spec/perplexity_api/configuration_spec.rb[1:3:1:1] | passed | 0.00084 seconds |
14
+ ./spec/perplexity_api/configuration_spec.rb[1:3:2:1] | passed | 0.00007 seconds |
15
+ ./spec/perplexity_api/configuration_spec.rb[2:1:1] | passed | 0.00073 seconds |
16
+ ./spec/perplexity_api/configuration_spec.rb[2:1:2] | passed | 0.00006 seconds |
17
+ ./spec/perplexity_api/configuration_spec.rb[2:2:1] | passed | 0.00739 seconds |
18
+ ./spec/perplexity_api/configuration_spec.rb[2:2:2] | passed | 0.0001 seconds |
19
+ ./spec/perplexity_api/configuration_spec.rb[2:3:1] | passed | 0.00102 seconds |
20
+ ./spec/perplexity_api_spec.rb[1:1] | passed | 0.00011 seconds |
21
+ ./spec/perplexity_api_spec.rb[1:2:1] | passed | 0.00011 seconds |
22
+ ./spec/perplexity_api_spec.rb[1:3:1] | passed | 0.00017 seconds |
23
+ ./spec/perplexity_api_spec.rb[1:3:2] | passed | 0.00013 seconds |
24
+ ./spec/perplexity_api_spec.rb[1:4:1:1] | passed | 0.00151 seconds |
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ perplexity_api (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.6.1)
10
+ dotenv (2.8.1)
11
+ rake (10.5.0)
12
+ rspec (3.13.0)
13
+ rspec-core (~> 3.13.0)
14
+ rspec-expectations (~> 3.13.0)
15
+ rspec-mocks (~> 3.13.0)
16
+ rspec-core (3.13.3)
17
+ rspec-support (~> 3.13.0)
18
+ rspec-expectations (3.13.3)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.13.0)
21
+ rspec-mocks (3.13.2)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.13.0)
24
+ rspec-support (3.13.2)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.17)
31
+ dotenv (~> 2.7)
32
+ perplexity_api!
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.17.2
data/README.md CHANGED
@@ -37,23 +37,16 @@ There are multiple ways to configure the API key:
37
37
 
38
38
  #### 1. Using Environment Variables (Recommended)
39
39
 
40
- The gem will automatically look for environment variables. Create a `.env` file in your project root:
40
+ The gem will automatically look for environment variables:
41
41
 
42
42
  ```
43
43
  PERPLEXITY_API_KEY=your-api-key-here
44
44
  ```
45
45
 
46
- A sample `.env.sample` file is included in the repository as a template. Copy it to create your own `.env` file:
47
-
48
- ```bash
49
- cp .env.sample .env
50
- ```
51
-
52
- Then edit the `.env` file with your actual API key. Make sure to add `.env` to your `.gitignore` file to avoid committing sensitive information.
53
-
54
- You can also configure other options via environment variables:
46
+ A sample `.env.sample` file is included in the repository as a template for the environment variables you can use:
55
47
 
56
48
  ```
49
+ PERPLEXITY_API_KEY=your-api-key-here
57
50
  PERPLEXITY_DEFAULT_MODEL=sonar
58
51
  PERPLEXITY_TEMPERATURE=0.5
59
52
  PERPLEXITY_MAX_TOKENS=2048
@@ -61,6 +54,16 @@ PERPLEXITY_TOP_P=0.9
61
54
  PERPLEXITY_TOP_K=0
62
55
  ```
63
56
 
57
+ If you're using the dotenv gem in your application, you can load these variables from a `.env` file:
58
+
59
+ ```ruby
60
+ require 'dotenv'
61
+ Dotenv.load # Load environment variables from .env file
62
+
63
+ # Then use the PerplexityApi gem
64
+ require 'perplexity_api'
65
+ ```
66
+
64
67
  #### 2. Using Ruby Configuration
65
68
 
66
69
  To configure the API key in your code:
@@ -1,8 +1,15 @@
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(debug_mode: false)
6
+ @debug_mode = debug_mode
7
+
8
+ # Load configuration from environment variables
9
+ load_from_env
10
+ end
11
+
12
+ def load_from_env
6
13
  @api_key = ENV["PERPLEXITY_API_KEY"]
7
14
  @api_base = ENV["PERPLEXITY_API_BASE"] || "https://api.perplexity.ai"
8
15
  @default_model = ENV["PERPLEXITY_DEFAULT_MODEL"] || "sonar"
@@ -12,11 +19,22 @@ module PerplexityApi
12
19
  top_p: ENV["PERPLEXITY_TOP_P"] ? ENV["PERPLEXITY_TOP_P"].to_f : 0.9,
13
20
  top_k: ENV["PERPLEXITY_TOP_K"] ? ENV["PERPLEXITY_TOP_K"].to_i : 0
14
21
  }
22
+
23
+ debug_log "Configuration loaded from environment variables"
24
+ debug_log "API Key: #{@api_key ? 'Set' : 'Not set'}"
25
+ debug_log "API Base: #{@api_base}"
26
+ debug_log "Default Model: #{@default_model}"
15
27
  end
16
-
28
+
17
29
  def validate!
18
30
  raise Error, "API key is not set." unless api_key
19
31
  end
32
+
33
+ private
34
+
35
+ def debug_log(message)
36
+ puts "[PerplexityApi] #{message}" if @debug_mode
37
+ end
20
38
  end
21
39
 
22
40
  class << self
@@ -27,5 +45,10 @@ module PerplexityApi
27
45
  def configure
28
46
  yield(configuration) if block_given?
29
47
  end
48
+
49
+ def reload_env(debug_mode: false)
50
+ configuration.debug_mode = debug_mode
51
+ configuration.load_from_env
52
+ end
30
53
  end
31
54
  end
@@ -1,3 +1,3 @@
1
1
  module PerplexityApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perplexity_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hisafumi Kikkawa
@@ -77,9 +77,11 @@ files:
77
77
  - ".env.sample"
78
78
  - ".gitignore"
79
79
  - ".rspec"
80
+ - ".rspec_status"
80
81
  - ".travis.yml"
81
82
  - CODE_OF_CONDUCT.md
82
83
  - Gemfile
84
+ - Gemfile.lock
83
85
  - LICENSE.txt
84
86
  - PUBLISHING.md
85
87
  - README.md