openlayer 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/openlayer/integrations/google_conversational_search_tracer.rb +80 -13
- data/lib/openlayer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 697bde0fdcf61182dd6235f06ab2ab9439b245251284f66100a53c44a6bfc146
|
|
4
|
+
data.tar.gz: ea5d247e85a34a14143e82e2aa49e39e44c322d7329cbba01967afb15fb7fc5e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a22c1acd44798f116733781f5648b8cf74697811c09a8ed76ac73a217b803467dd3213a7efe19a1b57c13b3ff93dddd7ca0b4eb5496ea05228f559a29c830dc5
|
|
7
|
+
data.tar.gz: c2b731b11958e0adc38bd37b30045494a832225daf1d8c79a310fb78b8cb72e49a7765d45700c3fcf01e982a5a830faacc7bf8127b0e84806d4a79dccbfc4f8f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.14.1 (2026-07-06)
|
|
4
|
+
|
|
5
|
+
Full Changelog: [v0.14.0...v0.14.1](https://github.com/openlayer-ai/openlayer-ruby/compare/v0.14.0...v0.14.1)
|
|
6
|
+
|
|
3
7
|
## 0.14.0 (2026-07-06)
|
|
4
8
|
|
|
5
9
|
Full Changelog: [v0.13.1...v0.14.0](https://github.com/openlayer-ai/openlayer-ruby/compare/v0.13.1...v0.14.0)
|
data/README.md
CHANGED
|
@@ -345,6 +345,9 @@ module Openlayer
|
|
|
345
345
|
|
|
346
346
|
# Extract references from answer
|
|
347
347
|
#
|
|
348
|
+
# Each reference's `content` is a oneof: exactly one of chunk_info,
|
|
349
|
+
# structured_document_info, or unstructured_document_info is present.
|
|
350
|
+
#
|
|
348
351
|
# @param answer [Object] Answer object from response
|
|
349
352
|
# @return [Array<Hash>, nil] Array of reference hashes or nil
|
|
350
353
|
def self.extract_references(answer)
|
|
@@ -354,25 +357,85 @@ module Openlayer
|
|
|
354
357
|
return nil if references.nil? || !references.respond_to?(:each_with_index)
|
|
355
358
|
|
|
356
359
|
references.each_with_index.map do |reference, index|
|
|
357
|
-
|
|
358
|
-
next nil if chunk_info.nil?
|
|
359
|
-
|
|
360
|
-
doc_metadata = safe_extract(chunk_info, :document_metadata)
|
|
361
|
-
|
|
362
|
-
{
|
|
363
|
-
reference_id: index.to_s,
|
|
364
|
-
content: safe_extract(chunk_info, :content),
|
|
365
|
-
relevance_score: safe_extract(chunk_info, :relevance_score)&.to_f,
|
|
366
|
-
document_id: doc_metadata ? safe_extract(doc_metadata, :document) : nil,
|
|
367
|
-
uri: doc_metadata ? safe_extract(doc_metadata, :uri) : nil,
|
|
368
|
-
title: doc_metadata ? safe_extract(doc_metadata, :title) : nil
|
|
369
|
-
}.compact
|
|
360
|
+
extract_reference(reference, index)
|
|
370
361
|
end.compact
|
|
371
362
|
rescue StandardError => e
|
|
372
363
|
warn_if_debug("[Openlayer] Failed to extract references: #{e.message}")
|
|
373
364
|
nil
|
|
374
365
|
end
|
|
375
366
|
|
|
367
|
+
# Extract a single reference hash from whichever `content` oneof
|
|
368
|
+
# variant is present on it
|
|
369
|
+
#
|
|
370
|
+
# @param reference [Object] Reference object
|
|
371
|
+
# @param index [Integer] Reference's index in the references array
|
|
372
|
+
# @return [Hash, nil] Reference hash, or nil if no known variant is set
|
|
373
|
+
def self.extract_reference(reference, index)
|
|
374
|
+
if (chunk_info = safe_extract(reference, :chunk_info))
|
|
375
|
+
extract_chunk_info_reference(chunk_info, index)
|
|
376
|
+
elsif (structured_document_info = safe_extract(reference, :structured_document_info))
|
|
377
|
+
extract_structured_document_info_reference(structured_document_info, index)
|
|
378
|
+
elsif (unstructured_document_info = safe_extract(reference, :unstructured_document_info))
|
|
379
|
+
extract_unstructured_document_info_reference(unstructured_document_info, index)
|
|
380
|
+
end
|
|
381
|
+
rescue StandardError => e
|
|
382
|
+
warn_if_debug("[Openlayer] Failed to extract reference: #{e.message}")
|
|
383
|
+
nil
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Build a reference hash from a ChunkInfo variant
|
|
387
|
+
#
|
|
388
|
+
# @param chunk_info [Object] ChunkInfo object
|
|
389
|
+
# @param index [Integer] Reference's index in the references array
|
|
390
|
+
# @return [Hash] Reference hash
|
|
391
|
+
def self.extract_chunk_info_reference(chunk_info, index)
|
|
392
|
+
doc_metadata = safe_extract(chunk_info, :document_metadata)
|
|
393
|
+
|
|
394
|
+
{
|
|
395
|
+
reference_id: index.to_s,
|
|
396
|
+
content: safe_extract(chunk_info, :content),
|
|
397
|
+
relevance_score: safe_extract(chunk_info, :relevance_score)&.to_f,
|
|
398
|
+
document_id: doc_metadata ? safe_extract(doc_metadata, :document) : nil,
|
|
399
|
+
uri: doc_metadata ? safe_extract(doc_metadata, :uri) : nil,
|
|
400
|
+
title: doc_metadata ? safe_extract(doc_metadata, :title) : nil
|
|
401
|
+
}.compact
|
|
402
|
+
end
|
|
403
|
+
|
|
404
|
+
# Build a reference hash from a StructuredDocumentInfo variant
|
|
405
|
+
#
|
|
406
|
+
# @param structured_document_info [Object] StructuredDocumentInfo object
|
|
407
|
+
# @param index [Integer] Reference's index in the references array
|
|
408
|
+
# @return [Hash] Reference hash
|
|
409
|
+
def self.extract_structured_document_info_reference(structured_document_info, index)
|
|
410
|
+
{
|
|
411
|
+
reference_id: index.to_s,
|
|
412
|
+
document_id: safe_extract(structured_document_info, :document),
|
|
413
|
+
uri: safe_extract(structured_document_info, :uri),
|
|
414
|
+
title: safe_extract(structured_document_info, :title),
|
|
415
|
+
struct_data: safe_extract(structured_document_info, :struct_data)
|
|
416
|
+
}.compact
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
# Build a reference hash from an UnstructuredDocumentInfo variant
|
|
420
|
+
#
|
|
421
|
+
# @param unstructured_document_info [Object] UnstructuredDocumentInfo object
|
|
422
|
+
# @param index [Integer] Reference's index in the references array
|
|
423
|
+
# @return [Hash] Reference hash
|
|
424
|
+
def self.extract_unstructured_document_info_reference(unstructured_document_info, index)
|
|
425
|
+
chunk_contents = safe_extract(unstructured_document_info, :chunk_contents)
|
|
426
|
+
content = if chunk_contents.respond_to?(:map)
|
|
427
|
+
chunk_contents.map { |chunk| safe_extract(chunk, :content) }.compact.join("\n")
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
{
|
|
431
|
+
reference_id: index.to_s,
|
|
432
|
+
content: (content unless content.nil? || content.empty?),
|
|
433
|
+
document_id: safe_extract(unstructured_document_info, :document),
|
|
434
|
+
uri: safe_extract(unstructured_document_info, :uri),
|
|
435
|
+
title: safe_extract(unstructured_document_info, :title)
|
|
436
|
+
}.compact
|
|
437
|
+
end
|
|
438
|
+
|
|
376
439
|
# Extract related questions from answer
|
|
377
440
|
#
|
|
378
441
|
# @param answer [Object] Answer object from response
|
|
@@ -717,6 +780,10 @@ module Openlayer
|
|
|
717
780
|
:extract_citations,
|
|
718
781
|
:extract_citation_sources,
|
|
719
782
|
:extract_references,
|
|
783
|
+
:extract_reference,
|
|
784
|
+
:extract_chunk_info_reference,
|
|
785
|
+
:extract_structured_document_info_reference,
|
|
786
|
+
:extract_unstructured_document_info_reference,
|
|
720
787
|
:extract_related_questions,
|
|
721
788
|
:extract_steps,
|
|
722
789
|
:extract_step_data,
|
data/lib/openlayer/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openlayer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.14.
|
|
4
|
+
version: 0.14.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Openlayer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-07-
|
|
11
|
+
date: 2026-07-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cgi
|