Module: Foobara::LlmBackedExecuteMethod::ClassMethods
- Defined in:
- foobara-llm-backed-command-1.0.1/src/llm_backed_execute_method.rb
Instance Method Summary collapse
- #build_llm_instructions(user_association_depth, assistant_association_depth) ⇒ Object
- #inputs_json_schema(association_depth) ⇒ Object
- #inputs_type_without_llm_integration_inputs ⇒ Object
- #llm_instructions(user_association_depth, assistant_association_depth) ⇒ Object
- #result_json_schema(association_depth) ⇒ Object
Instance Method Details
#build_llm_instructions(user_association_depth, assistant_association_depth) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'foobara-llm-backed-command-1.0.1/src/llm_backed_execute_method.rb', line 247 def build_llm_instructions(user_association_depth, assistant_association_depth) <<~INSTRUCTIONS You are implementing an API for a command named #{scoped_full_name} which has the following description: #{description} Here is the inputs JSON schema for the data you will receive: #{inputs_json_schema(user_association_depth)} Here is the result JSON schema: #{result_json_schema(assistant_association_depth)} You will receive 1 message containing only JSON data according to the inputs JSON schema above and you will generate a JSON response that is a valid response according to the result JSON schema above. You will reply with nothing more than the JSON you've generated so that the calling code can successfully parse your answer. INSTRUCTIONS end |
#inputs_json_schema(association_depth) ⇒ Object
185 186 187 188 189 190 |
# File 'foobara-llm-backed-command-1.0.1/src/llm_backed_execute_method.rb', line 185 def inputs_json_schema(association_depth) JsonSchemaGenerator.to_json_schema( inputs_type_without_llm_integration_inputs, association_depth: ) end |
#inputs_type_without_llm_integration_inputs ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'foobara-llm-backed-command-1.0.1/src/llm_backed_execute_method.rb', line 192 def inputs_type_without_llm_integration_inputs type_declaration = Util.deep_dup(inputs_type.declaration_data) element_type_declarations = type_declaration[:element_type_declarations] changed = false LLM_INTEGRATION_KEYS.each do |key| if element_type_declarations.key?(key) changed = true element_type_declarations.delete(key) end end if type_declaration.key?(:defaults) LLM_INTEGRATION_KEYS.each do |key| if type_declaration[:defaults].key?(key) changed = true type_declaration[:defaults].delete(key) end end if type_declaration[:defaults].empty? type_declaration.delete(:defaults) end end if changed domain.(type_declaration) else inputs_type end end |
#llm_instructions(user_association_depth, assistant_association_depth) ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'foobara-llm-backed-command-1.0.1/src/llm_backed_execute_method.rb', line 233 def llm_instructions(user_association_depth, assistant_association_depth) key = [user_association_depth, assistant_association_depth] @llm_instructions_cache ||= {} if @llm_instructions_cache.key?(key) # :nocov: @llm_instructions_cache[key] # :nocov: else @llm_instructions_cache[key] = build_llm_instructions(user_association_depth, assistant_association_depth) end end |
#result_json_schema(association_depth) ⇒ Object
226 227 228 229 230 231 |
# File 'foobara-llm-backed-command-1.0.1/src/llm_backed_execute_method.rb', line 226 def result_json_schema(association_depth) JsonSchemaGenerator.to_json_schema( result_type, association_depth: ) end |