Class: Rails::Llm::Structured::Base
- Inherits:
-
Object
- Object
- Rails::Llm::Structured::Base
- Defined in:
- lib/rails/llm/structured/base.rb
Class Attribute Summary collapse
-
.model_name ⇒ Object
Returns the value of attribute model_name.
-
.schema_definition ⇒ Object
Returns the value of attribute schema_definition.
-
.system_prompt_text ⇒ Object
Returns the value of attribute system_prompt_text.
Class Method Summary collapse
Instance Method Summary collapse
- #call(prompt, **options) ⇒ Object
-
#initialize(client: nil) ⇒ Base
constructor
A new instance of Base.
Constructor Details
Class Attribute Details
.model_name ⇒ Object
Returns the value of attribute model_name.
8 9 10 |
# File 'lib/rails/llm/structured/base.rb', line 8 def model_name @model_name end |
.schema_definition ⇒ Object
Returns the value of attribute schema_definition.
8 9 10 |
# File 'lib/rails/llm/structured/base.rb', line 8 def schema_definition @schema_definition end |
.system_prompt_text ⇒ Object
Returns the value of attribute system_prompt_text.
8 9 10 |
# File 'lib/rails/llm/structured/base.rb', line 8 def system_prompt_text @system_prompt_text end |
Class Method Details
.model(name) ⇒ Object
10 11 12 |
# File 'lib/rails/llm/structured/base.rb', line 10 def model(name) self.model_name = name end |
.structured_output(&block) ⇒ Object
14 15 16 |
# File 'lib/rails/llm/structured/base.rb', line 14 def structured_output(&block) self.schema_definition = Schema.new(&block) end |
.system(prompt) ⇒ Object
18 19 20 |
# File 'lib/rails/llm/structured/base.rb', line 18 def system(prompt) self.system_prompt_text = prompt end |
Instance Method Details
#call(prompt, **options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rails/llm/structured/base.rb', line 27 def call(prompt, **) raise Error, "No model specified" unless self.class.model_name raise Error, "No schema defined" unless self.class.schema_definition = (prompt) raw_response = @client.chat( model: self.class.model_name, messages: , response_format: self.class.schema_definition.to_json_schema, temperature: [:temperature] || 0.7, max_tokens: [:max_tokens] ) Response.new(raw_response, schema: self.class.schema_definition) end |