hyrum 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: 6af9ff6689127c74e41729fbd056dadf9a811ec19a74f14ccd6a61413d2b3c0b
4
- data.tar.gz: 900a08d6f56ad8e8cdf70f60fcf5782859b78420c95c9afaf0c86f78815ab449
3
+ metadata.gz: 2c973fd6cbfc5ee63d43e581024c7fc9720501d6e544aa90f524fc6ce8e3b641
4
+ data.tar.gz: a080770b267980f238d35e0d7ea86613ad37b306075a887d8ec83eaf52cd19db
5
5
  SHA512:
6
- metadata.gz: 14adcecb5a38a2fe356e5c9eb27e5fc254d1ce45953bfe32d595ad909813a49ea5a641a99f9b64daae75f3322f09f0bfa8891d9885990f8b1159d7f6f40fbead
7
- data.tar.gz: 19537c266190bcf175f8a340d8828fd354f974fbdb80639018e0d8862103a81bd792967b144afa4e2f5bc2cad78fd94e185bc30f7044cf8db62c1c004278cf55
6
+ metadata.gz: 95833489cffa0a13282d7c294e43346d6aff1aa762629f03a49b2b65dc663f3e9ec722861d4f2b5325fb5351ee3ad7444995f3981a43ee541fb9583f003579a8
7
+ data.tar.gz: 7b198b8dce4536f38f1e37b07fa7dad5c83bbcd4121e5a9ff76d16029aba45f5b60ba012b8cb153b3c5e9601834b6853daf6beee109321a4c67a6efeb41ffde2
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.0.1] - 2024-12-01
9
+
10
+ ### Added
11
+
12
+ - This CHANGELOG file
13
+ - Initial version of the project
14
+
15
+ ## [0.0.2] - 2024-12-06
16
+
17
+ ### Fixed
18
+
19
+ - Minor bug fixes
20
+ - Option defaults
21
+
22
+ ### Added
23
+
24
+ - New OpenAI generator specs
data/README.md CHANGED
@@ -21,7 +21,8 @@ Also, we don't want to spend a lot of time writing variations of the same messag
21
21
  This is the use case Hyrum tries to solve. It uses an AI service (openai,
22
22
  ollama, etc.) to generate variations of a provided message. The generated
23
23
  variations are also formatted in the language/format of your choice (ruby,
24
- json, etc.).
24
+ json, etc.). This code can then be used in your project to ensure messages are
25
+ no longer static, improving your api design.
25
26
 
26
27
  ## Example
27
28
 
