rubyai 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rubyai.rb +3 -44
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb31be8c4fbb608addbaa5fd17474999d20bd0ff12931d0701df19a3f1bbb060
|
4
|
+
data.tar.gz: cd2f8e0423796c303e4e11a1d0f2a1d503e7323b70c1d1cf0ffa53e82ef20471
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b84eb8e2d8a807886b85e1ff3dd9904b2746fb1363147d0125497ef43035a4850123eb66c7f208828382c12db38ac5a547a0b7b4e82a84a207aa04a34533df7f
|
7
|
+
data.tar.gz: 772685e21ceaf86b478326ac00c878797fe01f272dbc2eb86f9d298cabb91fe98f0430e5765f46abd5fd01e6619b0ff9622038b014ca264fbb21e3a1525723fb
|
data/lib/rubyai.rb
CHANGED
@@ -1,47 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'json'
|
1
|
+
require_relative "rubyai/client"
|
2
|
+
require_relative "rubyai/configuration"
|
4
3
|
|
5
4
|
module RubyAI
|
6
5
|
class Error < StandardError; end
|
7
|
-
|
8
|
-
class Client
|
9
|
-
BASE_URL = URI.parse("https://api.openai.com/v1/chat/completions")
|
10
|
-
|
11
|
-
def initialize(api_key, messages, temperature: 0.7, model: "gpt-3.5-turbo")
|
12
|
-
@api_key = api_key
|
13
|
-
@messages = messages
|
14
|
-
@temperature = temperature
|
15
|
-
@model = model
|
16
|
-
end
|
17
|
-
|
18
|
-
attr_accessor :api_key, :model, :messages, :temperature
|
19
|
-
|
20
|
-
def call
|
21
|
-
response = Net::HTTP.start(BASE_URL.host, BASE_URL.port, use_ssl: true) do |http|
|
22
|
-
request = Net::HTTP::Post.new(BASE_URL.request_uri, header)
|
23
|
-
request.body = body.to_json
|
24
|
-
http.request(request)
|
25
|
-
end
|
26
|
-
|
27
|
-
JSON.parse(response.body)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def body
|
33
|
-
{
|
34
|
-
'model': model,
|
35
|
-
'messages': [{"role": "user", "content": messages}],
|
36
|
-
'temperature': temperature
|
37
|
-
}
|
38
|
-
end
|
39
|
-
|
40
|
-
def header
|
41
|
-
{
|
42
|
-
'Content-Type': 'application/json',
|
43
|
-
'Authorization': "Bearer #{api_key}"
|
44
|
-
}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
6
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Shapalov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -36,8 +36,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
36
|
- !ruby/object:Gem::Version
|
37
37
|
version: '0'
|
38
38
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
39
|
+
rubygems_version: 3.5.6
|
40
40
|
signing_key:
|
41
41
|
specification_version: 4
|
42
|
-
summary: A Ruby gem for the OpenAI GPT-3 API
|
42
|
+
summary: A Ruby gem for the OpenAI (GPT-3 and GPT-4) API
|
43
43
|
test_files: []
|