Class: Rager::Context
- Inherits:
-
Object
- Object
- Rager::Context
- Extended by:
- T::Sig
- Defined in:
- lib/rager/context.rb
Instance Attribute Summary collapse
-
#backoff ⇒ Object
readonly
Returns the value of attribute backoff.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #chat(messages, **kwargs) ⇒ Object
- #embed(text, **kwargs) ⇒ Object
- #image_gen(prompt, **kwargs) ⇒ Object
-
#initialize(id: nil, name: nil, max_retries: nil, backoff: nil) ⇒ Context
constructor
A new instance of Context.
- #mesh_gen(prompt, **kwargs) ⇒ Object
- #rerank(query, documents, **kwargs) ⇒ Object
- #search(query, **kwargs) ⇒ Object
- #template(template, variables, **kwargs) ⇒ Object
Constructor Details
#initialize(id: nil, name: nil, max_retries: nil, backoff: nil) ⇒ Context
Returns a new instance of Context.
25 26 27 28 29 30 |
# File 'lib/rager/context.rb', line 25 def initialize(id: nil, name: nil, max_retries: nil, backoff: nil) @id = T.let(id || SecureRandom.uuid, String) @name = T.let(name, T.nilable(String)) @max_retries = T.let(max_retries || 0, Integer) @backoff = T.let(backoff || 1.0, Float) end |
Instance Attribute Details
#backoff ⇒ Object (readonly)
Returns the value of attribute backoff.
22 23 24 |
# File 'lib/rager/context.rb', line 22 def backoff @backoff end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
13 14 15 |
# File 'lib/rager/context.rb', line 13 def id @id end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
19 20 21 |
# File 'lib/rager/context.rb', line 19 def max_retries @max_retries end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/rager/context.rb', line 16 def name @name end |
Instance Method Details
#chat(messages, **kwargs) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rager/context.rb', line 38 def chat(, **kwargs) execute( Rager::Operation::Chat, Rager::Chat::Options, kwargs, ) { |, normalized_input| final_input = if normalized_input.is_a?(String) [ Rager::Chat::Message.new( role: Rager::Chat::MessageRole::User, content: normalized_input ) ] else normalized_input end provider = Rager::Providers.get_provider(:chat, .provider, ) provider.chat(final_input, ) } end |
#embed(text, **kwargs) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rager/context.rb', line 67 def (text, **kwargs) execute( Rager::Operation::Embed, Rager::Embed::Options, kwargs, text ) { |, normalized_input| final_input = if normalized_input.is_a?(String) [normalized_input] else normalized_input end provider = Rager::Providers.get_provider(:embed, .provider, ) provider.(final_input, ) } end |
#image_gen(prompt, **kwargs) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rager/context.rb', line 91 def image_gen(prompt, **kwargs) execute( Rager::Operation::ImageGen, Rager::ImageGen::Options, kwargs, prompt ) { |, normalized_input| provider = Rager::Providers.get_provider(:image_gen, .provider, ) provider.image_gen(T.cast(normalized_input, Rager::Types::ImageGenInput), ) } end |
#mesh_gen(prompt, **kwargs) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/rager/context.rb', line 109 def mesh_gen(prompt, **kwargs) execute( Rager::Operation::MeshGen, Rager::MeshGen::Options, kwargs, prompt ) { |, normalized_input| provider = Rager::Providers.get_provider(:mesh_gen, .provider, ) provider.mesh_gen(T.cast(normalized_input, Rager::Types::MeshGenInput), ) } end |
#rerank(query, documents, **kwargs) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/rager/context.rb', line 128 def rerank(query, documents, **kwargs) execute( Rager::Operation::Rerank, Rager::Rerank::Options, kwargs, {query: query, documents: documents} ) { |, normalized_input| provider = Rager::Providers.get_provider(:rerank, .provider, ) input_hash = T.cast(normalized_input, T::Hash[Symbol, T.untyped]) provider.rerank(input_hash[:query], input_hash[:documents], ) } end |
#search(query, **kwargs) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rager/context.rb', line 147 def search(query, **kwargs) execute( Rager::Operation::Search, Rager::Search::Options, kwargs, query ) { |, normalized_input| provider = Rager::Providers.get_provider(:search, .provider, ) provider.search(T.cast(normalized_input, Rager::Types::SearchInput), ) } end |
#template(template, variables, **kwargs) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/rager/context.rb', line 166 def template(template, variables, **kwargs) execute( Rager::Operation::Template, Rager::Template::Options, kwargs, {template: template, variables: variables} ) { |, normalized_input| provider = Rager::Providers.get_provider(:template, .provider, ) input_hash = T.cast(normalized_input, T::Hash[Symbol, T.untyped]) provider.template(input_hash[:template], input_hash[:variables], ) } end |