openai-chat 0.0.1 → 0.0.2

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: 543ce4c08a3a9770e84a643b690239101aff7fc586a836524ba5a35fb2d9afc6
4
- data.tar.gz: 2ea37a2cef4aa16f9e8f659490fb890bc9fc369391708cb8539656ade79fc5a3
3
+ metadata.gz: 356c73f7aa65e6bbb6a89fcb8c1764232a764f22c412d646405a2e05f112fefc
4
+ data.tar.gz: 6b6b842391c42aa797e6199ef65875fe7b35121fa65985e141ce6aeffb30023c
5
5
  SHA512:
6
- metadata.gz: c3ae2d72a8c9280b2bfccbd46a00522abeef0e34744602e566f471f504347f79e3769e435fa8ac6087b0cf2cc57a1fdfbacdd888bf825df0335f273948b8578a
7
- data.tar.gz: d9f73de9aa9b3fb61f4edddbfc88787451c4be91e8c0a0846c945633dde28a3226697af3658572eca5a194c5b80dd4c57c4ce1d6cc4133d9a6bf692dd07da6c2
6
+ metadata.gz: d94a2829fc56f46a2a485b3b3a4d0260a60d9eba88acb24cdafff5294a3760098ca0f85821fb8a844359bcb25268aacb73a7c89455fe05c67f57431a4ac8f0b4
7
+ data.tar.gz: 00eb5dd473c308f75727d8bce37cb87ce753e7482406183fd9c8f189a6c2f0fb0b956bb6a8b69363954aa4f3da89df5b262f1953915e125986adf2a4b27dd999
data/CHANGELOG.md CHANGED
@@ -3,3 +3,9 @@
3
3
  ## [0.0.1] - 2025-02-27
4
4
 
5
5
  - Initial release
6
+
7
+ ## [0.0.2] - 2025-02-28
8
+
9
+ - All dependencies have been removed
10
+ - Supports Ruby 2.0.0
11
+ - Updates gem author
data/Gemfile CHANGED
@@ -4,7 +4,3 @@ source "https://rubygems.org"
4
4
 
5
5
  # Specify your gem's dependencies in draft_chat.gemspec
6
6
  gemspec
7
-
8
- gem "activesupport", "~> 2.3", ">= 2.3.5"
9
- gem "http", "~> 5.2", ">= 5.2.0"
10
- gem "json", "~> 2.6", ">= 2.6.0"
data/Gemfile.lock CHANGED
@@ -1,46 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openai-chat (0.0.1)
5
- activesupport (~> 2.3, >= 2.3.5)
6
- http (~> 5.2, >= 5.2.0)
7
- json (~> 2.6, >= 2.6.0)
4
+ openai-chat (0.0.2)
8
5
 
9
6
  GEM
10
7
  remote: https://rubygems.org/
11
8
  specs:
12
- activesupport (2.3.18)
13
- addressable (2.8.7)
14
- public_suffix (>= 2.0.2, < 7.0)
15
- base64 (0.2.0)
16
- domain_name (0.6.20240107)
17
- ffi (1.17.1)
18
- ffi-compiler (1.3.2)
19
- ffi (>= 1.15.5)
20
- rake
21
- http (5.2.0)
22
- addressable (~> 2.8)
23
- base64 (~> 0.1)
24
- http-cookie (~> 1.0)
25
- http-form_data (~> 2.2)
26
- llhttp-ffi (~> 0.5.0)
27
- http-cookie (1.0.8)
28
- domain_name (~> 0.5)
29
- http-form_data (2.3.0)
30
- json (2.10.1)
31
- llhttp-ffi (0.5.0)
32
- ffi-compiler (~> 1.0)
33
- rake (~> 13.0)
34
- public_suffix (6.0.1)
35
- rake (13.2.1)
36
9
 
37
10
  PLATFORMS
38
11
  x86_64-linux
39
12
 
40
13
  DEPENDENCIES
41
- activesupport (~> 2.3, >= 2.3.5)
42
- http (~> 5.2, >= 5.2.0)
43
- json (~> 2.6, >= 2.6.0)
44
14
  openai-chat!
45
15
 
46
16
  BUNDLED WITH
data/README.md CHANGED
@@ -10,6 +10,7 @@ x.system("You are a helpful assistant that speaks like Shakespeare.")
10
10
  x.user("Hi there!")
11
11
  x.assistant!
12
12
  # => "Greetings, good sir or madam! How dost thou fare on this fine day? Pray, tell me how I may be of service to thee."
13
+
13
14
  x.user("What's the best pizza in Chicago?")
14
15
  x.assistant!
15
16
  # => "Ah, the fair and bustling city of Chicago, renowned for its deep-dish delight that hath captured hearts and stomachs aplenty. Amongst the many offerings of this great city, 'tis often said that Lou Malnati's and Giordano's art the titans of the deep-dish realm. Lou Malnati's crust is praised for its buttery crispness, whilst Giordano's doth boast a stuffed creation that is nigh unto legendary. Yet, I encourage thee to embark upon thine own quest and savor the offerings of these famed establishments, for in the tasting lies the truth of which thy palate prefers. Enjoy the gastronomic adventure, my friend."
@@ -51,16 +52,20 @@ Enjoy!
51
52
  Add this line to your application's Gemfile:
