Sha256: 8c8b3da0c1207f992bb95dc7210ec7815c40c1f35125e536f6700b1603020869

Contents?: true

Size: 1.93 KB

Versions: 20

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

module Appydave
  module Tools
    module YoutubeAutomation
      # GPT Agent interacts with OpenAI's GPT API to generate responses based on prompts for YouTube automation.
      class GptAgent
        include Appydave::Tools::Configuration::Configurable

        def initialize(sequence, debug: false)
          @sequence = sequence
          @debug = debug
          @prompts_path = '/Users/davidcruwys/Library/CloudStorage/Dropbox/team-tldr/_common/raw_prompts'
        end

        def run
          step = config.youtube_automation.get_sequence(@sequence)
          unless step
            puts "Error: Step #{@sequence} not found in the configuration."
            exit 1
          end

          prompt_content = read_prompt(step)

          puts "Running sequence: #{@sequence}"
          puts "Prompt file: #{prompt_file}"
          puts "Prompt content:\n#{prompt_content}" if @debug

          response = run_prompt(prompt_content)

          puts "Response:\n#{response}"
          save_response(prompt_file, response)
        end

        private

        def read_prompt(_step)
          File.read(filename)
        rescue Errno::ENOENT
          puts "Error: Prompt file #{filename} not found."
          exit 1
        end

        def run_prompt(prompt_content)
          client = OpenAI::Client.new(access_token: ENV.fetch('OPENAI_ACCESS_TOKEN', nil))
          response = client.completions(
            engine: 'davinci-codex',
            prompt: prompt_content,
            max_tokens: 1000
          )
          response['choices'][0]['text'].strip
        rescue StandardError => e
          puts "Error: Failed to run prompt. #{e.message}"
          exit 1
        end

        def save_response(filename, response)
          output_filename = filename.gsub('.md', '-output.md')
          File.write(output_filename, response)
          puts "Response saved to #{output_filename}"
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
appydave-tools-0.11.11 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.10 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.9 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.8 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.7 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.6 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.5 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.4 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.3 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.2 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.1 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.11.0 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.10.4 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.10.3 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.10.2 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.10.1 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.10.0 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.9.5 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.9.4 lib/appydave/tools/youtube_automation/gpt_agent.rb
appydave-tools-0.9.3 lib/appydave/tools/youtube_automation/gpt_agent.rb