Class: AskGpt::GPT
- Inherits:
-
Object
- Object
- AskGpt::GPT
- Defined in:
- lib/ask_gpt.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#history ⇒ Object
Returns the value of attribute history.
-
#messages ⇒ Object
Returns the value of attribute messages.
-
#model ⇒ Object
Returns the value of attribute model.
-
#temperature ⇒ Object
Returns the value of attribute temperature.
-
#unable_to_get_answer_text ⇒ Object
Returns the value of attribute unable_to_get_answer_text.
Instance Method Summary collapse
- #ask(question) ⇒ Object
-
#initialize(api_key, model: 'gpt-3.5-turbo', temperature: 0.7, unable_to_get_answer_text: nil) ⇒ GPT
constructor
A new instance of GPT.
Constructor Details
#initialize(api_key, model: 'gpt-3.5-turbo', temperature: 0.7, unable_to_get_answer_text: nil) ⇒ GPT
Returns a new instance of GPT.
10 11 12 13 14 15 16 17 |
# File 'lib/ask_gpt.rb', line 10 def initialize(api_key, model: 'gpt-3.5-turbo', temperature: 0.7, unable_to_get_answer_text: nil) @api_key = api_key @model = model @temperature = temperature = [] @history = [] @unable_to_get_answer_text = unable_to_get_answer_text || 'Unable to get answer from ChatGPT. Make sure API key is valid and has enough credits.' end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/ask_gpt.rb', line 8 def api_key @api_key end |
#history ⇒ Object
Returns the value of attribute history.
8 9 10 |
# File 'lib/ask_gpt.rb', line 8 def history @history end |
#messages ⇒ Object
Returns the value of attribute messages.
8 9 10 |
# File 'lib/ask_gpt.rb', line 8 def end |
#model ⇒ Object
Returns the value of attribute model.
8 9 10 |
# File 'lib/ask_gpt.rb', line 8 def model @model end |
#temperature ⇒ Object
Returns the value of attribute temperature.
8 9 10 |
# File 'lib/ask_gpt.rb', line 8 def temperature @temperature end |
#unable_to_get_answer_text ⇒ Object
Returns the value of attribute unable_to_get_answer_text.
8 9 10 |
# File 'lib/ask_gpt.rb', line 8 def unable_to_get_answer_text @unable_to_get_answer_text end |
Instance Method Details
#ask(question) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ask_gpt.rb', line 19 def ask(question) return if question.empty? replay_history (question) answer = get_completion return unable_to_get_answer_text unless answer update_history(question, answer) answer end |