52
53
 
53
54
  ```ruby
54
- gem 'openai-chat'
55
+ gem "openai-chat", github: "firstdraft/openai-chat"
55
56
  ```
56
57
 
57
- And then execute:
58
+ And then, at a command prompt:
58
59
 
59
- $ bundle install
60
+ ```
61
+ bundle install
62
+ ```
60
63
 
61
- Or install it yourself as:
64
+ Or, install it directly with:
62
65
 
63
- $ gem install openai-chat
66
+ ```
67
+ gem install openai-chat
68
+ ```
64
69
 
65
70
  ## TODOs
66
71
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OpenAI
4
4
  class Chat
5
- VERSION = "0.0.1"
5
+ VERSION = "0.0.2"
6
6
  end
7
7
  end
data/lib/openai/chat.rb CHANGED
@@ -1,31 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "openai/chat/version"
4
+ require "net/http"
5
+ require "uri"
6
+ require "json"
4
7
 
5
8
  module OpenAI
6
9
  class Chat
7
- require "active_support/core_ext/object/blank"
8
- require "http"
9
- require "json"
10
-
11
10
  attr_accessor :messages, :schema, :model
12
-
11
+
13
12
  def initialize(api_token: nil)
14
13
  @api_token = api_token || ENV.fetch("OPENAI_TOKEN")
15
14
  @messages = []
16
15
  @model = "gpt-4o"
17
16
  end
18
-
17
+
19
18
  def system(content)
20
- messages.push({role: "system", content:})
19
+ messages.push({role: "system", content: content})
21
20
  end
22
-
21
+
23
22
  def user(content)
24
- messages.push({role: "user", content:})
23
+ messages.push({role: "user", content: content})
25
24
  end
26
25
 
27
26
  def assistant(content)
28
- messages.push({role: "assistant", content:})
27
+ messages.push({role: "assistant", content: content})
29
28
  end
30
29
 
31
30
  def assistant!
@@ -33,38 +32,40 @@ module OpenAI
33
32
  "Authorization" => "Bearer #{@api_token}",
34
33
  "content-type" => "application/json",
35
34
  }
36
-
37
- response_format = if schema.present?
35
+
36
+ response_format = if schema.nil?
38
37
  {
39
- "type" => "json_schema",
40
- "json_schema" => JSON.parse(schema)
38
+ "type" => "text"
41
39
  }
42
40
  else
43
41
  {
44
- "type" => "text"
42
+ "type" => "json_schema",
43
+ "json_schema" => JSON.parse(schema)
45
44
  }
46
45
  end
47
-
46
+
48
47
  request_body_hash = {
49
48
  "model" => model,
50
49
  "response_format" => response_format,
51
50
  "messages" => messages
52
51
  }
53
-
52
+
54
53
  request_body_json = JSON.generate(request_body_hash)
55
-
56
- raw_response = HTTP.headers(request_headers_hash).post(
57
- "https://api.openai.com/v1/chat/completions",
58
- :body => request_body_json,
59
- ).to_s
60
-
61
- parsed_response = JSON.parse(raw_response)
62
-
54
+
55
+ uri = URI("https://api.openai.com/v1/chat/completions")
56
+ raw_response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
57
+ request = Net::HTTP::Post.new(uri, request_headers_hash)
58
+ request.body = request_body_json
59
+ http.request(request)
60
+ end
61
+
62
+ parsed_response = JSON.parse(raw_response.body)
63
+
63
64
  content = parsed_response.fetch("choices").at(0).fetch("message").fetch("content")
64
-
65
- messages.push({role: "assistant", content:})
66
-
67
- schema.present? ? JSON.parse(content) : content
65
+
66
+ messages.push({role: "assistant", content: content})
67
+
68
+ schema.nil? ? content : JSON.parse(content)
68
69
  end
69
70
 
70
71
  def inspect
metadata CHANGED
@@ -1,79 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openai-chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
+ - Raghu Betina
7
8
  - Jelani Woods
8
9
  autorequire:
9
10
  bindir: exe
10
11
  cert_chain: []
11
- date: 2025-02-27 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: activesupport
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.3'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.3.5
23
- type: :runtime
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '2.3'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.3.5
33
- - !ruby/object:Gem::Dependency
34
- name: http
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '5.2'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 5.2.0
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '5.2'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 5.2.0
53
- - !ruby/object:Gem::Dependency
54
- name: json
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '2.6'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 2.6.0
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '2.6'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 2.6.0
12
+ date: 2025-03-01 00:00:00.000000000 Z
13
+ dependencies: []
73
14
  description: This gem provides a class called `OpenAI::Chat` that is intended to make
74
15
  it as easy as possible to use OpenAI's Chat Completions endpoint. Supports Structured
75
16
  Output.
76
17
  email:
18
+ - raghu@firstdraft.com
77
19
  - jelani@firstdraft.com
78
20
  executables: []
79
21
  extensions: []
@@ -103,7 +45,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
45
  requirements:
104
46
  - - ">="
105
47
  - !ruby/object:Gem::Version
106
- version: 2.6.0
48
+ version: 2.0.0
107
49
  required_rubygems_version: !ruby/object:Gem::Requirement
108
50
  requirements:
109
51
  - - ">="