Module: Cryptum::OpenAI

Defined in:
lib/cryptum/open_ai.rb

Overview

This plugin is used for interacting w/ OpenAI’s REST API This is based on the following OpenAI API Specification: api.openai.com/v1

Class Method Summary collapse

Class Method Details

.chat_gpt(opts = {}) ⇒ Object

Supported Method Parameters

response = PWN::Plugins::OpenAI.chat_gpt(

env: 'required - env object containing OpenAI Bearer token',
option_choice = 'required - option_choice object in case proxy is configured',
request: 'required - message to ChatGPT'

)



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/cryptum/open_ai.rb', line 114

public_class_method def self.chat_gpt(opts = {})
  env = opts[:env]
  option_choice = opts[:option_choice]
  request = opts[:request]

  http_body = {
    model: 'text-davinci-003',
    prompt: request,
    temperature: 0,
    max_tokens: 1024
  }

  response = open_ai_rest_call(
    env: env,
    option_choice: option_choice,
    http_method: :post,
    rest_call: 'completions',
    http_body: http_body.to_json
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.get_models(opts = {}) ⇒ Object

Supported Method Parameters

models = PWN::Plugins::OpenAI.get_models(

env: 'required - env object containing OpenAI Bearer token',
option_choice = 'required - option_choice object in case proxy is configured',

)



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/cryptum/open_ai.rb', line 91

public_class_method def self.get_models(opts = {})
  env = opts[:env]
  option_choice = opts[:option_choice]

  response = open_ai_rest_call(
    env: env,
    option_choice: option_choice,
    http_method: :post,
    rest_call: 'models'
  )

  JSON.parse(response, symbolize_names: true)
rescue StandardError => e
  raise e
end

.helpObject

Display Usage for this Module



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/cryptum/open_ai.rb', line 141

public_class_method def self.help
  puts "USAGE:
    models = PWN::Plugins::OpenAI.get_models(
      env: 'required - env object containing OpenAI Bearer token',
      option_choice = 'required - option_choice object in case proxy is configured',
    )

    response = #{self}.chat_gpt(
      env: 'required - env object containing OpenAI Bearer token',
      option_choice = 'required - option_choice object in case proxy is configured',
      request: 'required - message to ChatGPT'
    )
  "
end