perplexity_api 0.1.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/.env.sample +10 -0
- data/.gitignore +57 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/PUBLISHING.md +101 -0
- data/README.md +116 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/perplexity_api/client.rb +46 -0
- data/lib/perplexity_api/configuration.rb +31 -0
- data/lib/perplexity_api/version.rb +3 -0
- data/lib/perplexity_api.rb +32 -0
- data/perplexity_api.gemspec +44 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e4890f02cef8111904b2e427ef9196eefd7a55e107fa8f56cd0cceba0eec3cbf
|
4
|
+
data.tar.gz: b3074af0a14e6e715015ba0d8b753f5ca23a806a0f3642c0d5ba52a8d2b5bd3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57050c2753a57e1b4de5149b692ed455bf2e0504b15497a9a78b96210365d16759be024f8f7add6926c7b9be8e5756db89135c6c50408c83fa8345cd6629c721
|
7
|
+
data.tar.gz: cb135987f010d46daf1af7fafcb599a475b3af8989b8e5e1f1f7eed4a73d53d254d64579aaa6d882e9f14697c5e83b551f604c077289f99b40ce55555f77a5a6
|
data/.env.sample
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Perplexity API Key (Required)
|
2
|
+
PERPLEXITY_API_KEY=your_api_key_here
|
3
|
+
|
4
|
+
# Optional Configuration
|
5
|
+
# PERPLEXITY_API_BASE=https://api.perplexity.ai
|
6
|
+
# PERPLEXITY_DEFAULT_MODEL=sonar
|
7
|
+
# PERPLEXITY_TEMPERATURE=0.7
|
8
|
+
# PERPLEXITY_MAX_TOKENS=1024
|
9
|
+
# PERPLEXITY_TOP_P=0.9
|
10
|
+
# PERPLEXITY_TOP_K=0
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
.env
|
15
|
+
.env.test
|
16
|
+
|
17
|
+
# Ignore Byebug command history file.
|
18
|
+
.byebug_history
|
19
|
+
|
20
|
+
## Specific to RubyMotion:
|
21
|
+
.dat*
|
22
|
+
.repl_history
|
23
|
+
build/
|
24
|
+
*.bridgesupport
|
25
|
+
build-iPhoneOS/
|
26
|
+
build-iPhoneSimulator/
|
27
|
+
|
28
|
+
## Specific to RubyMotion (use of CocoaPods):
|
29
|
+
#
|
30
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
31
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
32
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
33
|
+
#
|
34
|
+
# vendor/Pods/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/.bundle/
|
44
|
+
/vendor/bundle
|
45
|
+
/lib/bundler/man/
|
46
|
+
|
47
|
+
# for a library or gem, you might want to ignore these files since the code is
|
48
|
+
# intended to run in multiple environments; otherwise, check them in:
|
49
|
+
# Gemfile.lock
|
50
|
+
# .ruby-version
|
51
|
+
# .ruby-gemset
|
52
|
+
|
53
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
54
|
+
.rvmrc
|
55
|
+
|
56
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
57
|
+
# .rubocop-https?--*
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/PUBLISHING.md
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# Publishing Guide for Perplexity API Gem
|
2
|
+
|
3
|
+
This document explains the steps to publish the Perplexity API Gem to [RubyGems.org](https://rubygems.org).
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
1. Have a RubyGems account
|
8
|
+
2. Have the `gem` command installed
|
9
|
+
3. Have git installed
|
10
|
+
|
11
|
+
## Publishing Steps
|
12
|
+
|
13
|
+
### 1. Check the gemspec file
|
14
|
+
|
15
|
+
Verify that the `perplexity_api.gemspec` file has the following items correctly set:
|
16
|
+
|
17
|
+
- `spec.authors` - Your name
|
18
|
+
- `spec.email` - Your email address
|
19
|
+
- `spec.summary` - A brief description of the gem
|
20
|
+
- `spec.description` - A detailed description of the gem
|
21
|
+
- `spec.homepage` - The URL of the gem's homepage (usually a GitHub repository URL)
|
22
|
+
- `spec.metadata["source_code_uri"]` - The URI of the source code
|
23
|
+
- `spec.metadata["changelog_uri"]` - The URI of the changelog
|
24
|
+
|
25
|
+
### 2. Check the version number
|
26
|
+
|
27
|
+
Verify that the version number in `lib/perplexity_api/version.rb` is appropriate.
|
28
|
+
|
29
|
+
### 3. Run the tests
|
30
|
+
|
31
|
+
Make sure all tests pass:
|
32
|
+
|
33
|
+
```
|
34
|
+
$ bundle exec rake spec
|
35
|
+
```
|
36
|
+
|
37
|
+
### 4. Build the gem
|
38
|
+
|
39
|
+
Build the gem:
|
40
|
+
|
41
|
+
```
|
42
|
+
$ gem build perplexity_api.gemspec
|
43
|
+
```
|
44
|
+
|
45
|
+
This will create a `perplexity_api-x.y.z.gem` file (where x.y.z is the version number).
|
46
|
+
|
47
|
+
### 5. Test the gem installation (optional)
|
48
|
+
|
49
|
+
Install the built gem locally to verify it works correctly:
|
50
|
+
|
51
|
+
```
|
52
|
+
$ gem install ./perplexity_api-x.y.z.gem
|
53
|
+
```
|
54
|
+
|
55
|
+
### 6. Publish to RubyGems
|
56
|
+
|
57
|
+
Publish the gem to RubyGems:
|
58
|
+
|
59
|
+
```
|
60
|
+
$ gem push perplexity_api-x.y.z.gem
|
61
|
+
```
|
62
|
+
|
63
|
+
If this is your first time, you'll be prompted for your RubyGems username and password.
|
64
|
+
|
65
|
+
### 7. Verify the publication
|
66
|
+
|
67
|
+
Visit [RubyGems.org](https://rubygems.org) to verify that the gem was published successfully:
|
68
|
+
|
69
|
+
```
|
70
|
+
https://rubygems.org/gems/perplexity_api
|
71
|
+
```
|
72
|
+
|
73
|
+
## Version Update Steps
|
74
|
+
|
75
|
+
1. Make code changes
|
76
|
+
2. Add/update tests
|
77
|
+
3. Update the version number in `lib/perplexity_api/version.rb`
|
78
|
+
4. Update the changelog (if you have a CHANGELOG.md)
|
79
|
+
5. Follow steps 3-7 from the "Publishing Steps" section above
|
80
|
+
|
81
|
+
## Creating Git Tags (Recommended)
|
82
|
+
|
83
|
+
It's recommended to create git tags for each version:
|
84
|
+
|
85
|
+
```
|
86
|
+
$ git tag -a v0.1.0 -m "Version 0.1.0"
|
87
|
+
$ git push origin v0.1.0
|
88
|
+
```
|
89
|
+
|
90
|
+
## Troubleshooting
|
91
|
+
|
92
|
+
### If publication fails
|
93
|
+
|
94
|
+
- Check that there are no `TODO` items left in the gemspec file
|
95
|
+
- Verify your RubyGems account information
|
96
|
+
- Check your network connection
|
97
|
+
|
98
|
+
### If installation fails
|
99
|
+
|
100
|
+
- Verify that dependencies are correctly set
|
101
|
+
- Check that the Ruby version requirement is appropriate
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# PerplexityApi
|
2
|
+
|
3
|
+
A Ruby wrapper gem for Perplexity AI's API. This gem allows you to easily integrate Perplexity AI's powerful language models into your Ruby applications.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- API key can be configured externally
|
8
|
+
- Ability to select the latest models
|
9
|
+
- Simple interface to send messages and get results
|
10
|
+
- Options can be customized or use defaults
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'perplexity_api'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
```
|
23
|
+
$ bundle install
|
24
|
+
```
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
```
|
29
|
+
$ gem install perplexity_api
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
### Configuration
|
35
|
+
|
36
|
+
There are multiple ways to configure the API key:
|
37
|
+
|
38
|
+
#### 1. Using Environment Variables (Recommended)
|
39
|
+
|
40
|
+
The gem will automatically look for environment variables. Create a `.env` file in your project root:
|
41
|
+
|
42
|
+
```
|
43
|
+
PERPLEXITY_API_KEY=your-api-key-here
|
44
|
+
```
|
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:
|
55
|
+
|
56
|
+
```
|
57
|
+
PERPLEXITY_DEFAULT_MODEL=sonar
|
58
|
+
PERPLEXITY_TEMPERATURE=0.5
|
59
|
+
PERPLEXITY_MAX_TOKENS=2048
|
60
|
+
PERPLEXITY_TOP_P=0.9
|
61
|
+
PERPLEXITY_TOP_K=0
|
62
|
+
```
|
63
|
+
|
64
|
+
#### 2. Using Ruby Configuration
|
65
|
+
|
66
|
+
To configure the API key in your code:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
PerplexityApi.configure do |config|
|
70
|
+
config.api_key = "your-api-key"
|
71
|
+
# Optionally change other settings
|
72
|
+
# config.default_model = "sonar"
|
73
|
+
# config.default_options = { temperature: 0.5, max_tokens: 2048 }
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
### Basic Usage
|
78
|
+
|
79
|
+
The simplest way to send a message and get a response:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
response = PerplexityApi.chat("Hello, Perplexity AI!")
|
83
|
+
puts response["choices"][0]["message"]["content"]
|
84
|
+
```
|
85
|
+
|
86
|
+
### Using a Client Instance
|
87
|
+
|
88
|
+
For more detailed control, you can create a client instance:
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
client = PerplexityApi.new(
|
92
|
+
api_key: "your-api-key", # Optional if already configured
|
93
|
+
model: "sonar", # Override default model
|
94
|
+
options: {
|
95
|
+
temperature: 0.5,
|
96
|
+
max_tokens: 2048,
|
97
|
+
top_p: 0.9,
|
98
|
+
top_k: 0
|
99
|
+
}
|
100
|
+
)
|
101
|
+
|
102
|
+
response = client.chat("Enter your complex question here...")
|
103
|
+
puts response["choices"][0]["message"]["content"]
|
104
|
+
```
|
105
|
+
|
106
|
+
## Models
|
107
|
+
|
108
|
+
For the most up-to-date list of models, refer to the [Perplexity AI official documentation](https://docs.perplexity.ai/guides/model-cards).
|
109
|
+
|
110
|
+
## Development
|
111
|
+
|
112
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
113
|
+
|
114
|
+
## License
|
115
|
+
|
116
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "perplexity_api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module PerplexityApi
|
6
|
+
class Client
|
7
|
+
attr_reader :config
|
8
|
+
|
9
|
+
def initialize(api_key: nil, model: nil, options: {})
|
10
|
+
@config = PerplexityApi.configuration.dup
|
11
|
+
@config.api_key = api_key if api_key != nil
|
12
|
+
@model = model || @config.default_model
|
13
|
+
@options = @config.default_options.merge(options)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Method to send a message and get a response
|
17
|
+
def chat(message)
|
18
|
+
@config.validate!
|
19
|
+
|
20
|
+
uri = URI.parse("#{@config.api_base}/chat/completions")
|
21
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
22
|
+
http.use_ssl = true
|
23
|
+
|
24
|
+
request = Net::HTTP::Post.new(uri.path)
|
25
|
+
request["Content-Type"] = "application/json"
|
26
|
+
request["Authorization"] = "Bearer #{@config.api_key}"
|
27
|
+
|
28
|
+
request.body = {
|
29
|
+
model: @model,
|
30
|
+
messages: [{ role: "user", content: message }],
|
31
|
+
temperature: @options[:temperature],
|
32
|
+
max_tokens: @options[:max_tokens],
|
33
|
+
top_p: @options[:top_p],
|
34
|
+
top_k: @options[:top_k]
|
35
|
+
}.to_json
|
36
|
+
|
37
|
+
response = http.request(request)
|
38
|
+
|
39
|
+
if response.code.to_i == 200
|
40
|
+
JSON.parse(response.body)
|
41
|
+
else
|
42
|
+
raise Error, "API call failed: #{response.code} #{response.body}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PerplexityApi
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_key, :api_base, :default_model, :default_options
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@api_key = ENV["PERPLEXITY_API_KEY"]
|
7
|
+
@api_base = ENV["PERPLEXITY_API_BASE"] || "https://api.perplexity.ai"
|
8
|
+
@default_model = ENV["PERPLEXITY_DEFAULT_MODEL"] || "sonar"
|
9
|
+
@default_options = {
|
10
|
+
temperature: ENV["PERPLEXITY_TEMPERATURE"] ? ENV["PERPLEXITY_TEMPERATURE"].to_f : 0.7,
|
11
|
+
max_tokens: ENV["PERPLEXITY_MAX_TOKENS"] ? ENV["PERPLEXITY_MAX_TOKENS"].to_i : 1024,
|
12
|
+
top_p: ENV["PERPLEXITY_TOP_P"] ? ENV["PERPLEXITY_TOP_P"].to_f : 0.9,
|
13
|
+
top_k: ENV["PERPLEXITY_TOP_K"] ? ENV["PERPLEXITY_TOP_K"].to_i : 0
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate!
|
18
|
+
raise Error, "API key is not set." unless api_key
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def configuration
|
24
|
+
@configuration ||= Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def configure
|
28
|
+
yield(configuration) if block_given?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "perplexity_api/version"
|
2
|
+
require "perplexity_api/configuration"
|
3
|
+
require "perplexity_api/client"
|
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
|
+
module PerplexityApi
|
14
|
+
class Error < StandardError; end
|
15
|
+
|
16
|
+
# Helper method to create a client instance
|
17
|
+
def self.new(api_key: nil, model: nil, options: {})
|
18
|
+
Client.new(api_key: api_key, model: model, options: options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Helper method to directly send a message
|
22
|
+
def self.chat(message, api_key: nil, model: nil, options: {})
|
23
|
+
client = Client.new(api_key: api_key, model: model, options: options)
|
24
|
+
client.chat(message)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Helper method to get available models
|
28
|
+
def self.models(api_key: nil)
|
29
|
+
client = Client.new(api_key: api_key)
|
30
|
+
client.models
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "perplexity_api/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "perplexity_api"
|
7
|
+
spec.version = PerplexityApi::VERSION
|
8
|
+
spec.authors = ["Hisafumi Kikkawa"]
|
9
|
+
spec.email = ["hisafumi.kikkawa@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Ruby wrapper for Perplexity API}
|
12
|
+
spec.description = %q{A Ruby library for easily using Perplexity AI's API. Allows setting API keys, selecting models, and customizing options.}
|
13
|
+
spec.homepage = "https://github.com/hisafumi-kikkawa/perplexity_api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
20
|
+
|
21
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
spec.metadata["source_code_uri"] = "https://github.com/hisafumi-kikkawa/perplexity_api"
|
23
|
+
spec.metadata["changelog_uri"] = "https://github.com/hisafumi-kikkawa/perplexity_api/blob/master/CHANGELOG.md"
|
24
|
+
else
|
25
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
"public gem pushes."
|
27
|
+
end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
42
|
+
|
43
|
+
spec.required_ruby_version = ">= 2.6.0"
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: perplexity_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hisafumi Kikkawa
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: dotenv
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.7'
|
69
|
+
description: A Ruby library for easily using Perplexity AI's API. Allows setting API
|
70
|
+
keys, selecting models, and customizing options.
|
71
|
+
email:
|
72
|
+
- hisafumi.kikkawa@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".env.sample"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- PUBLISHING.md
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- lib/perplexity_api.rb
|
90
|
+
- lib/perplexity_api/client.rb
|
91
|
+
- lib/perplexity_api/configuration.rb
|
92
|
+
- lib/perplexity_api/version.rb
|
93
|
+
- perplexity_api.gemspec
|
94
|
+
homepage: https://github.com/hisafumi-kikkawa/perplexity_api
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata:
|
98
|
+
allowed_push_host: https://rubygems.org
|
99
|
+
homepage_uri: https://github.com/hisafumi-kikkawa/perplexity_api
|
100
|
+
source_code_uri: https://github.com/hisafumi-kikkawa/perplexity_api
|
101
|
+
changelog_uri: https://github.com/hisafumi-kikkawa/perplexity_api/blob/master/CHANGELOG.md
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.6.0
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubygems_version: 3.0.3.1
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: Ruby wrapper for Perplexity API
|
121
|
+
test_files: []
|