exa-ai 0.11.0 → 0.11.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/lib/exa/services/get_contents.rb +20 -1
- data/lib/exa/services/parameter_converter.rb +33 -1
- data/lib/exa/services/search.rb +18 -1
- data/lib/exa/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e5fb7cd2fe000621f282f4eba7b178bc628793fc8232a47664f9a62d6a9d63ed
|
|
4
|
+
data.tar.gz: c8f6d9cb0272743280d73383629e1db1b68febd787a04f68dd402c1eb7927e7a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5c59a5d154df999cfd6e1212d23cfa46507caaa37a026439107ee63e9866e010367d75da4199b7b9873ccf37b8af83176d14420f21ee68499dc00e43ce001425
|
|
7
|
+
data.tar.gz: fc82c1690affcec1d61bc5df5930819c0c375b33fe0ac3e40d956c1ce5ad6b36cc3b908590b9bbcb14759a3521cad2cc4ef5de494b32705a0a9d2238ddbb0112
|
|
@@ -12,14 +12,33 @@ module Exa
|
|
|
12
12
|
response = @connection.post("/contents", @params)
|
|
13
13
|
body = response.body
|
|
14
14
|
|
|
15
|
+
results = body["results"]
|
|
16
|
+
results = parse_json_summaries(results) if summary_schema?
|
|
17
|
+
|
|
15
18
|
Resources::ContentsResult.new(
|
|
16
|
-
results:
|
|
19
|
+
results: results,
|
|
17
20
|
request_id: body["requestId"],
|
|
18
21
|
context: body["context"],
|
|
19
22
|
statuses: body["statuses"],
|
|
20
23
|
cost_dollars: body["costDollars"]
|
|
21
24
|
)
|
|
22
25
|
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def summary_schema?
|
|
30
|
+
@params[:summary].is_a?(Hash) && @params[:summary][:schema]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def parse_json_summaries(results)
|
|
34
|
+
results&.map do |r|
|
|
35
|
+
if r["summary"].is_a?(String)
|
|
36
|
+
r.merge("summary" => JSON.parse(r["summary"]))
|
|
37
|
+
else
|
|
38
|
+
r
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
23
42
|
end
|
|
24
43
|
end
|
|
25
44
|
end
|
|
@@ -10,10 +10,11 @@ module Exa
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def convert(params)
|
|
13
|
+
consolidated = consolidate_content_params(params)
|
|
13
14
|
converted = {}
|
|
14
15
|
contents = {}
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
consolidated.each do |key, value|
|
|
17
18
|
if content_key?(key)
|
|
18
19
|
contents[convert_content_key(key)] = convert_content_value(key, value)
|
|
19
20
|
else
|
|
@@ -27,6 +28,37 @@ module Exa
|
|
|
27
28
|
|
|
28
29
|
private
|
|
29
30
|
|
|
31
|
+
CONTENT_SUB_PARAMS = {
|
|
32
|
+
text_max_characters: { parent: :text, key: :max_characters },
|
|
33
|
+
include_html_tags: { parent: :text, key: :include_html_tags },
|
|
34
|
+
text_verbosity: { parent: :text, key: :verbosity },
|
|
35
|
+
summary_query: { parent: :summary, key: :query },
|
|
36
|
+
summary_schema: { parent: :summary, key: :schema },
|
|
37
|
+
context_max_characters: { parent: :context, key: :max_characters },
|
|
38
|
+
highlights_max_characters: { parent: :highlights, key: :max_characters },
|
|
39
|
+
highlights_num_sentences: { parent: :highlights, key: :num_sentences },
|
|
40
|
+
highlights_per_url: { parent: :highlights, key: :highlights_per_url },
|
|
41
|
+
highlights_query: { parent: :highlights, key: :query },
|
|
42
|
+
image_links: { parent: :extras, key: :image_links },
|
|
43
|
+
links: { parent: :extras, key: :links }
|
|
44
|
+
}.freeze
|
|
45
|
+
|
|
46
|
+
def consolidate_content_params(params)
|
|
47
|
+
result = {}
|
|
48
|
+
params.each do |key, value|
|
|
49
|
+
mapping = CONTENT_SUB_PARAMS[key]
|
|
50
|
+
if mapping
|
|
51
|
+
parent = mapping[:parent]
|
|
52
|
+
result[parent] = {} if result[parent] == true || !result.key?(parent)
|
|
53
|
+
result[parent] = {} unless result[parent].is_a?(Hash)
|
|
54
|
+
result[parent][mapping[:key]] = value
|
|
55
|
+
else
|
|
56
|
+
result[key] = value
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
result
|
|
60
|
+
end
|
|
61
|
+
|
|
30
62
|
def convert_key(key)
|
|
31
63
|
case key
|
|
32
64
|
when :start_published_date then :startPublishedDate
|
data/lib/exa/services/search.rb
CHANGED
|
@@ -18,8 +18,11 @@ module Exa
|
|
|
18
18
|
response = @connection.post("/search", ParameterConverter.convert(@params))
|
|
19
19
|
body = response.body
|
|
20
20
|
|
|
21
|
+
results = body["results"]
|
|
22
|
+
results = parse_json_summaries(results) if summary_schema?
|
|
23
|
+
|
|
21
24
|
Resources::SearchResult.new(
|
|
22
|
-
results:
|
|
25
|
+
results: results,
|
|
23
26
|
request_id: body["requestId"],
|
|
24
27
|
resolved_search_type: body["resolvedSearchType"],
|
|
25
28
|
search_type: body["searchType"],
|
|
@@ -44,6 +47,20 @@ module Exa
|
|
|
44
47
|
|
|
45
48
|
raise ArgumentError, "Invalid search type: '#{search_type}'. Must be one of: #{VALID_SEARCH_TYPES.join(', ')}"
|
|
46
49
|
end
|
|
50
|
+
|
|
51
|
+
def summary_schema?
|
|
52
|
+
@params[:summary].is_a?(Hash) && @params[:summary][:schema]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def parse_json_summaries(results)
|
|
56
|
+
results&.map do |r|
|
|
57
|
+
if r["summary"].is_a?(String)
|
|
58
|
+
r.merge("summary" => JSON.parse(r["summary"]))
|
|
59
|
+
else
|
|
60
|
+
r
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
47
64
|
end
|
|
48
65
|
end
|
|
49
66
|
end
|
data/lib/exa/version.rb
CHANGED