Module: Raif
- Defined in:
- lib/raif.rb,
lib/raif/engine.rb,
lib/raif/version.rb,
lib/raif/languages.rb,
lib/raif/llm_registry.rb,
lib/raif/configuration.rb,
lib/raif/json_schema_builder.rb,
lib/raif/embedding_model_registry.rb,
lib/generators/raif/views_generator.rb,
lib/raif/errors/invalid_config_error.rb,
lib/generators/raif/task/task_generator.rb,
lib/generators/raif/agent/agent_generator.rb,
lib/raif/errors/open_ai/json_schema_error.rb,
lib/raif/errors/unsupported_feature_error.rb,
lib/raif/errors/action_not_authorized_error.rb,
lib/raif/errors/invalid_user_tool_type_error.rb,
lib/generators/raif/install/install_generator.rb,
lib/raif/errors/invalid_model_file_input_error.rb,
lib/raif/errors/invalid_conversation_type_error.rb,
lib/raif/errors/invalid_model_image_input_error.rb,
lib/generators/raif/model_tool/model_tool_generator.rb,
lib/generators/raif/conversation/conversation_generator.rb,
app/models/raif/llm.rb,
app/models/raif/task.rb,
app/models/raif/agent.rb,
app/jobs/raif/application_job.rb,
app/models/raif/agents/re_act_step.rb,
app/helpers/raif/application_helper.rb,
app/models/raif/agents/re_act_agent.rb,
app/jobs/raif/conversation_entry_job.rb,
app/controllers/raif/admin/stats_controller.rb,
app/controllers/raif/admin/tasks_controller.rb,
app/controllers/raif/application_controller.rb,
app/controllers/raif/admin/agents_controller.rb,
app/helpers/raif/shared/conversations_helper.rb,
app/models/raif/concerns/json_schema_definition.rb,
app/models/raif/agents/native_tool_calling_agent.rb,
app/controllers/raif/admin/application_controller.rb,
app/controllers/raif/admin/stats/tasks_controller.rb,
app/controllers/raif/admin/conversations_controller.rb,
app/controllers/raif/admin/model_completions_controller.rb,
app/controllers/raif/admin/model_tool_invocations_controller.rb
Defined Under Namespace
Modules: Admin, Agents, ApplicationHelper, Concerns, Errors, Generators, Shared, Utils Classes: Agent, ApplicationController, ApplicationJob, ApplicationRecord, Configuration, Conversation, ConversationEntriesController, ConversationEntry, ConversationEntryJob, ConversationsController, EmbeddingModel, Engine, JsonSchemaBuilder, Llm, ModelCompletion, ModelFileInput, ModelImageInput, ModelTool, ModelToolInvocation, Task, UserToolInvocation, ViewsGenerator
Constant Summary collapse
- VERSION =
"1.1.0"
- SUPPORTED_LANGUAGES =
[ "ar", "da", "de", "en", "es", "fi", "fr", "he", "hi", "it", "ja", "ko", "nl", "no", "pl", "pt", "ru", "sv", "th", "tr", "uk", "vi", "zh", ].freeze
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
-
.embedding_model_registry ⇒ Object
Returns the value of attribute embedding_model_registry.
- .logger ⇒ Object
Class Method Summary collapse
- .available_embedding_model_keys ⇒ Object
- .available_embedding_models ⇒ Object
- .available_llm_keys ⇒ Object
- .available_llms ⇒ Object
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
- .default_embedding_model_key ⇒ Object
- .default_embedding_models ⇒ Object
- .default_llms ⇒ Object
- .embedding_model(model_key) ⇒ Object
- .embedding_model_config(model_key) ⇒ Object
- .generate_embedding!(input, dimensions: nil) ⇒ Object
- .llm(model_key) ⇒ Object
- .llm_config(model_key) ⇒ Object
- .llm_registry ⇒ Object
- .register_embedding_model(embedding_model_class, embedding_model_config) ⇒ Object
- .register_llm(llm_class, llm_config) ⇒ Object
- .supported_languages ⇒ Object
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
22 23 24 |
# File 'lib/raif.rb', line 22 def configuration @configuration end |
.embedding_model_registry ⇒ Object
Returns the value of attribute embedding_model_registry.
5 6 7 |
# File 'lib/raif/embedding_model_registry.rb', line 5 def @embedding_model_registry end |
.logger ⇒ Object
35 36 37 |
# File 'lib/raif.rb', line 35 def self.logger @logger ||= Rails.logger end |
Class Method Details
.available_embedding_model_keys ⇒ Object
43 44 45 |
# File 'lib/raif/embedding_model_registry.rb', line 43 def self. .keys end |
.available_embedding_models ⇒ Object
39 40 41 |
# File 'lib/raif/embedding_model_registry.rb', line 39 def self. .values end |
.available_llm_keys ⇒ Object
34 35 36 |
# File 'lib/raif/llm_registry.rb', line 34 def self.available_llm_keys llm_registry.keys end |
.available_llms ⇒ Object
30 31 32 |
# File 'lib/raif/llm_registry.rb', line 30 def self.available_llms llm_registry.values end |
.config ⇒ Object
27 28 29 |
# File 'lib/raif.rb', line 27 def self.config @configuration ||= Raif::Configuration.new end |
.configure {|config| ... } ⇒ Object
31 32 33 |
# File 'lib/raif.rb', line 31 def self.configure yield(config) end |
.default_embedding_model_key ⇒ Object
13 14 15 |
# File 'lib/raif/embedding_model_registry.rb', line 13 def self. Rails.env.test? ? :raif_test_embedding_model : Raif.config. end |
.default_embedding_models ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/raif/embedding_model_registry.rb', line 51 def self. { Raif::EmbeddingModels::OpenAi => [ { key: :open_ai_text_embedding_3_large, api_name: "text-embedding-3-large", input_token_cost: 0.13 / 1_000_000, default_output_vector_size: 3072, }, { key: :open_ai_text_embedding_3_small, api_name: "text-embedding-3-small", input_token_cost: 0.02 / 1_000_000, default_output_vector_size: 1536, }, { key: :open_ai_text_embedding_ada_002, api_name: "text-embedding-ada-002", input_token_cost: 0.01 / 1_000_000, default_output_vector_size: 1536, }, ], Raif::EmbeddingModels::BedrockTitan => [ { key: :bedrock_titan_embed_text_v2, api_name: "amazon.titan-embed-text-v2:0", input_token_cost: 0.01 / 1_000_000, default_output_vector_size: 1024, }, ] } end |
.default_llms ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/raif/llm_registry.rb', line 42 def self.default_llms { Raif::Llms::OpenAi => [ { key: :open_ai_gpt_4o_mini, api_name: "gpt-4o-mini", input_token_cost: 0.15 / 1_000_000, output_token_cost: 0.6 / 1_000_000, }, { key: :open_ai_gpt_4o, api_name: "gpt-4o", input_token_cost: 2.5 / 1_000_000, output_token_cost: 10.0 / 1_000_000, }, { key: :open_ai_gpt_3_5_turbo, api_name: "gpt-3.5-turbo", input_token_cost: 0.5 / 1_000_000, output_token_cost: 1.5 / 1_000_000, model_provider_settings: { supports_structured_outputs: false } }, { key: :open_ai_gpt_4_1, api_name: "gpt-4.1", input_token_cost: 2.0 / 1_000_000, output_token_cost: 8.0 / 1_000_000, }, { key: :open_ai_gpt_4_1_mini, api_name: "gpt-4.1-mini", input_token_cost: 0.4 / 1_000_000, output_token_cost: 1.6 / 1_000_000, }, { key: :open_ai_gpt_4_1_nano, api_name: "gpt-4.1-nano", input_token_cost: 0.1 / 1_000_000, output_token_cost: 0.4 / 1_000_000, }, ], Raif::Llms::Anthropic => [ { key: :anthropic_claude_4_sonnet, api_name: "claude-sonnet-4-20250514", input_token_cost: 3.0 / 1_000_000, output_token_cost: 15.0 / 1_000_000, max_completion_tokens: 8192 }, { key: :anthropic_claude_4_opus, api_name: "claude-opus-4-20250514", input_token_cost: 15.0 / 1_000_000, output_token_cost: 75.0 / 1_000_000, max_completion_tokens: 8192 }, { key: :anthropic_claude_3_7_sonnet, api_name: "claude-3-7-sonnet-latest", input_token_cost: 3.0 / 1_000_000, output_token_cost: 15.0 / 1_000_000, max_completion_tokens: 8192 }, { key: :anthropic_claude_3_5_sonnet, api_name: "claude-3-5-sonnet-latest", input_token_cost: 3.0 / 1_000_000, output_token_cost: 15.0 / 1_000_000, max_completion_tokens: 8192 }, { key: :anthropic_claude_3_5_haiku, api_name: "claude-3-5-haiku-latest", input_token_cost: 0.8 / 1_000_000, output_token_cost: 4.0 / 1_000_000, max_completion_tokens: 8192 }, { key: :anthropic_claude_3_opus, api_name: "claude-3-opus-latest", input_token_cost: 15.0 / 1_000_000, output_token_cost: 75.0 / 1_000_000, max_completion_tokens: 4096 }, ], Raif::Llms::BedrockClaude => [ { key: :bedrock_claude_4_sonnet, api_name: "anthropic.claude-sonnet-4-20250514-v1:0", input_token_cost: 0.003 / 1000, output_token_cost: 0.015 / 1000, max_completion_tokens: 8192 }, { key: :bedrock_claude_4_opus, api_name: "anthropic.claude-opus-4-20250514-v1:0", input_token_cost: 0.015 / 1000, output_token_cost: 0.075 / 1000, max_completion_tokens: 8192 }, { key: :bedrock_claude_3_5_sonnet, api_name: "anthropic.claude-3-5-sonnet-20241022-v2:0", input_token_cost: 0.003 / 1000, output_token_cost: 0.015 / 1000, max_completion_tokens: 8192 }, { key: :bedrock_claude_3_7_sonnet, api_name: "anthropic.claude-3-7-sonnet-20250219-v1:0", input_token_cost: 0.003 / 1000, output_token_cost: 0.015 / 1000, max_completion_tokens: 8192 }, { key: :bedrock_claude_3_5_haiku, api_name: "anthropic.claude-3-5-haiku-20241022-v1:0", input_token_cost: 0.0008 / 1000, output_token_cost: 0.004 / 1000, max_completion_tokens: 8192 }, { key: :bedrock_claude_3_opus, api_name: "anthropic.claude-3-opus-20240229-v1:0", input_token_cost: 0.015 / 1000, output_token_cost: 0.075 / 1000, max_completion_tokens: 4096 }, ], Raif::Llms::OpenRouter => [ { key: :open_router_claude_3_7_sonnet, api_name: "anthropic/claude-3.7-sonnet", input_token_cost: 3.0 / 1_000_000, output_token_cost: 15.0 / 1_000_000, }, { key: :open_router_llama_3_3_70b_instruct, api_name: "meta-llama/llama-3.3-70b-instruct", input_token_cost: 0.10 / 1_000_000, output_token_cost: 0.25 / 1_000_000, }, { key: :open_router_llama_3_1_8b_instruct, api_name: "meta-llama/llama-3.1-8b-instruct", input_token_cost: 0.02 / 1_000_000, output_token_cost: 0.03 / 1_000_000, }, { key: :open_router_gemini_2_0_flash, api_name: "google/gemini-2.0-flash-001", input_token_cost: 0.1 / 1_000_000, output_token_cost: 0.4 / 1_000_000, }, { key: :open_router_deepseek_chat_v3, api_name: "deepseek/deepseek-chat-v3-0324", input_token_cost: 0.27 / 1_000_000, output_token_cost: 1.1 / 1_000_000, }, ] } end |
.embedding_model(model_key) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/raif/embedding_model_registry.rb', line 28 def self.(model_key) = [model_key] if .nil? raise ArgumentError, "No embedding model found for model key: #{model_key}. Available models: #{.join(", ")}" end = [:embedding_model_class] .new(**.except(:embedding_model_class)) end |
.embedding_model_config(model_key) ⇒ Object
47 48 49 |
# File 'lib/raif/embedding_model_registry.rb', line 47 def self.(model_key) [model_key] end |
.generate_embedding!(input, dimensions: nil) ⇒ Object
8 9 10 11 |
# File 'lib/raif/embedding_model_registry.rb', line 8 def self.(input, dimensions: nil) = (.to_sym) .(input, dimensions:) end |
.llm(model_key) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/raif/llm_registry.rb', line 19 def self.llm(model_key) llm_config = llm_registry[model_key] if llm_config.nil? raise ArgumentError, "No LLM found for model key: #{model_key}. Available models: #{available_llm_keys.join(", ")}" end llm_class = llm_config[:llm_class] llm_class.new(**llm_config.except(:llm_class)) end |
.llm_config(model_key) ⇒ Object
38 39 40 |
# File 'lib/raif/llm_registry.rb', line 38 def self.llm_config(model_key) llm_registry[model_key] end |
.llm_registry ⇒ Object
4 5 6 |
# File 'lib/raif/llm_registry.rb', line 4 def self.llm_registry @llm_registry ||= {} end |
.register_embedding_model(embedding_model_class, embedding_model_config) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/raif/embedding_model_registry.rb', line 17 def self.(, ) = .new(**) unless .valid? raise ArgumentError, "The embedding model you tried to register is invalid: #{.errors..join(", ")}" end @embedding_model_registry ||= {} @embedding_model_registry[.key] = .merge(embedding_model_class: ) end |
.register_llm(llm_class, llm_config) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/raif/llm_registry.rb', line 8 def self.register_llm(llm_class, llm_config) llm = llm_class.new(**llm_config) unless llm.valid? raise ArgumentError, "The LLM you tried to register is invalid: #{llm.errors..join(", ")}" end @llm_registry ||= {} @llm_registry[llm.key] = llm_config.merge(llm_class: llm_class) end |
.supported_languages ⇒ Object
30 31 32 |
# File 'lib/raif/languages.rb', line 30 def self.supported_languages SUPPORTED_LANGUAGES end |