Module: Foobara::LlmBackedExecuteMethod::ClassMethods
- Defined in:
- foobara-llm-backed-command-1.0.2/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
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 |
# File 'foobara-llm-backed-command-1.0.2/src/llm_backed_execute_method.rb', line 273 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
211 212 213 214 215 216 |
# File 'foobara-llm-backed-command-1.0.2/src/llm_backed_execute_method.rb', line 211 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
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'foobara-llm-backed-command-1.0.2/src/llm_backed_execute_method.rb', line 218 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
259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'foobara-llm-backed-command-1.0.2/src/llm_backed_execute_method.rb', line 259 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
252 253 254 255 256 257 |
# File 'foobara-llm-backed-command-1.0.2/src/llm_backed_execute_method.rb', line 252 def result_json_schema(association_depth) JsonSchemaGenerator.to_json_schema( result_type, association_depth: ) end |