rubyai 0.0.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 +7 -0
- data/lib/rubyai.rb +47 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: d773991eb859ade93ab2fd3cf021e35d5739d9b21b151650a1acf4966bd27c3d
|
|
4
|
+
data.tar.gz: 8d0cc8d3d2a754f9ce248db8bc0ca438c6ef5c1309508633f2cce7ac021966d1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c543eeb52f3ecc0b5e9cf9d4f024cf11838fec17b3d63d5267eace99ac7006cebe9848ae8669e687ff57af7d18a2775e3e8efcad90f4424559045235987a7e06
|
|
7
|
+
data.tar.gz: e81f2c6845ee87c7e251f905491829be84d22aff5fd8b96238ccb7f3384dae21e607d2021aed7035bae64cd0956bdac38bbc516a60f48796de072e404c196fcf
|
data/lib/rubyai.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'uri'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
module RubyAI
|
|
6
|
+
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, model, messages, temperature)
|
|
12
|
+
@api_key = api_key
|
|
13
|
+
@model = model
|
|
14
|
+
@messages = messages
|
|
15
|
+
@temperature = temperature
|
|
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': 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
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rubyai
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alex Shaplov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-03-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A Ruby gem for the OpenAI GPT-3 API
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/rubyai.rb
|
|
20
|
+
homepage: https://rubygems.org/gems/rubyai
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.2.33
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Hola!
|
|
43
|
+
test_files: []
|