ruby_raider 0.8.7 → 0.8.9
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 +4 -4
- data/.github/workflows/integration.yml +0 -2
- data/.github/workflows/push_gem.yml +37 -0
- data/.github/workflows/system.yml +0 -2
- data/.gitignore +1 -2
- data/.reek.yml +0 -3
- data/.rubocop.yml +0 -4
- data/README.md +0 -23
- data/Rakefile +0 -5
- data/lib/commands/utility_commands.rb +0 -15
- data/lib/generators/templates/common/read_me.tt +22 -49
- data/lib/ruby_raider.rb +0 -5
- data/lib/utilities/utilities.rb +0 -20
- data/lib/version +1 -1
- data/ruby_raider.gemspec +0 -2
- metadata +4 -34
- data/lib/commands/open_ai_commands.rb +0 -61
- data/lib/open_ai/open_ai.rb +0 -67
- data/spec/integration/commands/open_ai_commands_spec.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72f4f4c7e7650bfc8e0e0e310c5ead22bd5ccbdf482c138d1c806ea7d0792f39
|
4
|
+
data.tar.gz: cca704db232dc1a96f740f7ba5355ab5c999f0f1c40c858362bb18aea6b39081
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0394034b63ea2cf8492ee8a7de03af6d3a18b13c2de3fe6167cdf6cb8b76eeb11bf7bd8bd67ebd76a37e3cac156e661898eb79e840f3819d1b2e95c1ebce53b7'
|
7
|
+
data.tar.gz: be7be6a039005affeb510db66601d7bf8f63ca0c7deb7aa9e7c03521bde212d5f4e31bbb30988757af5b198c96435ccd7358c72c0fe111b04618c6d68f184ab5
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Push Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
|
6
|
+
permissions:
|
7
|
+
contents: read
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
push:
|
11
|
+
if: github.repository == 'RubyRaider/ruby_raider'
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
environment:
|
15
|
+
name: rubygems.org
|
16
|
+
url: https://rubygems.org/gems/ruby_raider
|
17
|
+
|
18
|
+
permissions:
|
19
|
+
contents: write
|
20
|
+
id-token: write
|
21
|
+
|
22
|
+
steps:
|
23
|
+
# Set up
|
24
|
+
- name: Harden Runner
|
25
|
+
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
|
26
|
+
with:
|
27
|
+
egress-policy: audit
|
28
|
+
|
29
|
+
- uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
|
30
|
+
- name: Set up Ruby
|
31
|
+
uses: ruby/setup-ruby@cacc9f1c0b3f4eb8a16a6bb0ed10897b43b9de49 # v1.176.0
|
32
|
+
with:
|
33
|
+
bundler-cache: true
|
34
|
+
ruby-version: ruby
|
35
|
+
|
36
|
+
# Release
|
37
|
+
- uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1
|
data/.gitignore
CHANGED
data/.reek.yml
CHANGED
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -91,7 +91,6 @@ Commands:
|
|
91
91
|
raider generate # Provides access to all the scaffolding commands
|
92
92
|
raider help [COMMAND] # Describe available commands or one specific command
|
93
93
|
raider new [PROJECT_NAME] # Creates a new framework based on settings picked
|
94
|
-
raider open_ai # Provides access to all the open ai commands
|
95
94
|
raider utility # Provides access to all the utility commands
|
96
95
|
raider version # It shows the version of Ruby Raider you are currently using
|
97
96
|
```
|
@@ -100,7 +99,6 @@ All the basic commands have their corresponding shortcut:
|
|
100
99
|
|
101
100
|
* g for generate
|
102
101
|
* n for new
|
103
|
-
* o for open_ai
|
104
102
|
* u for utility
|
105
103
|
* v for version
|
106
104
|
|
@@ -133,27 +131,6 @@ To initialise Appium server run this command:
|
|
133
131
|
raider u start_appium
|
134
132
|
```
|
135
133
|
|
136
|
-
### Open AI Commands
|
137
|
-
|
138
|
-
```ruby
|
139
|
-
# Will print the result of the request on the terminal
|
140
|
-
raider o make [REQUEST]
|
141
|
-
# Will create a file with the result of your request as content
|
142
|
-
raider o make [REQUEST] - -path or -p [PATH]
|
143
|
-
# Will input the content of the chosen file into open ai and will edit it based on the result
|
144
|
-
raider o make [PATH_NAME] - -edit or -e [FILE_PATH]
|
145
|
-
# Creates a cucumber file and uses it to input into open ai and create a steps file
|
146
|
-
# The prompt is required
|
147
|
-
raider o cucumber [NAME] - -prompt or -p [PROMPT]
|
148
|
-
# Creates a cucumber step definitions file based on an scenario file
|
149
|
-
raider open_ai steps [NAME]
|
150
|
-
Options :
|
151
|
-
-p, [--path = PATH] # The path where your steps will be created
|
152
|
-
-pr, [--prompt = PROMPT] # This will create the selected steps based on your prompt using open ai
|
153
|
-
-i, [--input = INPUT] # It uses a file as input to create the steps
|
154
|
-
|
155
|
-
```
|
156
|
-
|
157
134
|
### Sponsors
|
158
135
|
|
159
136
|
This project is tested with BrowserStack.
|
data/Rakefile
CHANGED
@@ -24,11 +24,6 @@ task :path, [:path] do |_t, args|
|
|
24
24
|
ScaffoldingCommands.new.invoke(:path, nil, %W[#{args.path} -s])
|
25
25
|
end
|
26
26
|
|
27
|
-
desc 'Download mobile builds'
|
28
|
-
task :builds, [:type] do |_t, args|
|
29
|
-
ScaffoldingCommands.new.invoke(:download_builds, nil, %W[#{args.type}])
|
30
|
-
end
|
31
|
-
|
32
27
|
desc 'Logs a warning'
|
33
28
|
task :log, [:message] do |_t, args|
|
34
29
|
RubyRaider::Logger.warn(args.message)
|
@@ -73,21 +73,6 @@ class UtilityCommands < Thor
|
|
73
73
|
Utilities.platform = platform
|
74
74
|
end
|
75
75
|
|
76
|
-
desc 'build [BUILD_TYPE]', 'It downloads the selected example build for appium projects'
|
77
|
-
|
78
|
-
def build(build_type)
|
79
|
-
raise 'Please select one of the following build types: android, ios' unless %w[android ios].include?(build_type)
|
80
|
-
|
81
|
-
build_type == 'android' ? Utilities.download_android_build : Utilities.download_ios_build
|
82
|
-
end
|
83
|
-
|
84
|
-
desc 'builds', 'It downloads both builds for appium cross platform projects'
|
85
|
-
|
86
|
-
def builds
|
87
|
-
Utilities.download_android_build
|
88
|
-
Utilities.download_ios_build
|
89
|
-
end
|
90
|
-
|
91
76
|
desc 'start_appium', 'It starts the appium server'
|
92
77
|
def start_appium
|
93
78
|
system 'appium --base-path /wd/hub'
|
@@ -1,29 +1,25 @@
|
|
1
1
|
# Ruby Raider
|
2
2
|
|
3
|
-
[](https://badge.fury.io/rb/ruby_raider)
|
4
|
-
[](https://github.com/RubyRaider/ruby_raider/actions/workflows/rspec.yml)
|
5
|
-
[](https://gitter.im/RubyRaider/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
6
|
-
|
7
3
|
<!-- PROJECT LOGO -->
|
8
4
|
<br />
|
9
5
|
<div align="center">
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
6
|
+
<a href="https://github.com/RubyRaider/ruby_raider">
|
7
|
+
<img src="https://rubyraiderdotcom.files.wordpress.com/2022/05/logo_transparent_background-1.png" alt="Logo">
|
8
|
+
</a>
|
9
|
+
<h1 align="center">Ruby Raider</h1>
|
10
|
+
<p align="center">
|
11
|
+
This is a gem to make setup and start of UI automation projects easier.
|
12
|
+
<br />
|
13
|
+
<a href="https://github.com/RubyRaider/ruby_raider#getting-started"><strong>Explore the docs »</strong></a>
|
14
|
+
<br />
|
15
|
+
<br />
|
16
|
+
<a href="https://rubygems.org/gems/ruby_raider">Rubygems</a>
|
17
|
+
·
|
18
|
+
<a href="https://github.com/RubyRaider/ruby_raider/issues">Report Bug</a>
|
19
|
+
·
|
20
|
+
<a href="https://github.com/RubyRaider/ruby_raider/issues">Request Feature</a>
|
21
|
+
</p>
|
22
|
+
<p align="center"> For more information and updates on releases, see <a href="https://ruby-raider.com">https://ruby-raider.com</a></p>
|
27
23
|
</div>
|
28
24
|
|
29
25
|
## What is Ruby Raider?
|
@@ -86,19 +82,17 @@ Select the ones you will like to work with.
|
|
86
82
|
|
87
83
|
```ruby
|
88
84
|
Commands:
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
raider version # It shows the version of Ruby Raider you are currently using
|
85
|
+
raider generate # Provides access to all the scaffolding commands
|
86
|
+
raider help [COMMAND] # Describe available commands or one specific command
|
87
|
+
raider new [PROJECT_NAME] # Creates a new framework based on settings picked
|
88
|
+
raider utility # Provides access to all the utility commands
|
89
|
+
raider version # It shows the version of Ruby Raider you are currently using
|
95
90
|
```
|
96
91
|
|
97
92
|
All the basic commands have their corresponding shortcut:
|
98
93
|
|
99
94
|
* g for generate
|
100
95
|
* n for new
|
101
|
-
* o for open_ai
|
102
96
|
* u for utility
|
103
97
|
* v for version
|
104
98
|
|
@@ -130,24 +124,3 @@ To initialise Appium server run this command:
|
|
130
124
|
```ruby
|
131
125
|
raider u start_appium
|
132
126
|
```
|
133
|
-
|
134
|
-
### Open AI Commands
|
135
|
-
|
136
|
-
```ruby
|
137
|
-
# Will print the result of the request on the terminal
|
138
|
-
raider o make [REQUEST]
|
139
|
-
# Will create a file with the result of your request as content
|
140
|
-
raider o make [REQUEST] - -path or -p [PATH]
|
141
|
-
# Will input the content of the chosen file into open ai and will edit it based on the result
|
142
|
-
raider o make [PATH_NAME] - -edit or -e [FILE_PATH]
|
143
|
-
# Creates a cucumber file and uses it to input into open ai and create a steps file
|
144
|
-
# The prompt is required
|
145
|
-
raider o cucumber [NAME] - -prompt or -p [PROMPT]
|
146
|
-
# Creates a cucumber step definitions file based on an scenario file
|
147
|
-
raider open_ai steps [NAME]
|
148
|
-
Options :
|
149
|
-
-p, [--path = PATH] # The path where your steps will be created
|
150
|
-
-pr, [--prompt = PROMPT] # This will create the selected steps based on your prompt using open ai
|
151
|
-
-i, [--input = INPUT] # It uses a file as input to create the steps
|
152
|
-
|
153
|
-
```
|
data/lib/ruby_raider.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../lib/commands/open_ai_commands'
|
4
3
|
require_relative '../lib/commands/scaffolding_commands'
|
5
4
|
require_relative '../lib/commands/utility_commands'
|
6
5
|
|
@@ -28,10 +27,6 @@ module RubyRaider
|
|
28
27
|
subcommand 'generate', ScaffoldingCommands
|
29
28
|
map 'g' => 'generate'
|
30
29
|
|
31
|
-
desc 'open_ai', 'Provides access to all the open ai commands'
|
32
|
-
subcommand 'open_ai', OpenAiCommands
|
33
|
-
map 'o' => 'open_ai'
|
34
|
-
|
35
30
|
desc 'utility', 'Provides access to all the utility commands'
|
36
31
|
subcommand 'utility', UtilityCommands
|
37
32
|
map 'u' => 'utility'
|
data/lib/utilities/utilities.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'yaml'
|
4
|
-
require 'faraday'
|
5
4
|
|
6
5
|
module Utilities
|
7
6
|
@path = 'config/config.yml'
|
@@ -62,25 +61,6 @@ module Utilities
|
|
62
61
|
system "#{command} #{opts}"
|
63
62
|
end
|
64
63
|
|
65
|
-
def download_android_build
|
66
|
-
download_build('Android-MyDemoAppRN.1.3.0.build-244.apk',
|
67
|
-
'https://github.com/saucelabs/my-demo-app-rn/releases/download/v1.3.0/Android-MyDemoAppRN.1.3.0.build-244.apk')
|
68
|
-
end
|
69
|
-
|
70
|
-
def download_ios_build
|
71
|
-
download_build('iOS-Simulator-MyRNDemoApp.1.3.0-162.zip',
|
72
|
-
'https://github.com/saucelabs/my-demo-app-rn/releases/download/v1.3.0/iOS-Simulator-MyRNDemoApp.1.3.0-162.zip')
|
73
|
-
end
|
74
|
-
|
75
|
-
def download_build(name, url)
|
76
|
-
response = Faraday.get(url)
|
77
|
-
build_url = Faraday.get(response.headers['location'])
|
78
|
-
|
79
|
-
File.open(name, 'wb') do |file|
|
80
|
-
file.write(build_url.body)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
64
|
private
|
85
65
|
|
86
66
|
def overwrite_yaml
|
data/lib/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.9
|
data/ruby_raider.gemspec
CHANGED
@@ -21,8 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency 'rubocop-performance', '~> 1.15.0'
|
22
22
|
s.add_development_dependency 'rubocop-rspec', '~> 2.9.0'
|
23
23
|
|
24
|
-
s.add_runtime_dependency 'faraday', '~> 1.10.0'
|
25
|
-
s.add_runtime_dependency 'ruby-openai', '~> 3.5'
|
26
24
|
s.add_runtime_dependency 'thor', '~> 1.2.1'
|
27
25
|
s.add_runtime_dependency 'tty-prompt', '~> 0.23.1'
|
28
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_raider
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Agustin Pequeno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -108,34 +108,6 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: 2.9.0
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: faraday
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 1.10.0
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 1.10.0
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: ruby-openai
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '3.5'
|
132
|
-
type: :runtime
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '3.5'
|
139
111
|
- !ruby/object:Gem::Dependency
|
140
112
|
name: thor
|
141
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,6 +148,7 @@ files:
|
|
176
148
|
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
177
149
|
- ".github/auto_assign-issues.yml"
|
178
150
|
- ".github/workflows/integration.yml"
|
151
|
+
- ".github/workflows/push_gem.yml"
|
179
152
|
- ".github/workflows/reek.yml"
|
180
153
|
- ".github/workflows/rubocop.yml"
|
181
154
|
- ".github/workflows/system.yml"
|
@@ -189,7 +162,6 @@ files:
|
|
189
162
|
- README.md
|
190
163
|
- Rakefile
|
191
164
|
- bin/raider
|
192
|
-
- lib/commands/open_ai_commands.rb
|
193
165
|
- lib/commands/scaffolding_commands.rb
|
194
166
|
- lib/commands/utility_commands.rb
|
195
167
|
- lib/generators/actions/actions_generator.rb
|
@@ -262,7 +234,6 @@ files:
|
|
262
234
|
- lib/generators/templates/helpers/spec_helper.tt
|
263
235
|
- lib/generators/templates/helpers/visual_helper.tt
|
264
236
|
- lib/generators/templates/helpers/visual_spec_helper.tt
|
265
|
-
- lib/open_ai/open_ai.rb
|
266
237
|
- lib/ruby_raider.rb
|
267
238
|
- lib/scaffolding/scaffolding.rb
|
268
239
|
- lib/scaffolding/templates/feature.tt
|
@@ -274,7 +245,6 @@ files:
|
|
274
245
|
- lib/utilities/utilities.rb
|
275
246
|
- lib/version
|
276
247
|
- ruby_raider.gemspec
|
277
|
-
- spec/integration/commands/open_ai_commands_spec.rb
|
278
248
|
- spec/integration/commands/scaffolding_commands_spec.rb
|
279
249
|
- spec/integration/commands/utility_commands_spec.rb
|
280
250
|
- spec/integration/generators/actions_generator_spec.rb
|
@@ -305,7 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
305
275
|
- !ruby/object:Gem::Version
|
306
276
|
version: '0'
|
307
277
|
requirements: []
|
308
|
-
rubygems_version: 3.5.
|
278
|
+
rubygems_version: 3.5.3
|
309
279
|
signing_key:
|
310
280
|
specification_version: 4
|
311
281
|
summary: A gem to make setup and start of UI automation projects easier
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require_relative '../open_ai/open_ai'
|
3
|
-
|
4
|
-
class OpenAiCommands < Thor
|
5
|
-
desc 'make [REQUEST]', 'Uses open AI to create a file or generate output'
|
6
|
-
option :path,
|
7
|
-
type: :string, required: false, desc: 'The path where your file will be created', aliases: '-p'
|
8
|
-
option :edit,
|
9
|
-
type: :string, required: false, desc: 'Path to the file you want to edit', aliases: '-e'
|
10
|
-
|
11
|
-
def make(request, path = nil)
|
12
|
-
path ||= options[:path]
|
13
|
-
edit_path = options[:edit]
|
14
|
-
if edit_path
|
15
|
-
pp 'Editing File...'
|
16
|
-
OpenAi.edit_file(path: edit_path, request: request)
|
17
|
-
pp "File #{edit_path} edited"
|
18
|
-
elsif path
|
19
|
-
pp 'Generating File...'
|
20
|
-
OpenAi.create_file(path: path, request: request)
|
21
|
-
pp "File created in #{path}"
|
22
|
-
else
|
23
|
-
puts OpenAi.output(request: request)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
desc 'cucumber [NAME]', 'Creates feature and step files only using open ai'
|
28
|
-
option :prompt,
|
29
|
-
type: :string,
|
30
|
-
required: true, desc: 'The prompt for open ai', aliases: '-p'
|
31
|
-
|
32
|
-
def cucumber(name)
|
33
|
-
feature_path = "features/#{name}.feature"
|
34
|
-
make(options[:prompt], feature_path)
|
35
|
-
prompt_step = "create cucumber steps for the following scenarios in ruby #{File.read(feature_path)}"
|
36
|
-
make(prompt_step, "features/step_definitions/#{name}_steps.rb")
|
37
|
-
end
|
38
|
-
|
39
|
-
desc 'steps [NAME]', 'Creates a new step definitions file'
|
40
|
-
option :path,
|
41
|
-
type: :string,
|
42
|
-
required: false, desc: 'The path where your steps will be created', aliases: '-p'
|
43
|
-
option :prompt,
|
44
|
-
type: :string, required: false,
|
45
|
-
desc: 'This will create the selected steps based on your prompt using open ai', aliases: '-pr'
|
46
|
-
option :input,
|
47
|
-
type: :string,
|
48
|
-
required: false, desc: 'It uses a file as input to create the steps', aliases: '-i'
|
49
|
-
|
50
|
-
def steps(name)
|
51
|
-
path = 'features/step_definitions'
|
52
|
-
input = options[:input]
|
53
|
-
if input
|
54
|
-
prompt = options[:prompt] || 'create cucumber steps for the following scenarios in ruby'
|
55
|
-
content = "#{prompt} #{File.read(input)}"
|
56
|
-
make(content, "#{path}/#{name}_steps.rb")
|
57
|
-
else
|
58
|
-
make(options[:open_ai], "#{path}/#{name}_steps.rb")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
data/lib/open_ai/open_ai.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'openai'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
module OpenAi
|
5
|
-
class << self
|
6
|
-
def client
|
7
|
-
@client ||= create_client
|
8
|
-
end
|
9
|
-
|
10
|
-
def create_client
|
11
|
-
configure_client
|
12
|
-
OpenAI::Client.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def configure_client
|
16
|
-
OpenAI.configure do |config|
|
17
|
-
config.access_token = ENV.fetch('OPENAI_ACCESS_TOKEN')
|
18
|
-
config.organization_id = ENV.fetch('OPENAI_ORGANIZATION_ID', nil)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def input(request, model = 'gpt-3.5-turbo', temperature = 0.7)
|
23
|
-
client.chat(
|
24
|
-
parameters: {
|
25
|
-
model: model,
|
26
|
-
messages: [{ role: 'user', content: request }],
|
27
|
-
temperature: temperature
|
28
|
-
})
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_file(options)
|
32
|
-
path, request, choice = options.values_at(:path, :request, :choice)
|
33
|
-
File.write(path, output(request: request, choice: choice))
|
34
|
-
end
|
35
|
-
|
36
|
-
def output(options)
|
37
|
-
request, choice = options.values_at(:request, :choice)
|
38
|
-
choice ||= 0
|
39
|
-
extract_text(input(request), 'choices', choice, 'message', 'content')
|
40
|
-
end
|
41
|
-
|
42
|
-
def edit_file(options)
|
43
|
-
path, request, choice = options.values_at(:path, :request, :choice)
|
44
|
-
content = File.read(path)
|
45
|
-
response = edit(content: content, request: request)
|
46
|
-
File.write(path, extract_text(response, 'choices', choice, 'text'))
|
47
|
-
end
|
48
|
-
|
49
|
-
def edit(options)
|
50
|
-
content, request, model = options.values_at(:content, :request, :model)
|
51
|
-
model ||= 'text-davinci-edit-001'
|
52
|
-
client.edits(
|
53
|
-
parameters: {
|
54
|
-
model: model,
|
55
|
-
input: content,
|
56
|
-
instruction: request
|
57
|
-
}
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def extract_text(response, *keys)
|
64
|
-
response.dig(*keys)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# require 'dotenv'
|
2
|
-
# require 'fileutils'
|
3
|
-
# require 'pathname'
|
4
|
-
# require 'yaml'
|
5
|
-
# require_relative '../../../lib/generators/common_generator'
|
6
|
-
# require_relative '../../../lib/integration.commands/open_ai_commands'
|
7
|
-
# require_relative '../../../lib/scaffolding/scaffolding'
|
8
|
-
# require_relative '../../spec_helper'
|
9
|
-
#
|
10
|
-
# describe OpenAiCommands do
|
11
|
-
# let(:open_ai) { described_class }
|
12
|
-
# let(:name) { 'test' }
|
13
|
-
#
|
14
|
-
# orig_dir = Dir.pwd
|
15
|
-
# Dotenv.load
|
16
|
-
#
|
17
|
-
# after do
|
18
|
-
# Dir.chdir orig_dir
|
19
|
-
# end
|
20
|
-
#
|
21
|
-
# context 'without any project' do
|
22
|
-
# after do
|
23
|
-
# FileUtils.rm_rf('joke.txt')
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# # TODO: Enable test once the paid account is setup
|
27
|
-
# # it 'creates a file using open ai' do
|
28
|
-
# # open_ai.new.invoke(:make, nil, ['tell me a joke', '--path', 'joke.txt'])
|
29
|
-
# # expect(File).to be_size('joke.txt')
|
30
|
-
# # end
|
31
|
-
#
|
32
|
-
# # it 'edits an existing file using open ai' do
|
33
|
-
# # FileUtils.touch('joke.txt')
|
34
|
-
# # open_ai.new.invoke(:make, nil, ['tell me a better joke', '--edit', 'joke.txt'])
|
35
|
-
# # end
|
36
|
-
# end
|
37
|
-
# end
|