Sha256: ecf321fb15d1968d86dddae9bd9c416190fdf5657bafecf7e6ebfba65971362b

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

class SlackSmartBot
  module Commands
    module General
      module AI
        module OpenAI
          def open_ai_chat(message, delete_history)
            save_stats(__method__)
            get_personal_settings()
            @ai_open_ai, message_connect = SlackSmartBot::AI::OpenAI.connect(@ai_open_ai, config, @personal_settings, reconnect: delete_history)
            respond message_connect if message_connect
            user = Thread.current[:user]
            if !@ai_open_ai[user.name].nil? and !@ai_open_ai[user.name][:client].nil?
              @ai_gpt ||= {}
              @ai_gpt[user.name] ||= []

              if message == "" # ?? is called
                @ai_gpt[user.name] = []
                respond "*GPT*: Let's start a new conversation. Ask me anything."
              else
                react :speech_balloon
                begin
                  @ai_gpt[user.name] = [] if delete_history
                  @ai_gpt[user.name] << message
                  success, res = SlackSmartBot::AI::OpenAI.send_gpt_chat(@ai_open_ai[user.name][:client], @ai_open_ai[user.name].gpt_model, @ai_gpt[user.name].join("\n"))
                  if success
                    @ai_gpt[user.name] << res
                  end
                  respond "*GPT* Session: _<#{@ai_gpt[user.name].first[0..29]}...>_ (id:#{@ai_gpt[user.name].object_id}) \n#{res.strip}"
                rescue => exception
                  respond "*GPT*: Sorry, I'm having some problems. OpenAI probably is not available. Please try again later."
                end
                unreact :speech_balloon
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slack-smart-bot-1.14.2 lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb
slack-smart-bot-1.14.1 lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb
slack-smart-bot-1.14.0 lib/slack/smart-bot/commands/general/ai/open_ai/open_ai_chat.rb