Class: RelevantChunks::Processor
- Inherits:
-
Object
- Object
- RelevantChunks::Processor
- Defined in:
- lib/relevant_chunks/processor.rb
Overview
Handles text processing and relevance scoring using Claude/Anthropic
The Processor class manages the chunking and scoring of text using the Anthropic API.
Class Attribute Summary collapse
-
.configuration ⇒ Object
Returns the value of attribute configuration.
Instance Attribute Summary collapse
-
#api_key ⇒ String
readonly
Anthropic API key.
-
#chunker ⇒ Chunker
readonly
Text chunker instance.
-
#max_score ⇒ Integer
readonly
Maximum score in the scoring range.
-
#model ⇒ String
readonly
Claude model to use.
-
#system_prompt ⇒ String
readonly
System prompt for scoring.
-
#temperature ⇒ Float
readonly
Temperature for scoring (0.0-1.0).
Instance Method Summary collapse
-
#initialize(api_key:, max_tokens: 1000, overlap_size: 100, model: "claude-3-5-sonnet-latest", temperature: 0.0, system_prompt: nil, max_score: 100) ⇒ Processor
constructor
Initialize a new Processor instance.
-
#process(text, query) ⇒ Array<Hash>
Process text and score chunks against a query.
Constructor Details
#initialize(api_key:, max_tokens: 1000, overlap_size: 100, model: "claude-3-5-sonnet-latest", temperature: 0.0, system_prompt: nil, max_score: 100) ⇒ Processor
Initialize a new Processor instance
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/relevant_chunks/processor.rb', line 77 def initialize(api_key:, max_tokens: 1000, overlap_size: 100, model: "claude-3-5-sonnet-latest", temperature: 0.0, system_prompt: nil, max_score: 100) @api_key = api_key @chunker = Chunker.new(max_tokens: max_tokens, overlap_size: overlap_size) @model = model @temperature = temperature @max_score = max_score @system_prompt = system_prompt || default_system_prompt @conn = Faraday.new(url: "https://api.anthropic.com") do |f| f.request :json f.response :json f.adapter :net_http f.headers = { "accept" => "application/json", "anthropic-version" => "2023-06-01", "content-type" => "application/json", "x-api-key" => api_key } end end |
Class Attribute Details
.configuration ⇒ Object
Returns the value of attribute configuration.
46 47 48 |
# File 'lib/relevant_chunks/processor.rb', line 46 def configuration @configuration end |
Instance Attribute Details
#api_key ⇒ String (readonly)
Returns Anthropic API key.
50 51 52 |
# File 'lib/relevant_chunks/processor.rb', line 50 def api_key @api_key end |
#chunker ⇒ Chunker (readonly)
Returns Text chunker instance.
53 54 55 |
# File 'lib/relevant_chunks/processor.rb', line 53 def chunker @chunker end |
#max_score ⇒ Integer (readonly)
Returns Maximum score in the scoring range.
65 66 67 |
# File 'lib/relevant_chunks/processor.rb', line 65 def max_score @max_score end |
#model ⇒ String (readonly)
Returns Claude model to use.
56 57 58 |
# File 'lib/relevant_chunks/processor.rb', line 56 def model @model end |
#system_prompt ⇒ String (readonly)
Returns System prompt for scoring.
62 63 64 |
# File 'lib/relevant_chunks/processor.rb', line 62 def system_prompt @system_prompt end |
#temperature ⇒ Float (readonly)
Returns Temperature for scoring (0.0-1.0).
59 60 61 |
# File 'lib/relevant_chunks/processor.rb', line 59 def temperature @temperature end |
Instance Method Details
#process(text, query) ⇒ Array<Hash>
Process text and score chunks against a query
115 116 117 118 |
# File 'lib/relevant_chunks/processor.rb', line 115 def process(text, query) chunks = chunker.chunk_text(text) chunks.map { |chunk| score_chunk(chunk, query) } end |