@@ -71,9 +72,6 @@ Usage: hyrum [options]
71
72
  ```
72
73
 
73
74
  ## Installation
74
- NOTE: This gem is not yet available on rubygems.org. You can install it from the
75
- repository with `bundle exec rake install`. In the future, you can...
76
-
77
75
  Install the gem and add to the application's Gemfile by executing:
78
76
 
79
77
  $ bundle add hyrum
@@ -11,17 +11,13 @@ module Hyrum
11
11
 
12
12
  def initialize(options)
13
13
  @options = options
14
- configure
15
- @client = OpenAI::Client.new
16
14
  end
17
15
 
18
16
  def generate
19
- if options[:ai_model] == :fake
20
- return JSON.parse(canned_content)
21
- end
17
+ configure
22
18
 
23
- response = get_response(prompt)
24
- puts "Response: #{JSON.pretty_generate(response)}" if options[:verbose]
19
+ response = chat_response
20
+ puts "OpenAI response: #{JSON.pretty_generate(response)}" if options[:verbose]
25
21
  content = response.dig('choices', 0, 'message', 'content')
26
22
  JSON.parse(content)
27
23
  end
@@ -40,15 +36,9 @@ module Hyrum
40
36
  template.result_with_hash(erb_hash)
41
37
  end
42
38
 
43
- def get_response(prompt)
44
- @client.chat(
45
- parameters: {
46
- model: options[:ai_model],
47
- response_format: { type: 'json_object' },
48
- messages: [{ role: 'user', content: prompt}],
49
- temperature: 0.7
50
- }
51
- )
39
+ def chat_response
40
+ client = OpenAI::Client.new
41
+ client.chat(parameters: chat_params)
52
42
  rescue OpenAI::Error => e
53
43
  puts "OpenAI::Error: #{e.message}"
54
44
  exit
@@ -58,6 +48,15 @@ module Hyrum
58
48
  exit
59
49
  end
60
50
 
51
+ def chat_params
52
+ {
53
+ model: options[:ai_model],
54
+ response_format: { type: 'json_object' },
55
+ messages: [{ role: 'user', content: prompt}],
56
+ temperature: 0.7
57
+ }
58
+ end
59
+
61
60
  def configure
62
61
  OpenAI.configure do |config|
63
62
  config.access_token = ENV.fetch('OPENAI_ACCESS_TOKEN') if options[:ai_service] == :openai
@@ -73,10 +72,6 @@ module Hyrum
73
72
  puts "Please set the OPENAI_ACCESS_TOKEN environment variable."
74
73
  exit
75
74
  end
76
-
77
- def canned_content
78
- FakeGenerator::FAKE_MESSAGES
79
- end
80
75
  end
81
76
  end
82
77
  end
@@ -19,6 +19,7 @@ module Hyrum
19
19
  parser.parse!(@args)
20
20
  end
21
21
  enforce_mandatory_options
22
+ set_dynamic_defaults
22
23
  options
23
24
  rescue OptionParser::InvalidOption => e
24
25
  err = "Invalid option: #{e.message}"
@@ -35,6 +36,11 @@ module Hyrum
35
36
 
36
37
  private
37
38
 
39
+ def set_dynamic_defaults
40
+ default_model = Generators::AI_MODEL_DEFAULTS[options[:ai_service]]
41
+ options[:ai_model] ||= default_model
42
+ end
43
+
38
44
  def enforce_mandatory_options
39
45
  missing = MANDATORY_OPTIONS.select { |param| options[param].nil? }
40
46
  return if missing.empty?
@@ -66,25 +72,25 @@ module Hyrum
66
72
  end
67
73
 
68
74
  def ai_service_options(parser)
75
+ options[:ai_service] = :fake
76
+
69
77
  description = "AI service: one of #{Generators::AI_SERVICES.join(', ')}"
70
78
  parser.on('-s SERVICE', '--service SERVICE', Generators::AI_SERVICES, description) do |service|
71
79
  options[:ai_service] = service.to_sym
72
80
  end
73
- options[:ai_service] ||= :fake
74
81
 
75
- default_model = Generators::AI_MODEL_DEFAULTS[options[:ai_service]]
76
82
  description = 'AI model: must be a valid model for the selected service'
77
83
  parser.on('-d MODEL', '--model MODEL', description) do |model|
78
84
  options[:ai_model] = model.to_sym
79
85
  end
80
- options[:ai_model] ||= default_model
81
86
  end
82
87
 
83
88
  def message_key_options(parser)
89
+ options[:key] = :status
90
+
84
91
  parser.on('-k KEY', '--key KEY', 'Message key') do |key|
85
- options[:key] = key
92
+ options[:key] = key.to_sym
86
93
  end
87
- options[:key] ||= 'status'
88
94
  end
89
95
 
90
96
  def message_options(parser)
@@ -100,13 +106,14 @@ module Hyrum
100
106
  end
101
107
 
102
108
  def format_options(parser)
109
+ options[:format] = :text
110
+
103
111
  formats = Formats::FORMATS
104
112
  description = 'Output format. Supported formats are:'
105
113
  supported = formats.join(', ')
106
114
  parser.on('-f FORMAT', '--format FORMAT', formats, description, supported) do |format|
107
115
  options[:format] = format
108
116
  end
109
- options[:format] ||= :text
110
117
  end
111
118
  end
112
119
  end
data/lib/hyrum/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hyrum
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyrum
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
7
  - Tracy Atteberry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-02 00:00:00.000000000 Z
11
+ date: 2024-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-openai
@@ -46,7 +46,9 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files:
48
48
  - README.md
49
+ - CHANGELOG.md
49
50
  files:
51
+ - CHANGELOG.md
50
52
  - README.md
51
53
  - bin/console
52
54
  - bin/hyrum
@@ -85,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
87
  requirements:
86
88
  - - ">="
87
89
  - !ruby/object:Gem::Version
88
- version: 3.1.0
90
+ version: 3.2.0
89
91
  required_rubygems_version: !ruby/object:Gem::Requirement
90
92
  requirements:
91
93
  - - ">="