Class: FlexiAdmin::Services::CodeGen::Gpt
- Inherits:
-
Object
- Object
- FlexiAdmin::Services::CodeGen::Gpt
- Defined in:
- lib/flexi_admin/services/code_gen/gpt.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- GPT_3_5 =
'gpt-3.5-turbo'- GPT_3_5_16 =
'gpt-3.5-turbo-16k'- GPT_4 =
'gpt-4-turbo-2024-04-09'- GPT_4o =
'gpt-4o'- GPT_4o_mini =
'gpt-4o-mini'- GPT_o1 =
'gpt-o1'- GPT_o1_mini =
'o1-mini'
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #chat(message, format: 'text', model: GPT_4o, temperature: nil) ⇒ Object
-
#initialize ⇒ Gpt
constructor
A new instance of Gpt.
- #resolve_temperature(model) ⇒ Object
Constructor Details
#initialize ⇒ Gpt
Returns a new instance of Gpt.
40 41 42 |
# File 'lib/flexi_admin/services/code_gen/gpt.rb', line 40 def initialize @client = OpenAI::Client.new log_errors: true end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
38 39 40 |
# File 'lib/flexi_admin/services/code_gen/gpt.rb', line 38 def client @client end |
Instance Method Details
#chat(message, format: 'text', model: GPT_4o, temperature: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/flexi_admin/services/code_gen/gpt.rb', line 44 def chat(, format: 'text', model: GPT_4o, temperature: nil) temperature ||= resolve_temperature(model) response = client.chat( parameters: { model: model, response_format: { type: format.to_s == 'json' ? 'json_object' : 'text' }, messages: [{ role: 'user', content: }], temperature: temperature } ) Response.new(response, format:) end |
#resolve_temperature(model) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/flexi_admin/services/code_gen/gpt.rb', line 59 def resolve_temperature(model) case model when GPT_o1, GPT_o1_mini 1 else 0.7 end end |