hallucinate 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9c6c372947846db5fcbc5ceb0e936e29f675373788ed615ed548cfb64195760
4
- data.tar.gz: ee6ae6910f147bb605cd609076ac7556bff9111c2518a1fdea5b318310277c1a
3
+ metadata.gz: f3641152c58241f8875aae5274c03ad8242099938179ccbe42910fd30206bce7
4
+ data.tar.gz: eef4bdb54605ef34cabb3646433d18556cc13c6d2e570cf5d5229bd320cd4fee
5
5
  SHA512:
6
- metadata.gz: 8fab4811baf45d1fef631d082d83747e3a52434bc14e0fb0e94e6898db7e54b0771fcab520c4f1121140aa9c3ed8dadc8315c418bd44d3103ef1e0ccc8da3a33
7
- data.tar.gz: bb0f00aa2a83d42e94b82e314d5a65b9e1ee4bb6c22828626c27456a3b5ff2806e110f84e6392a3dfa0700b8a83e6807773f1cf0afe44bf5ced32970b5486a43
6
+ metadata.gz: d1be1ceb0f1b9404fb22e804503e512f68b1ec7d203d4fff30cb5329fa7de033bf3a576342398afceda905cc7db77bcd5f21edbefa8b3a7809251cde800f31b7
7
+ data.tar.gz: 40f01ca24d67dfb729810d05a7018edf552e5a5eb92638d7abeaf32e2ac5c0ad4989d0de3640f31463f4d13a7308b0a762e8ffdd006ed7579220f341b8272b4d
@@ -4,10 +4,17 @@ require "json"
4
4
 
5
5
  module Hallucinate
6
6
  class AIResponseGenerator
7
+ class MissingApiKeyError < StandardError; end
8
+
7
9
  OPENAI_URL = "https://api.openai.com/v1/chat/completions"
8
10
 
9
- def generate_response(class_name, method_name, args)
10
- api_key = Hallucinate.configuration.api_key
11
+ def generate_response(class_name, method_name, *args, **kargs)
12
+ api_key = begin
13
+ Hallucinate.configuration.api_key
14
+ rescue NoMethodError
15
+ raise MissingApiKeyError
16
+ end
17
+
11
18
  uri = URI(OPENAI_URL)
12
19
  request = Net::HTTP::Post.new(uri)
13
20
  request["Authorization"] = "Bearer #{api_key}"
@@ -17,7 +24,7 @@ module Hallucinate
17
24
  messages: [
18
25
  {
19
26
  role: :user,
20
- content: "Write a method named #{method_name} that would match a class #{class_name} context, knowing the value of these arguments: #{args}, and returns a result you imagine is the most appropriate. Please provide only the method's return output. I really don't want you to be verbose. ONLY respond with the returned result."
27
+ content: "Write a method named #{method_name} that would match a class #{class_name} context, knowing the value of these arguments: #{args} and #{kargs}, and returns a result you imagine is the most appropriate. Please provide only the method's return output. I really don't want you to be verbose. ONLY respond with the returned result."
21
28
  }
22
29
  ],
23
30
  max_tokens: 150
@@ -2,8 +2,8 @@ module Hallucinate
2
2
  module Hallucinator
3
3
  def self.included(base)
4
4
  base.class_eval do
5
- def method_missing(method_name, *args, &block)
6
- AIResponseGenerator.new.generate_response(self.class.name, method_name, *args)
5
+ def method_missing(method_name, *args, **kargs, &block)
6
+ AIResponseGenerator.new.generate_response(self.class.name, method_name, *args, **kargs)
7
7
  end
8
8
 
9
9
  def respond_to_missing?(method_name, include_private = false)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hallucinate
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hallucinate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - MatthieuGC
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 3.4.10
59
+ rubygems_version: 3.4.22
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: Hallucinate is a gem that uses OpenAI's GPT to generate code that doesn't