lib/gpt-cli.rb in gpt-cli-0.1.2 vs lib/gpt-cli.rb in gpt-cli-0.1.3

- old
+ new

@@ -1,17 +1,18 @@ # frozen_string_literal: true require_relative "gpt-cli/version" -require_relative "contexts" +require "json" require "quick_openai" require "optparse" class ChatGPT def contexts - file_contents = File.read(File.join(File.dirname(__FILE__), 'contexts.rb')) - instance_eval(file_contents) + file_contents = File.read(ENV["OPENAI_CONTEXTS_PATH"]) + contexts = JSON.parse(file_contents) + contexts.transform_keys(&:to_sym) end def gpt3(prompt, options) context = options[:context] || contexts[ENV["OPENAI_DEFAULT_CONTEXT"].to_sym] messages = [ @@ -42,10 +43,10 @@ def self.exe options = {} chatgpt = ChatGPT.new parser = OptionParser.new do |opts| - opts.on('-c', '--context CONTEXT_KEY', 'Context key from contexts.rb') do |context_input| + opts.on('-c', '--context CONTEXT_KEY', 'Context key from contexts.json') do |context_input| options[:context] = chatgpt.contexts.key?(context_input.to_sym) ? chatgpt.contexts[context_input.to_sym] : context_input end opts.on('-p', '--prompt PROMPT_TEXT', 'Prompt text to be passed to GPT-3') do |prompt_text| options[:prompt] = prompt_text end