Class: Agents::OpenAiGptClient
- Defined in:
- lib/gpt_clients/open_ai_gpt_client.rb
Instance Attribute Summary collapse
-
#default_params ⇒ Object
readonly
Returns the value of attribute default_params.
-
#open_ai_client ⇒ Object
readonly
Returns the value of attribute open_ai_client.
Instance Method Summary collapse
- #chat(prompt: "", **args) ⇒ Object
-
#initialize(open_ai_client:, default_params: {}, **args) ⇒ OpenAiGptClient
constructor
A new instance of OpenAiGptClient.
Constructor Details
#initialize(open_ai_client:, default_params: {}, **args) ⇒ OpenAiGptClient
Returns a new instance of OpenAiGptClient.
6 7 8 9 10 11 12 13 |
# File 'lib/gpt_clients/open_ai_gpt_client.rb', line 6 def initialize(open_ai_client:, default_params: {}, **args) super(**args) @open_ai_client = open_ai_client @default_params = { model: "gpt-3.5-turbo-1106", temperature: 0.7, }.merge(default_params) end |
Instance Attribute Details
#default_params ⇒ Object (readonly)
Returns the value of attribute default_params.
4 5 6 |
# File 'lib/gpt_clients/open_ai_gpt_client.rb', line 4 def default_params @default_params end |
#open_ai_client ⇒ Object (readonly)
Returns the value of attribute open_ai_client.
3 4 5 |
# File 'lib/gpt_clients/open_ai_gpt_client.rb', line 3 def open_ai_client @open_ai_client end |
Instance Method Details
#chat(prompt: "", **args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gpt_clients/open_ai_gpt_client.rb', line 15 def chat(prompt: "", **args) = [] << { role: "system", content: "#{args[:system_prompt] || 'You are a helpful assistant.'}" } << { role: "user", content: "#{prompt}" } Agents.logger.debug("Sending to ChatGPT:") Agents.logger.debug() parameters = default_params.merge({messages: }) completions = open_ai_client.chat parameters: parameters Agents.logger.debug("ChatGPT Responded:") Agents.logger.debug(completions) text = completions.dig("choices", 0, "message", "content") Agents.logger.debug("-" * 80) Agents.logger.debug text Agents.logger.debug("-" * 80) GptResponse.new(text) end |