source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/model_completion.rb | Ruby | mit | 296 | main | 5,733 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_model_completions
#
# id :bigint not null, primary key
# available_model_tools :jsonb not null
# cache_creation_input_tokens :integer
# cache_read_input_tokens :integer
# citations ... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/application_record.rb | Ruby | mit | 296 | main | 1,013 | # frozen_string_literal: true
class Raif::ApplicationRecord < Raif.config.model_superclass.constantize
include Raif::Concerns::BooleanTimestamp
self.abstract_class = true
scope :newest_first, -> { order(created_at: :desc) }
scope :oldest_first, -> { order(created_at: :asc) }
# Returns a scope that checks ... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/conversation_entry.rb | Ruby | mit | 296 | main | 11,890 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_conversation_entries
#
# id :bigint not null, primary key
# completed_at :datetime
# creator_type :string not null
# failed_at :datetime
# model_response_message :tex... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/user_tool_invocation.rb | Ruby | mit | 296 | main | 1,266 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_user_tool_invocations
#
# id :bigint not null, primary key
# tool_settings :jsonb not null
# type :string not null
# created_at :datet... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/embedding_model.rb | Ruby | mit | 296 | main | 641 | # frozen_string_literal: true
class Raif::EmbeddingModel
include ActiveModel::Model
attr_accessor :key,
:api_name,
:display_name,
:input_token_cost,
:default_output_vector_size
validates :default_output_vector_size, presence: true, numericality: { only_integer: true, greater_than: 0 }
validat... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/streaming_responses/anthropic.rb | Ruby | mit | 296 | main | 1,913 | # frozen_string_literal: true
class Raif::StreamingResponses::Anthropic
def initialize
@response_json = { "content" => [], "usage" => {} }
@finish_reason = nil
end
def process_streaming_event(event_type, event)
delta = nil
index = event["index"]
case event_type
when "message_start"
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/streaming_responses/bedrock.rb | Ruby | mit | 296 | main | 4,842 | # frozen_string_literal: true
class Raif::StreamingResponses::Bedrock
def initialize_new_message
@reasoning_content_blocks = {}
# Initialize empty AWS response object
@message = Aws::BedrockRuntime::Types::Message.new(
role: "assistant",
content: []
)
@output = Aws::BedrockRuntime:... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/streaming_responses/open_ai_responses.rb | Ruby | mit | 296 | main | 1,551 | # frozen_string_literal: true
class Raif::StreamingResponses::OpenAiResponses
def initialize
@output_items = []
@finish_reason = nil
end
def process_streaming_event(event_type, event)
output_index = event["output_index"]
content_index = event["content_index"]
delta = nil
case event["t... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/streaming_responses/open_ai_completions.rb | Ruby | mit | 296 | main | 2,184 | # frozen_string_literal: true
class Raif::StreamingResponses::OpenAiCompletions
attr_reader :raw_response, :tool_calls
def initialize
@id = nil
@raw_response = ""
@tool_calls = []
@usage = {}
@finish_reason = nil
@response_json = {}
end
def process_streaming_event(event_type, event)
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/streaming_responses/google.rb | Ruby | mit | 296 | main | 2,157 | # frozen_string_literal: true
class Raif::StreamingResponses::Google
def initialize
@response_json = { "candidates" => [{ "content" => { "parts" => [] } }], "usageMetadata" => {} }
@finish_reason = nil
end
def process_streaming_event(event_type, event)
delta = nil
# Google streams complete can... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/llms/open_router.rb | Ruby | mit | 296 | main | 4,949 | # frozen_string_literal: true
class Raif::Llms::OpenRouter < Raif::Llm
include Raif::Concerns::Llms::OpenAiCompletions::MessageFormatting
include Raif::Concerns::Llms::OpenAiCompletions::ToolFormatting
include Raif::Concerns::Llms::OpenAiCompletions::ResponseToolCalls
include Raif::Concerns::Llms::OpenAi::Json... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/llms/open_ai_responses.rb | Ruby | mit | 296 | main | 4,805 | # frozen_string_literal: true
class Raif::Llms::OpenAiResponses < Raif::Llms::OpenAiBase
include Raif::Concerns::Llms::OpenAiResponses::MessageFormatting
include Raif::Concerns::Llms::OpenAiResponses::ToolFormatting
include Raif::Concerns::Llms::OpenAiResponses::ResponseToolCalls
private
def api_path
"re... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/llms/open_ai_base.rb | Ruby | mit | 296 | main | 2,824 | # frozen_string_literal: true
class Raif::Llms::OpenAiBase < Raif::Llm
include Raif::Concerns::Llms::OpenAi::JsonSchemaValidation
def self.cache_read_input_token_cost_multiplier
0.5
end
def perform_model_completion!(model_completion, &block)
if supports_temperature?
model_completion.temperature... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/llms/google.rb | Ruby | mit | 296 | main | 5,816 | # frozen_string_literal: true
class Raif::Llms::Google < Raif::Llm
include Raif::Concerns::Llms::Google::MessageFormatting
include Raif::Concerns::Llms::Google::ToolFormatting
include Raif::Concerns::Llms::Google::ResponseToolCalls
def self.cache_read_input_token_cost_multiplier
0.25
end
def perform_... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/llms/open_ai_completions.rb | Ruby | mit | 296 | main | 3,499 | # frozen_string_literal: true
class Raif::Llms::OpenAiCompletions < Raif::Llms::OpenAiBase
include Raif::Concerns::Llms::OpenAiCompletions::MessageFormatting
include Raif::Concerns::Llms::OpenAiCompletions::ToolFormatting
include Raif::Concerns::Llms::OpenAiCompletions::ResponseToolCalls
private
def api_path... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/llms/anthropic.rb | Ruby | mit | 296 | main | 4,847 | # frozen_string_literal: true
class Raif::Llms::Anthropic < Raif::Llm
include Raif::Concerns::Llms::Anthropic::MessageFormatting
include Raif::Concerns::Llms::Anthropic::ToolFormatting
include Raif::Concerns::Llms::Anthropic::ResponseToolCalls
def self.prompt_tokens_include_cached_tokens?
false
end
d... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/llms/bedrock.rb | Ruby | mit | 296 | main | 6,783 | # frozen_string_literal: true
class Raif::Llms::Bedrock < Raif::Llm
include Raif::Concerns::Llms::Bedrock::MessageFormatting
include Raif::Concerns::Llms::Bedrock::ToolFormatting
include Raif::Concerns::Llms::Bedrock::ResponseToolCalls
def self.prompt_tokens_include_cached_tokens?
false
end
def self.... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/embedding_models/bedrock.rb | Ruby | mit | 296 | main | 1,259 | # frozen_string_literal: true
class Raif::EmbeddingModels::Bedrock < Raif::EmbeddingModel
def generate_embedding!(input, dimensions: nil)
unless input.is_a?(String)
raise ArgumentError, "Raif::EmbeddingModels::Bedrock#generate_embedding! input must be a string"
end
params = build_request_paramete... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/embedding_models/google.rb | Ruby | mit | 296 | main | 1,020 | # frozen_string_literal: true
class Raif::EmbeddingModels::Google < Raif::EmbeddingModel
def generate_embedding!(input, dimensions: nil)
unless input.is_a?(String)
raise ArgumentError, "Raif::EmbeddingModels::Google#generate_embedding! input must be a string"
end
response = connection.post("models... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/embedding_models/open_ai.rb | Ruby | mit | 296 | main | 1,114 | # frozen_string_literal: true
class Raif::EmbeddingModels::OpenAi < Raif::EmbeddingModel
def generate_embedding!(input, dimensions: nil)
unless input.is_a?(String) || input.is_a?(Array)
raise ArgumentError, "Raif::EmbeddingModels::OpenAi#generate_embedding! input must be a string or an array of strings"
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/model_tools/wikipedia_search.rb | Ruby | mit | 296 | main | 1,879 | # frozen_string_literal: true
class Raif::ModelTools::WikipediaSearch < Raif::ModelTool
tool_arguments_schema do
string "query", description: "The query to search Wikipedia for"
end
example_model_invocation do
{
"name" => tool_name,
"arguments" => { "query": "Jimmy Buffett" }
}
end
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/model_tools/agent_final_answer.rb | Ruby | mit | 296 | main | 839 | # frozen_string_literal: true
class Raif::ModelTools::AgentFinalAnswer < Raif::ModelTool
tool_arguments_schema do
string "final_answer", description: "Your complete and final answer to the user's question or task"
end
example_model_invocation do
{
"name" => tool_name,
"arguments" => { "final... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/model_tools/fetch_url.rb | Ruby | mit | 296 | main | 1,235 | # frozen_string_literal: true
class Raif::ModelTools::FetchUrl < Raif::ModelTool
tool_arguments_schema do
string "url", description: "The URL to fetch content from"
end
example_model_invocation do
{
"name": tool_name,
"arguments": { "url": "https://en.wikipedia.org/wiki/NASA" }
}
end
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/model_tools/provider_managed/image_generation.rb | Ruby | mit | 296 | main | 240 | # frozen_string_literal: true
class Raif::ModelTools::ProviderManaged::ImageGeneration < Raif::ModelTools::ProviderManaged::Base
tool_description do
"Utilizes the model provider's built-in image generation capabilities."
end
end |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/model_tools/provider_managed/web_search.rb | Ruby | mit | 296 | main | 228 | # frozen_string_literal: true
class Raif::ModelTools::ProviderManaged::WebSearch < Raif::ModelTools::ProviderManaged::Base
tool_description do
"Utilizes the model provider's built-in web search capabilities."
end
end |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/model_tools/provider_managed/code_execution.rb | Ruby | mit | 296 | main | 236 | # frozen_string_literal: true
class Raif::ModelTools::ProviderManaged::CodeExecution < Raif::ModelTools::ProviderManaged::Base
tool_description do
"Utilizes the model provider's built-in code execution capabilities."
end
end |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/agents/native_tool_calling_agent.rb | Ruby | mit | 296 | main | 10,507 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_agents
#
# id :bigint not null, primary key
# available_model_tools :jsonb not null
# completed_at :datetime
# conversation_history :jsonb not null
# creator_type :... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/evals/scoring_rubric.rb | Ruby | mit | 296 | main | 7,453 | # frozen_string_literal: true
module Raif
module Evals
# ScoringRubric provides a standardized way to define evaluation criteria with
# multiple scoring levels. Each level can define either a score range or a single
# score value, along with descriptive text explaining what qualifies for that score.
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/evals/llm_judge.rb | Ruby | mit | 296 | main | 2,380 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_tasks
#
# id :bigint not null, primary key
# available_model_tools :jsonb not null
# completed_at :datetime
# creator_type :string
# failed_at :datetime
# llm_mode... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/evals/llm_judges/summarization.rb | Ruby | mit | 296 | main | 9,383 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_tasks
#
# id :bigint not null, primary key
# available_model_tools :jsonb not null
# completed_at :datetime
# creator_type :string
# failed_at :datetime
# llm_mode... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/evals/llm_judges/binary.rb | Ruby | mit | 296 | main | 4,232 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_tasks
#
# id :bigint not null, primary key
# available_model_tools :jsonb not null
# completed_at :datetime
# creator_type :string
# failed_at :datetime
# llm_mode... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/evals/llm_judges/comparative.rb | Ruby | mit | 296 | main | 4,344 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_tasks
#
# id :bigint not null, primary key
# available_model_tools :jsonb not null
# completed_at :datetime
# creator_type :string
# failed_at :datetime
# llm_mode... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/evals/llm_judges/scored.rb | Ruby | mit | 296 | main | 3,420 | # frozen_string_literal: true
# == Schema Information
#
# Table name: raif_tasks
#
# id :bigint not null, primary key
# available_model_tools :jsonb not null
# completed_at :datetime
# creator_type :string
# failed_at :datetime
# llm_mode... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/run_with.rb | Ruby | mit | 296 | main | 4,115 | # frozen_string_literal: true
module Raif::Concerns::RunWith
extend ActiveSupport::Concern
included do
class_attribute :_run_with_args, instance_writer: false, default: []
# Backward compatibility alias
class_attribute :_task_run_args, instance_writer: false, default: []
# Automatically serializ... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/has_prompt_templates.rb | Ruby | mit | 296 | main | 2,584 | # frozen_string_literal: true
module Raif
module Concerns
module HasPromptTemplates
extend ActiveSupport::Concern
class TemplateContext < ActionView::Base.with_empty_template_cache
def initialize(lookup_context, instance)
super(lookup_context, {}, nil)
@_instance = instan... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/json_schema_definition.rb | Ruby | mit | 296 | main | 3,723 | # frozen_string_literal: true
module Raif
module Concerns
module JsonSchemaDefinition
extend ActiveSupport::Concern
class_methods do
def json_schema_definition(schema_name, dynamic: false, &block)
raise ArgumentError, "A block must be provided to define the JSON schema" unless bloc... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/tool_call_validation.rb | Ruby | mit | 296 | main | 3,342 | # frozen_string_literal: true
# Shared validation logic for developer-managed tool calls returned by an LLM.
# Produces a structured result so callers (agents, conversations) can apply
# their own retry/error semantics.
#
# Validation checks, in order:
# 1. Tool exists in the provided tool map.
# 2. `prepare_tool_argu... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/has_requested_language.rb | Ruby | mit | 296 | main | 590 | # frozen_string_literal: true
module Raif::Concerns::HasRequestedLanguage
extend ActiveSupport::Concern
included do
validates :requested_language_key, inclusion: { in: Raif.supported_languages, allow_blank: true }
end
def requested_language_name
@requested_language_name ||= I18n.t("raif.languages.#{r... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/has_llm.rb | Ruby | mit | 296 | main | 433 | # frozen_string_literal: true
module Raif::Concerns::HasLlm
extend ActiveSupport::Concern
included do
validates :llm_model_key, presence: true, inclusion: { in: ->{ Raif.available_llm_keys.map(&:to_s) } }
before_validation ->{ self.llm_model_key ||= default_llm_model_key }
end
def default_llm_model_... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llm_temperature.rb | Ruby | mit | 296 | main | 430 | # frozen_string_literal: true
module Raif::Concerns::LlmTemperature
extend ActiveSupport::Concern
included do
class_attribute :temperature, instance_writer: false
end
class_methods do
def llm_temperature(temperature)
raise ArgumentError, "temperature must be a number between 0 and 1" unless tem... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/provider_managed_tool_calls.rb | Ruby | mit | 296 | main | 5,891 | # frozen_string_literal: true
module Raif::Concerns::ProviderManagedToolCalls
extend ActiveSupport::Concern
# Provider-managed tool data is not normalized by the provider SDKs the same
# way developer-managed tool calls are. This method smooths those differences
# into one admin-friendly structure for the mod... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/has_available_model_tools.rb | Ruby | mit | 296 | main | 332 | # frozen_string_literal: true
module Raif::Concerns::HasAvailableModelTools
extend ActiveSupport::Concern
def available_model_tools_map
available_model_tools&.map do |tool_name|
tool_klass = tool_name.is_a?(String) ? tool_name.constantize : tool_name
[tool_klass.tool_name, tool_klass]
end.to_h... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/boolean_timestamp.rb | Ruby | mit | 296 | main | 2,776 | # frozen_string_literal: true
module Raif::Concerns::BooleanTimestamp
extend ActiveSupport::Concern
class_methods do
# Column name should be something like email_abc_disabled_at, or its inverse should be specified
def boolean_timestamp(column_name, define_inverse_accessors: false)
if define_inverse_... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/invokes_model_tools.rb | Ruby | mit | 296 | main | 265 | # frozen_string_literal: true
module Raif::Concerns::InvokesModelTools
extend ActiveSupport::Concern
included do
has_many :raif_model_tool_invocations,
class_name: "Raif::ModelToolInvocation",
as: :source,
dependent: :destroy
end
end |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llm_prompt_caching.rb | Ruby | mit | 296 | main | 535 | # frozen_string_literal: true
module Raif::Concerns::LlmPromptCaching
extend ActiveSupport::Concern
included do
class_attribute :anthropic_prompt_caching_enabled, instance_writer: false, default: false
class_attribute :bedrock_prompt_caching_enabled, instance_writer: false, default: false
end
class_m... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llm_response_parsing.rb | Ruby | mit | 296 | main | 2,176 | # frozen_string_literal: true
module Raif::Concerns::LlmResponseParsing
extend ActiveSupport::Concern
ASCII_CONTROL_CHARS = /[\x00-\x1f\x7f]/
included do
normalizes :raw_response, with: ->(text){ text&.strip }
enum :response_format, Raif::Llm.valid_response_formats, prefix: true
validates :respon... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/agent_inference_stats.rb | Ruby | mit | 296 | main | 1,172 | # frozen_string_literal: true
module Raif::Concerns::AgentInferenceStats
extend ActiveSupport::Concern
# Returns the total number of prompt tokens across all model completions
def total_prompt_tokens
@total_prompt_tokens ||= raif_model_completions.sum(:prompt_tokens)
end
# Returns the total number of c... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/has_runtime_duration.rb | Ruby | mit | 296 | main | 1,126 | # frozen_string_literal: true
module Raif::Concerns::HasRuntimeDuration
extend ActiveSupport::Concern
def runtime_ended_at
completed_at || failed_at
end
def runtime_duration_seconds
return if started_at.blank? || runtime_ended_at.blank?
duration_in_seconds = runtime_ended_at - started_at
ret... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/message_formatting.rb | Ruby | mit | 296 | main | 2,728 | # frozen_string_literal: true
module Raif::Concerns::Llms::MessageFormatting
extend ActiveSupport::Concern
def format_messages(messages)
messages.map do |message|
if message.is_a?(Hash) && message["type"] == "tool_call"
format_tool_call_message(message)
elsif message.is_a?(Hash) && message... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/open_ai_responses/response_tool_calls.rb | Ruby | mit | 296 | main | 666 | # frozen_string_literal: true
module Raif::Concerns::Llms::OpenAiResponses::ResponseToolCalls
extend ActiveSupport::Concern
def extract_response_tool_calls(resp)
return if resp["output"].blank?
tool_calls = []
resp["output"].each do |output_item|
next unless output_item["type"] == "function_cal... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/open_ai_responses/message_formatting.rb | Ruby | mit | 296 | main | 1,982 | # frozen_string_literal: true
module Raif::Concerns::Llms::OpenAiResponses::MessageFormatting
extend ActiveSupport::Concern
def format_string_message(content, role: nil)
if role == "assistant"
{ "type" => "output_text", "text" => content }
else
{ "type" => "input_text", "text" => content }
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/open_ai_responses/tool_formatting.rb | Ruby | mit | 296 | main | 1,415 | # frozen_string_literal: true
module Raif::Concerns::Llms::OpenAiResponses::ToolFormatting
extend ActiveSupport::Concern
def build_tools_parameter(model_completion)
model_completion.available_model_tools_map.map do |_tool_name, tool|
if tool.provider_managed?
format_provider_managed_tool(tool)
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/open_ai_completions/tool_formatting.rb | Ruby | mit | 296 | main | 1,037 | # frozen_string_literal: true
module Raif::Concerns::Llms::OpenAiCompletions::ToolFormatting
extend ActiveSupport::Concern
def build_tools_parameter(model_completion)
model_completion.available_model_tools_map.map do |_tool_name, tool|
if tool.provider_managed?
raise Raif::Errors::UnsupportedFea... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/open_ai_completions/message_formatting.rb | Ruby | mit | 296 | main | 1,972 | # frozen_string_literal: true
module Raif::Concerns::Llms::OpenAiCompletions::MessageFormatting
extend ActiveSupport::Concern
def format_model_image_input_message(image_input)
if image_input.source_type == :url
{
"type" => "image_url",
"image_url" => { "url" => image_input.url }
}
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/open_ai_completions/response_tool_calls.rb | Ruby | mit | 296 | main | 614 | # frozen_string_literal: true
module Raif::Concerns::Llms::OpenAiCompletions::ResponseToolCalls
extend ActiveSupport::Concern
def extract_response_tool_calls(resp)
tool_calls = resp&.dig("choices", 0, "message", "tool_calls")
return if tool_calls.blank?
tool_calls.map do |tool_call|
{
"... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/anthropic/response_tool_calls.rb | Ruby | mit | 296 | main | 572 | # frozen_string_literal: true
module Raif::Concerns::Llms::Anthropic::ResponseToolCalls
extend ActiveSupport::Concern
def extract_response_tool_calls(resp)
return if resp&.dig("content").nil?
# Find any tool_use content blocks
tool_uses = resp&.dig("content")&.select do |content|
content["type"... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/anthropic/tool_formatting.rb | Ruby | mit | 296 | main | 1,990 | # frozen_string_literal: true
module Raif::Concerns::Llms::Anthropic::ToolFormatting
extend ActiveSupport::Concern
def build_tools_parameter(model_completion)
tools = []
# If we're looking for a JSON response, add a tool to the request that the model can use to provide a JSON response
if model_comple... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/anthropic/message_formatting.rb | Ruby | mit | 296 | main | 2,465 | # frozen_string_literal: true
module Raif::Concerns::Llms::Anthropic::MessageFormatting
extend ActiveSupport::Concern
def format_messages(messages)
# Anthropic tool results come back as user-role content blocks, so conversation
# continuations may need adjacent user messages collapsed after formatting.
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/google/tool_formatting.rb | Ruby | mit | 296 | main | 2,196 | # frozen_string_literal: true
module Raif::Concerns::Llms::Google::ToolFormatting
extend ActiveSupport::Concern
def build_tools_parameter(model_completion)
tools = []
function_declarations = []
# If we support native tool use and have tools available, add them to the request
if supports_native_to... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/google/response_tool_calls.rb | Ruby | mit | 296 | main | 986 | # frozen_string_literal: true
module Raif::Concerns::Llms::Google::ResponseToolCalls
extend ActiveSupport::Concern
def extract_response_tool_calls(resp)
parts = resp&.dig("candidates", 0, "content", "parts")
return if parts.blank?
# Find any functionCall parts
function_calls = parts.select { |par... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/google/message_formatting.rb | Ruby | mit | 296 | main | 3,315 | # frozen_string_literal: true
module Raif::Concerns::Llms::Google::MessageFormatting
extend ActiveSupport::Concern
# Google uses a different envelope ("parts") and also represents tool results as
# user-role messages, so we normalize adjacent same-role messages after formatting.
def format_messages(messages)
... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/open_ai/json_schema_validation.rb | Ruby | mit | 296 | main | 4,051 | # frozen_string_literal: true
module Raif::Concerns::Llms::OpenAi::JsonSchemaValidation
extend ActiveSupport::Concern
def validate_json_schema!(schema)
return if schema.blank?
errors = []
# Check if schema is present
if schema.blank?
errors << "JSON schema must include a 'schema' property"... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/bedrock/tool_formatting.rb | Ruby | mit | 296 | main | 1,324 | # frozen_string_literal: true
module Raif::Concerns::Llms::Bedrock::ToolFormatting
extend ActiveSupport::Concern
def build_tools_parameter(model_completion)
tools = []
# If we're looking for a JSON response, add a tool to the request that the model can use to provide a JSON response
if model_completi... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/bedrock/response_tool_calls.rb | Ruby | mit | 296 | main | 1,382 | # frozen_string_literal: true
module Raif::Concerns::Llms::Bedrock::ResponseToolCalls
extend ActiveSupport::Concern
def extract_response_tool_calls(resp)
# Get the message from the response object
message = resp.output.message
return if message.content.nil?
# Find any tool_use blocks in the conte... |
github | CultivateLabs/raif | https://github.com/CultivateLabs/raif | app/models/raif/concerns/llms/bedrock/message_formatting.rb | Ruby | mit | 296 | main | 4,240 | # frozen_string_literal: true
module Raif::Concerns::Llms::Bedrock::MessageFormatting
extend ActiveSupport::Concern
def format_messages(messages)
# Bedrock tool results are represented as user-role content blocks, so a
# tool_result followed by the next user prompt must be merged into one user
# messa... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | Rakefile | Ruby | mit | 296 | main | 816 | # encoding: utf-8
require 'rubygems'
begin
require 'bundler/setup'
rescue LoadError => e
warn e.message
warn "Run `gem install bundler` to install Bundler"
exit -1
end
require 'rake'
require 'rake/clean'
CLEAN.include('spec/*.xml')
require 'rubygems/tasks'
Gem::Tasks.new
require 'rspec/core/rake_task'
RSpe... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | Gemfile | Ruby | mit | 296 | main | 480 | source 'https://rubygems.org'
gemspec
# gem 'command_mapper', '~> 0.3', github: 'postmodern/command_mapper.rb',
# branch: '0.3.0'
group :development do
gem 'rake'
gem 'rubygems-tasks', '~> 0.2'
gem 'rspec', '~> 3.0'
gem 'simplecov', '~> 0.20'
gem 'kramdown'... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | ruby-nmap.gemspec | Ruby | mit | 296 | main | 1,954 | # encoding: utf-8
require 'yaml'
Gem::Specification.new do |gem|
gemspec = YAML.load_file('gemspec.yml')
gem.name = gemspec.fetch('name')
gem.version = gemspec.fetch('version') do
require_relative 'lib/nmap/version'
Nmap::VERSION
end
gem.summary = g... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/command_spec.rb | Ruby | mit | 296 | main | 37,317 | require 'spec_helper'
require 'nmap/command'
describe Nmap::Command do
describe described_class::Port do
describe "#validate" do
context "when given an Integer" do
let(:value) { 443 }
it "must return true" do
expect(subject.validate(value)).to be(true)
end
contex... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/spec_helper.rb | Ruby | mit | 296 | main | 278 | require 'rspec'
require 'simplecov'
SimpleCov.start
require 'nmap/version'
require 'nmap/xml'
include Nmap
RSpec.configure do |spec|
spec.before(:all) do
@xml = XML.open('spec/fixtures/scan.xml')
@local_xml = XML.open('spec/fixtures/local_scan.xml')
end
end |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml_spec.rb | Ruby | mit | 296 | main | 7,443 | require 'spec_helper'
require 'nmap/xml'
describe Nmap::XML do
let(:file) { 'spec/fixtures/scan.xml' }
let(:path) { File.expand_path(file) }
let(:doc) { Nokogiri::XML(File.open(path)) }
subject { described_class.new(doc) }
describe "#initialize" do
it "must set #doc" do
expect(described_class.ne... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/status_spec.rb | Ruby | mit | 296 | main | 348 | require 'spec_helper'
require 'nmap/xml/status'
describe Nmap::XML::Status do
describe "#to_s" do
let(:state) { :up }
let(:reason) { 'syn-ack' }
let(:reason_ttl) { 100 }
subject { described_class.new(state,reason,reason_ttl) }
it "should return the state" do
expect(subject.to_s).to eq(st... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/os_match_spec.rb | Ruby | mit | 296 | main | 359 | require 'spec_helper'
require 'nmap/xml/os_match'
describe Nmap::XML::OSMatch do
describe "#to_s" do
let(:name) { 'Linux 2.6.39' }
let(:accuracy) { 97 }
subject { described_class.new(name,accuracy) }
it "should include the name and accuracy" do
expect(subject.to_s).to eq("#{na... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/scanner_spec.rb | Ruby | mit | 296 | main | 545 | require 'spec_helper'
require 'nmap/xml/scanner'
describe Nmap::XML::Scanner do
describe "#to_s" do
let(:name) { 'nmap' }
let(:version) { '6.01' }
let(:args) { 'nmap -v -sS -sU -A -O -oX spec/scan.xml scanme.nmap.org' }
let(:start_time) { Time.parse('Sat Jul 20 23:55:27 2013') }
subject do... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/run_stat_spec.rb | Ruby | mit | 296 | main | 625 | require 'spec_helper'
require 'nmap/xml/run_stat'
describe Nmap::XML::RunStat do
subject { @xml.run_stats.first }
describe "#to_s" do
let(:end_time) { Time.parse('2013-07-21 00:14:33 -0700') }
let(:elapsed) { '1145.71' }
let(:summary) do
"Nmap done at Sun Jul 21 00:14:33 2013; 1 IP addres... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/sequence_examples.rb | Ruby | mit | 296 | main | 248 | require 'spec_helper'
shared_examples_for "Sequence" do
describe "#values" do
subject { super().values }
it 'has 6 items' do
expect(subject.size).to eq(6)
end
it { is_expected.to all(be_between(0,0xFFFFFFFF)) }
end
end |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/scan_spec.rb | Ruby | mit | 296 | main | 644 | require 'spec_helper'
require 'nmap/xml/scan'
describe Nmap::XML::Scan do
let(:type) { :syn }
let(:protocol) { :tcp }
describe "#initialize" do
subject { described_class.new(type,protocol) }
it "should accept a type and protocol" do
expect(subject.type).to eq(type)
expect(subject.protoc... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/os_class_spec.rb | Ruby | mit | 296 | main | 797 | require 'spec_helper'
require 'xml/cpe_examples'
require 'nmap/xml/os'
require 'cgi'
describe Nmap::XML::OS do
subject { @xml.hosts.first.os.classes.first }
describe "#type" do
it "should parse the type" do
expect(subject.type).to eq(:"general purpose")
end
end
describe "#vendor" do
it "sh... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/scan_task_spec.rb | Ruby | mit | 296 | main | 823 | require 'spec_helper'
require 'nmap/xml/scan_task'
describe Nmap::XML::ScanTask do
let(:name) { 'SYN Stealth Scan' }
let(:end_time) { Time.now }
let(:duration) { 10 }
let(:start_time) { end_time - duration }
let(:extra_info) { '1000 total ports' }
subject do
described_class.new(
name,... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/traceroute_spec.rb | Ruby | mit | 296 | main | 917 | require 'spec_helper'
require 'nmap/xml/traceroute'
describe Nmap::XML::Traceroute do
subject { @xml.hosts.first.traceroute }
describe "#port" do
subject { super().port }
it { is_expected.to be_kind_of(Integer) }
it { is_expected.to be > 0 }
it { is_expected.to be < 65535 }
end
describe "#pr... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/cpe_examples.rb | Ruby | mit | 296 | main | 215 | require 'rspec'
shared_examples_for "CPE" do
subject { super().cpe }
it { is_expected.not_to be_empty }
it "should contain CPE URLs" do
expect(subject).to all(be_kind_of(Nmap::XML::CPE::URL))
end
end |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/hop_spec.rb | Ruby | mit | 296 | main | 275 | require 'spec_helper'
require 'nmap/xml/hop'
describe Nmap::XML::Hop do
describe "#to_s" do
subject do
described_class.new('10.0.0.1', nil, '1', '3.38')
end
it "should return the addr" do
expect(subject.to_s).to eq(subject.addr)
end
end
end |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/scripts_examples.rb | Ruby | mit | 296 | main | 465 | require 'rspec'
require 'nmap/xml/script'
shared_examples_for "#scripts" do
describe "#scripts" do
subject { super().scripts }
it { is_expected.to be_kind_of(Hash) }
it { is_expected.not_to be_empty }
it "should contain String keys" do
expect(subject.keys).to all(be_kind_of(String))
e... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/service_spec.rb | Ruby | mit | 296 | main | 2,851 | require 'spec_helper'
require 'xml/cpe_examples'
require 'nmap/xml'
require 'nmap/xml/service'
describe Nmap::XML::Service do
let(:port) { @xml.host.open_ports.find { |port| port.number == 80 } }
subject { port.service }
describe "#name" do
it "should parse the name" do
expect(subject.name).to eq('h... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/address_spec.rb | Ruby | mit | 296 | main | 280 | require 'spec_helper'
require 'nmap/xml/address'
describe Nmap::XML::Address do
describe "#to_s" do
let(:addr) { '127.0.0.1' }
subject { described_class.new(:ipv4, addr) }
it "should return the address" do
expect(subject.to_s).to eq(addr)
end
end
end |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/uptime_spec.rb | Ruby | mit | 296 | main | 391 | require 'spec_helper'
require 'nmap/xml/uptime'
describe Nmap::XML::Uptime do
describe "#to_s" do
let(:seconds) { 920430 }
let(:last_boot) { Time.parse("2013-07-10 08:34:03 -0700") }
subject { described_class.new(seconds,last_boot) }
it "should convert the uptipe to a String" do
expect(subj... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/tcp_sequence_spec.rb | Ruby | mit | 296 | main | 891 | require 'spec_helper'
require 'xml/sequence_examples'
require 'nmap/xml/tcp_sequence'
describe Nmap::XML::TcpSequence do
subject { @xml.hosts.first.tcp_sequence }
describe "#index" do
it "should parse the index" do
expect(subject.index).to be > 0
end
end
describe "#description" do
it "shou... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/hostname_spec.rb | Ruby | mit | 296 | main | 654 | require 'spec_helper'
require 'nmap/xml/hostname'
describe Nmap::XML::Hostname do
let(:name) { 'scanme.nmap.org' }
describe "#user?" do
subject { described_class.new('user', name) }
it "should check if type is 'user'" do
expect(subject.user?).to eq(true)
end
end
describe "#user?" do
su... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/os_spec.rb | Ruby | mit | 296 | main | 1,510 | require 'spec_helper'
require 'nmap/xml/os'
require 'cgi'
describe Nmap::XML::OS do
subject { @xml.hosts.first.os }
describe "#classes" do
subject { super().classes }
it { is_expected.not_to be_empty }
it "should return OSClass objects" do
expect(subject).to all(be_kind_of(Nmap::XML::OSClass)... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/ip_id_sequence_spec.rb | Ruby | mit | 296 | main | 701 | require 'spec_helper'
require 'xml/sequence_examples'
require 'nmap/xml/ip_id_sequence'
describe Nmap::XML::IpIdSequence do
subject { @xml.hosts.first.ip_id_sequence }
describe "#description" do
it "should parse the description" do
expect(subject.description).to eq("All zeros")
end
end
describ... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/host_spec.rb | Ruby | mit | 296 | main | 5,182 | require 'spec_helper'
require 'xml/scripts_examples'
require 'nmap/xml'
require 'nmap/xml/host'
describe Nmap::XML::Host do
subject { @xml.hosts.first }
describe "#start_time" do
it "should parse the start_time" do
expect(subject.start_time).to be > Time.at(0)
end
end
describe "#end_time" do
... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/script_spec.rb | Ruby | mit | 296 | main | 6,554 | require 'spec_helper'
require 'nmap/xml/script'
describe Nmap::XML::Script do
let(:id) { 'ssh-hostkey' }
subject { @xml.hosts.first.ports.first.scripts[id] }
describe "#id" do
it "must return the 'id' attribute" do
expect(subject.id).to eq(id)
end
end
describe "#output" do
it "must retur... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/port_spec.rb | Ruby | mit | 296 | main | 1,122 | require 'spec_helper'
require 'xml/scripts_examples'
require 'nmap/xml/port'
describe Nmap::XML::Port do
subject { @xml.hosts.first.ports.first }
describe "#protocol" do
it "should parse the protocol" do
expect(subject.protocol).to eq(:tcp)
end
end
describe "#number" do
it "should parse th... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/tcp_ts_sequence_spec.rb | Ruby | mit | 296 | main | 717 | require 'spec_helper'
require 'xml/sequence_examples'
require 'nmap/xml/tcp_ts_sequence'
describe Nmap::XML::TcpTsSequence do
subject { @xml.hosts.first.tcp_ts_sequence }
describe "#description" do
it "should parse the description" do
expect(subject.description).to eq("1000HZ").or(eq('other'))
end
... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | spec/xml/cpe/url_spec.rb | Ruby | mit | 296 | main | 2,517 | require 'spec_helper'
describe Nmap::XML::CPE::URL do
describe "parse" do
context "when the URL does not start with 'cpe:'" do
it "should raise an ArgumentError" do
expect {
described_class.parse('foo:')
}.to raise_error(ArgumentError)
end
end
context "when blank fi... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | lib/nmap/xml.rb | Ruby | mit | 296 | main | 9,320 | # frozen_string_literal: true
require_relative 'xml/scanner'
require_relative 'xml/scan_task'
require_relative 'xml/scan'
require_relative 'xml/host'
require_relative 'xml/run_stat'
require_relative 'xml/prescript'
require_relative 'xml/postscript'
require 'nokogiri'
module Nmap
#
# Represents an Nmap XML file.
... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | lib/nmap/command.rb | Ruby | mit | 296 | main | 26,391 | # frozen_string_literal: true
require 'command_mapper/command'
module Nmap
#
# ## Nmap options:
#
# ### Target Specifications:
#
# * `-iL path/to/file` - `nmap.target_file = "path/to/file"`
# * `-iR 10` - `nmap.random_targets = 10`
# * `--exclude host1 --exclude host2` - `nmap.exclude = ["host1", "hos... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | lib/nmap/xml/scripts.rb | Ruby | mit | 296 | main | 662 | # frozen_string_literal: true
require_relative 'script'
module Nmap
class XML
#
# Mixin that adds methods for parsing `<script>` XML elements.
#
# @since 1.0.0
#
module Scripts
#
# The output from the NSE script's output and structured data.
#
# @return [Hash{String =... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | lib/nmap/xml/host.rb | Ruby | mit | 296 | main | 12,704 | # frozen_string_literal: true
require_relative 'status'
require_relative 'address'
require_relative 'hostname'
require_relative 'os'
require_relative 'port'
require_relative 'ip_id_sequence'
require_relative 'tcp_sequence'
require_relative 'tcp_ts_sequence'
require_relative 'uptime'
require_relative 'traceroute'
requi... |
github | postmodern/ruby-nmap | https://github.com/postmodern/ruby-nmap | lib/nmap/xml/traceroute.rb | Ruby | mit | 296 | main | 1,518 | # frozen_string_literal: true
require_relative 'hop'
module Nmap
class XML
#
# Wraps the `trace` XML element.
#
# @since 1.0.0
#
class Traceroute
include Enumerable
#
# Creates a new traceroute.
#
# @param [Nokogiri::XML::Element] node
# The `trace` XM... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.