Class: OpenAiCommands
- Inherits:
-
Thor
- Object
- Thor
- OpenAiCommands
- Defined in:
- lib/commands/open_ai_commands.rb
Instance Method Summary collapse
Instance Method Details
#cucumber(name) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/commands/open_ai_commands.rb', line 33 def cucumber(name) feature_path = "features/#{name}.feature" make([:prompt], feature_path) prompt_step = "create cucumber steps for the following scenarios in ruby #{File.read(feature_path)}" make(prompt_step, "features/step_definitions/#{name}_steps.rb") end |
#make(request, path = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/commands/open_ai_commands.rb', line 12 def make(request, path = nil) path ||= [:path] edit_path = [:edit] if edit_path pp 'Editing File...' OpenAi.edit_file(path: edit_path, request: request) pp "File #{edit_path} edited" elsif path pp 'Generating File...' OpenAi.create_file(path: path, request: request) pp "File created in #{path}" else puts OpenAi.output(request: request) end end |
#steps(name) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/commands/open_ai_commands.rb', line 51 def steps(name) path = 'features/step_definitions' input = [:input] if input prompt = [:prompt] || 'create cucumber steps for the following scenarios in ruby' content = "#{prompt} #{File.read(input)}" make(content, "#{path}/#{name}_steps.rb") else make([:open_ai], "#{path}/#{name}_steps.rb") end end |
#test ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/commands/open_ai_commands.rb', line 64 def test conn = Faraday.new(url: 'https://api.openai.com') do |faraday| faraday.headers['Content-Type'] = 'application/json' faraday.headers['Authorization'] = "Bearer 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" faraday.headers['OpenAI-Beta'] = 'assistants=v1' end # Data payload for the POST request payload = { instructions: "You are a personal math tutor. When asked a question, write and run Python code to answer the question.", name: "Math Tutor", tools: [{ type: "code_interpreter" }], model: "gpt-4-1106-preview" } # Perform the POST request response = conn.post('/v1/assistants', payload.to_json) # Output the response body puts response.body end |