exa-ai 0.4.0 → 0.5.0
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/exe/exa-ai +6 -6
- data/exe/exa-ai-answer +9 -8
- data/exe/exa-ai-context +6 -5
- data/exe/exa-ai-enrichment-cancel +1 -0
- data/exe/exa-ai-enrichment-create +1 -0
- data/exe/exa-ai-enrichment-delete +1 -0
- data/exe/exa-ai-enrichment-get +1 -0
- data/exe/exa-ai-enrichment-list +1 -0
- data/exe/exa-ai-enrichment-update +1 -0
- data/exe/exa-ai-find-similar +1 -0
- data/exe/exa-ai-get-contents +9 -8
- data/exe/exa-ai-research-get +7 -7
- data/exe/exa-ai-research-list +5 -5
- data/exe/exa-ai-research-start +8 -7
- data/exe/exa-ai-search +20 -13
- data/exe/exa-ai-webset-cancel +1 -0
- data/exe/exa-ai-webset-create +1 -0
- data/exe/exa-ai-webset-delete +1 -0
- data/exe/exa-ai-webset-get +1 -0
- data/exe/exa-ai-webset-item-get +1 -0
- data/exe/exa-ai-webset-item-list +1 -0
- data/exe/exa-ai-webset-list +1 -0
- data/exe/exa-ai-webset-search-cancel +2 -1
- data/exe/exa-ai-webset-search-create +2 -1
- data/exe/exa-ai-webset-search-get +2 -1
- data/exe/exa-ai-webset-update +1 -0
- data/lib/exa/middleware/raise_error.rb +5 -0
- data/lib/exa/services/search.rb +21 -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: 9f9d0670c6b642073a66e32d8ecdd46702931e4b17f66bd6970b976a51ec5c56
|
|
4
|
+
data.tar.gz: 2f9126068c6e0672cf7ac67b2d18e188396dbd3785285c4683b2deb99b97d14d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70e7be7fd10d14c69dd1b3125e453c9aa5a7233fb5f618233b8e3af0b42c7546a02b7cb34b9a20f9bb25b0f235f5b6fcbecefbaa5c33393720a47200b1443d93
|
|
7
|
+
data.tar.gz: 3ef41b82e7126b4f875a3acddeaf046293a75e2d6cae3a03ea1c3ab46dc5ba9d8ade004add9e5f588876b7cdc4bf7a6c4f27d6be08a42b31e29a7ec3a987dd4f
|
data/exe/exa-ai
CHANGED
|
@@ -44,7 +44,7 @@ module ExaCLI
|
|
|
44
44
|
print_help
|
|
45
45
|
exit 0
|
|
46
46
|
when "--api-key"
|
|
47
|
-
puts "Use --api-key flag with specific commands"
|
|
47
|
+
$stderr.puts "Error: Use --api-key flag with specific commands"
|
|
48
48
|
exit 1
|
|
49
49
|
when "search"
|
|
50
50
|
exec File.expand_path("../exa-ai-search", __FILE__), *ARGV[1..]
|
|
@@ -175,15 +175,15 @@ module ExaCLI
|
|
|
175
175
|
def self.print_error_for_command(cmd)
|
|
176
176
|
return print_help if cmd.nil?
|
|
177
177
|
|
|
178
|
-
puts "Error: Unknown command '#{cmd}'"
|
|
179
|
-
puts ""
|
|
178
|
+
$stderr.puts "Error: Unknown command '#{cmd}'"
|
|
179
|
+
$stderr.puts ""
|
|
180
180
|
|
|
181
181
|
# Try to suggest similar commands
|
|
182
182
|
suggestion = suggest_command(cmd)
|
|
183
|
-
puts "Did you mean: #{suggestion}?" if suggestion
|
|
183
|
+
$stderr.puts "Did you mean: #{suggestion}?" if suggestion
|
|
184
184
|
|
|
185
|
-
puts ""
|
|
186
|
-
puts "Run 'exa-ai --help' for usage information."
|
|
185
|
+
$stderr.puts ""
|
|
186
|
+
$stderr.puts "Run 'exa-ai --help' for usage information."
|
|
187
187
|
end
|
|
188
188
|
|
|
189
189
|
def self.suggest_command(input)
|
data/exe/exa-ai-answer
CHANGED
|
@@ -38,7 +38,7 @@ def parse_args(argv)
|
|
|
38
38
|
i += 2
|
|
39
39
|
when "--help", "-h"
|
|
40
40
|
puts <<~HELP
|
|
41
|
-
Usage: exa-
|
|
41
|
+
Usage: exa-ai answer QUERY [OPTIONS]
|
|
42
42
|
|
|
43
43
|
Generate an answer to a question using Exa AI
|
|
44
44
|
|
|
@@ -55,12 +55,12 @@ def parse_args(argv)
|
|
|
55
55
|
--help, -h Show this help message
|
|
56
56
|
|
|
57
57
|
Examples:
|
|
58
|
-
exa-
|
|
59
|
-
exa-
|
|
60
|
-
exa-
|
|
61
|
-
exa-
|
|
62
|
-
exa-
|
|
63
|
-
exa-
|
|
58
|
+
exa-ai answer "What is the capital of France?"
|
|
59
|
+
exa-ai answer "Latest AI breakthroughs" --stream
|
|
60
|
+
exa-ai answer "Latest AI breakthroughs" --text
|
|
61
|
+
exa-ai answer "Ruby best practices" --output-format pretty
|
|
62
|
+
exa-ai answer "What is the capital of France?" --output-schema '{"type":"object","properties":{"city":{"type":"string"},"state":{"type":"string"}}}'
|
|
63
|
+
exa-ai answer "What is Paris?" --system-prompt "Respond in the voice of a pirate"
|
|
64
64
|
HELP
|
|
65
65
|
exit 0
|
|
66
66
|
else
|
|
@@ -80,7 +80,7 @@ begin
|
|
|
80
80
|
# Validate query
|
|
81
81
|
if args[:query].nil? || args[:query].empty?
|
|
82
82
|
$stderr.puts "Error: Query is required"
|
|
83
|
-
$stderr.puts "Run 'exa-
|
|
83
|
+
$stderr.puts "Run 'exa-ai answer --help' for usage information"
|
|
84
84
|
exit 1
|
|
85
85
|
end
|
|
86
86
|
|
|
@@ -125,6 +125,7 @@ begin
|
|
|
125
125
|
result = client.answer(args[:query], **answer_params)
|
|
126
126
|
output = Exa::CLI::Formatters::AnswerFormatter.format(result, output_format)
|
|
127
127
|
puts output
|
|
128
|
+
$stdout.flush
|
|
128
129
|
end
|
|
129
130
|
|
|
130
131
|
rescue Exa::ConfigurationError => e
|
data/exe/exa-ai-context
CHANGED
|
@@ -43,7 +43,7 @@ end
|
|
|
43
43
|
def print_help
|
|
44
44
|
puts "Exa Context - Get code context from repositories"
|
|
45
45
|
puts ""
|
|
46
|
-
puts "Usage: exa-
|
|
46
|
+
puts "Usage: exa-ai context <query> [options]"
|
|
47
47
|
puts ""
|
|
48
48
|
puts "Arguments:"
|
|
49
49
|
puts " query Search query for code context (required)"
|
|
@@ -55,9 +55,9 @@ def print_help
|
|
|
55
55
|
puts " --help, -h Show this help message"
|
|
56
56
|
puts ""
|
|
57
57
|
puts "Examples:"
|
|
58
|
-
puts " exa-
|
|
59
|
-
puts " exa-
|
|
60
|
-
puts " exa-
|
|
58
|
+
puts " exa-ai context 'React hooks'"
|
|
59
|
+
puts " exa-ai context 'authentication with JWT in Ruby' --tokens-num 5000"
|
|
60
|
+
puts " exa-ai context 'React hooks' --output-format text"
|
|
61
61
|
end
|
|
62
62
|
|
|
63
63
|
begin
|
|
@@ -68,7 +68,7 @@ begin
|
|
|
68
68
|
unless options[:query]
|
|
69
69
|
puts "Error: Query argument required"
|
|
70
70
|
puts ""
|
|
71
|
-
puts "Run 'exa-
|
|
71
|
+
puts "Run 'exa-ai context --help' for usage information."
|
|
72
72
|
exit 1
|
|
73
73
|
end
|
|
74
74
|
|
|
@@ -91,6 +91,7 @@ begin
|
|
|
91
91
|
# Format and output
|
|
92
92
|
output = Exa::CLI::Formatters::ContextFormatter.format(result, output_format)
|
|
93
93
|
puts output
|
|
94
|
+
$stdout.flush
|
|
94
95
|
rescue Exa::Error => e
|
|
95
96
|
puts "Error: #{e.message}"
|
|
96
97
|
exit 1
|
|
@@ -210,6 +210,7 @@ begin
|
|
|
210
210
|
# Format and output result
|
|
211
211
|
output = Exa::CLI::Formatters::EnrichmentFormatter.format(enrichment, output_format)
|
|
212
212
|
puts output
|
|
213
|
+
$stdout.flush
|
|
213
214
|
|
|
214
215
|
rescue Exa::ConfigurationError => e
|
|
215
216
|
$stderr.puts "Configuration error: #{e.message}"
|
data/exe/exa-ai-enrichment-get
CHANGED
data/exe/exa-ai-enrichment-list
CHANGED
data/exe/exa-ai-find-similar
CHANGED
data/exe/exa-ai-get-contents
CHANGED
|
@@ -164,7 +164,7 @@ end
|
|
|
164
164
|
|
|
165
165
|
def print_help
|
|
166
166
|
puts <<~HELP
|
|
167
|
-
Usage: exa-
|
|
167
|
+
Usage: exa-ai get-contents <urls> [options]
|
|
168
168
|
|
|
169
169
|
Retrieve full page contents from URLs
|
|
170
170
|
|
|
@@ -203,12 +203,12 @@ def print_help
|
|
|
203
203
|
--help, -h Show this help message
|
|
204
204
|
|
|
205
205
|
Examples:
|
|
206
|
-
exa-
|
|
207
|
-
exa-
|
|
208
|
-
exa-
|
|
209
|
-
exa-
|
|
210
|
-
exa-
|
|
211
|
-
exa-
|
|
206
|
+
exa-ai get-contents 'https://example.com'
|
|
207
|
+
exa-ai get-contents 'https://example.com' --text
|
|
208
|
+
exa-ai get-contents 'https://example.com' --text --text-max-characters 3000 --include-html-tags
|
|
209
|
+
exa-ai get-contents 'url1,url2' --summary --summary-query "Be terse"
|
|
210
|
+
exa-ai get-contents 'https://example.com' --subpages 1 --subpage-target about
|
|
211
|
+
exa-ai get-contents 'https://example.com' --links 5 --image-links 10
|
|
212
212
|
HELP
|
|
213
213
|
end
|
|
214
214
|
|
|
@@ -220,7 +220,7 @@ begin
|
|
|
220
220
|
if options[:ids].empty?
|
|
221
221
|
$stderr.puts "Error: URLs argument required"
|
|
222
222
|
$stderr.puts ""
|
|
223
|
-
$stderr.puts "Run 'exa-
|
|
223
|
+
$stderr.puts "Run 'exa-ai get-contents --help' for usage information."
|
|
224
224
|
exit 1
|
|
225
225
|
end
|
|
226
226
|
|
|
@@ -243,6 +243,7 @@ begin
|
|
|
243
243
|
# Format and output
|
|
244
244
|
output = Exa::CLI::Formatters::ContentsFormatter.format(result, output_format)
|
|
245
245
|
puts output
|
|
246
|
+
$stdout.flush
|
|
246
247
|
rescue Exa::ConfigurationError => e
|
|
247
248
|
$stderr.puts "Configuration error: #{e.message}"
|
|
248
249
|
exit 1
|
data/exe/exa-ai-research-get
CHANGED
|
@@ -24,7 +24,7 @@ while args.any?
|
|
|
24
24
|
output_format = args.shift
|
|
25
25
|
when "--help", "-h"
|
|
26
26
|
puts <<~HELP
|
|
27
|
-
Usage: exa-
|
|
27
|
+
Usage: exa-ai research-get <research_id> [options]
|
|
28
28
|
|
|
29
29
|
Get the status and results of a research task.
|
|
30
30
|
|
|
@@ -39,10 +39,10 @@ while args.any?
|
|
|
39
39
|
--help, -h Show this help message
|
|
40
40
|
|
|
41
41
|
Examples:
|
|
42
|
-
exa-
|
|
43
|
-
exa-
|
|
44
|
-
exa-
|
|
45
|
-
exa-
|
|
42
|
+
exa-ai research-get research_123
|
|
43
|
+
exa-ai research-get research_123 --events
|
|
44
|
+
exa-ai research-get research_123 --stream
|
|
45
|
+
exa-ai research-get research_123 --output-format pretty
|
|
46
46
|
HELP
|
|
47
47
|
exit 0
|
|
48
48
|
else
|
|
@@ -59,8 +59,8 @@ end
|
|
|
59
59
|
# Validate required arguments
|
|
60
60
|
if research_id.nil?
|
|
61
61
|
warn "Error: Research ID argument required"
|
|
62
|
-
warn "Usage: exa-
|
|
63
|
-
warn "Try 'exa-
|
|
62
|
+
warn "Usage: exa-ai research-get <research_id> [options]"
|
|
63
|
+
warn "Try 'exa-ai research-get --help' for more information"
|
|
64
64
|
exit 1
|
|
65
65
|
end
|
|
66
66
|
|
data/exe/exa-ai-research-list
CHANGED
|
@@ -23,7 +23,7 @@ while args.any?
|
|
|
23
23
|
output_format = args.shift
|
|
24
24
|
when "--help", "-h"
|
|
25
25
|
puts <<~HELP
|
|
26
|
-
Usage: exa-
|
|
26
|
+
Usage: exa-ai research-list [options]
|
|
27
27
|
|
|
28
28
|
List research tasks with cursor-based pagination.
|
|
29
29
|
|
|
@@ -35,10 +35,10 @@ while args.any?
|
|
|
35
35
|
--help, -h Show this help message
|
|
36
36
|
|
|
37
37
|
Examples:
|
|
38
|
-
exa-
|
|
39
|
-
exa-
|
|
40
|
-
exa-
|
|
41
|
-
exa-
|
|
38
|
+
exa-ai research-list
|
|
39
|
+
exa-ai research-list --limit 20
|
|
40
|
+
exa-ai research-list --cursor next_page_cursor
|
|
41
|
+
exa-ai research-list --output-format pretty
|
|
42
42
|
HELP
|
|
43
43
|
exit 0
|
|
44
44
|
else
|
data/exe/exa-ai-research-start
CHANGED
|
@@ -39,7 +39,7 @@ def parse_args(argv)
|
|
|
39
39
|
i += 2
|
|
40
40
|
when "--help", "-h"
|
|
41
41
|
puts <<~HELP
|
|
42
|
-
Usage: exa-
|
|
42
|
+
Usage: exa-ai research-start --instructions "TEXT" [OPTIONS]
|
|
43
43
|
|
|
44
44
|
Start a research task using Exa AI
|
|
45
45
|
|
|
@@ -54,10 +54,10 @@ def parse_args(argv)
|
|
|
54
54
|
--help, -h Show this help message
|
|
55
55
|
|
|
56
56
|
Examples:
|
|
57
|
-
exa-
|
|
58
|
-
exa-
|
|
59
|
-
exa-
|
|
60
|
-
exa-
|
|
57
|
+
exa-ai research-start --instructions "Find Ruby performance tips"
|
|
58
|
+
exa-ai research-start --instructions "Analyze AI trends" --wait --events
|
|
59
|
+
exa-ai research-start --instructions "Summarize papers" --model exa-research-pro --wait
|
|
60
|
+
exa-ai research-start --instructions "Find stats" --output-schema '{"type":"object"}'
|
|
61
61
|
HELP
|
|
62
62
|
exit 0
|
|
63
63
|
else
|
|
@@ -75,7 +75,7 @@ begin
|
|
|
75
75
|
# Validate instructions
|
|
76
76
|
if args[:instructions].nil? || args[:instructions].empty?
|
|
77
77
|
$stderr.puts "Error: --instructions flag is required"
|
|
78
|
-
$stderr.puts "Run 'exa-
|
|
78
|
+
$stderr.puts "Run 'exa-ai research-start --help' for usage information"
|
|
79
79
|
exit 1
|
|
80
80
|
end
|
|
81
81
|
|
|
@@ -133,6 +133,7 @@ begin
|
|
|
133
133
|
# Format and output final result
|
|
134
134
|
output = Exa::CLI::Formatters::ResearchFormatter.format_task(final_task, output_format, show_events: args[:events])
|
|
135
135
|
puts output
|
|
136
|
+
$stdout.flush
|
|
136
137
|
|
|
137
138
|
# Exit with error code if task failed
|
|
138
139
|
exit 1 if final_task.failed?
|
|
@@ -140,7 +141,7 @@ begin
|
|
|
140
141
|
rescue Exa::CLI::Polling::TimeoutError => e
|
|
141
142
|
$stderr.puts "\nError: Task did not complete within timeout period (5 minutes)"
|
|
142
143
|
$stderr.puts "Task ID: #{task.research_id}"
|
|
143
|
-
$stderr.puts "You can check the status later with: exa-
|
|
144
|
+
$stderr.puts "You can check the status later with: exa-ai research-get #{task.research_id}"
|
|
144
145
|
exit 1
|
|
145
146
|
end
|
|
146
147
|
else
|
data/exe/exa-ai-search
CHANGED
|
@@ -20,7 +20,13 @@ def parse_args(argv)
|
|
|
20
20
|
args[:num_results] = argv[i + 1].to_i
|
|
21
21
|
i += 2
|
|
22
22
|
when "--type"
|
|
23
|
-
|
|
23
|
+
search_type = argv[i + 1]
|
|
24
|
+
valid_types = ["fast", "deep", "keyword", "auto"]
|
|
25
|
+
unless valid_types.include?(search_type)
|
|
26
|
+
$stderr.puts "Error: Search type must be one of: #{valid_types.join(', ')}"
|
|
27
|
+
exit 1
|
|
28
|
+
end
|
|
29
|
+
args[:type] = search_type
|
|
24
30
|
i += 2
|
|
25
31
|
when "--category"
|
|
26
32
|
category = argv[i + 1]
|
|
@@ -116,7 +122,7 @@ def parse_args(argv)
|
|
|
116
122
|
i += 2
|
|
117
123
|
when "--help", "-h"
|
|
118
124
|
puts <<~HELP
|
|
119
|
-
Usage: exa-
|
|
125
|
+
Usage: exa-ai search QUERY [OPTIONS]
|
|
120
126
|
|
|
121
127
|
Search the web using Exa AI
|
|
122
128
|
|
|
@@ -125,7 +131,7 @@ def parse_args(argv)
|
|
|
125
131
|
|
|
126
132
|
Options:
|
|
127
133
|
--num-results N Number of results to return (default: 10)
|
|
128
|
-
--type TYPE Search type:
|
|
134
|
+
--type TYPE Search type: fast, deep, keyword, or auto (default: fast)
|
|
129
135
|
--category CAT Focus on specific data category
|
|
130
136
|
Options: "company", "research paper", "news", "pdf",
|
|
131
137
|
"github", "tweet", "personal site", "linkedin profile",
|
|
@@ -160,15 +166,15 @@ def parse_args(argv)
|
|
|
160
166
|
--help, -h Show this help message
|
|
161
167
|
|
|
162
168
|
Examples:
|
|
163
|
-
exa-
|
|
164
|
-
exa-
|
|
165
|
-
exa-
|
|
166
|
-
exa-
|
|
167
|
-
exa-
|
|
168
|
-
exa-
|
|
169
|
-
exa-
|
|
170
|
-
exa-
|
|
171
|
-
exa-
|
|
169
|
+
exa-ai search "ruby programming"
|
|
170
|
+
exa-ai search "machine learning" --num-results 5 --type deep
|
|
171
|
+
exa-ai search "Latest LLM research" --category "research paper"
|
|
172
|
+
exa-ai search "AI startups" --category company
|
|
173
|
+
exa-ai search "Anthropic" --linkedin company
|
|
174
|
+
exa-ai search "Dario Amodei" --linkedin person
|
|
175
|
+
exa-ai search "AI" --linkedin all
|
|
176
|
+
exa-ai search "AI research" --include-domains arxiv.org,scholar.google.com
|
|
177
|
+
exa-ai search "tutorials" --output-format pretty
|
|
172
178
|
HELP
|
|
173
179
|
exit 0
|
|
174
180
|
else
|
|
@@ -237,7 +243,7 @@ begin
|
|
|
237
243
|
# Validate query
|
|
238
244
|
if args[:query].nil? || args[:query].empty?
|
|
239
245
|
$stderr.puts "Error: Query is required"
|
|
240
|
-
$stderr.puts "Run 'exa-
|
|
246
|
+
$stderr.puts "Run 'exa-ai search --help' for usage information"
|
|
241
247
|
exit 1
|
|
242
248
|
end
|
|
243
249
|
|
|
@@ -281,6 +287,7 @@ begin
|
|
|
281
287
|
# Format and output result
|
|
282
288
|
output = Exa::CLI::Formatters::SearchFormatter.format(result, output_format)
|
|
283
289
|
puts output
|
|
290
|
+
$stdout.flush
|
|
284
291
|
|
|
285
292
|
rescue Exa::ConfigurationError => e
|
|
286
293
|
$stderr.puts "Configuration error: #{e.message}"
|
data/exe/exa-ai-webset-cancel
CHANGED
data/exe/exa-ai-webset-create
CHANGED
data/exe/exa-ai-webset-delete
CHANGED
data/exe/exa-ai-webset-get
CHANGED
data/exe/exa-ai-webset-item-get
CHANGED
data/exe/exa-ai-webset-item-list
CHANGED
data/exe/exa-ai-webset-list
CHANGED
|
@@ -77,8 +77,9 @@ begin
|
|
|
77
77
|
search = client.cancel_webset_search(webset_id: webset_id, id: search_id)
|
|
78
78
|
|
|
79
79
|
# Format and output
|
|
80
|
-
output = Exa::CLI::Formatters::
|
|
80
|
+
output = Exa::CLI::Formatters::SearchFormatter.format(search, output_format)
|
|
81
81
|
puts output
|
|
82
|
+
$stdout.flush
|
|
82
83
|
|
|
83
84
|
rescue Exa::NotFound => e
|
|
84
85
|
$stderr.puts "Search not found: #{e.message}"
|
|
@@ -203,8 +203,9 @@ begin
|
|
|
203
203
|
search = client.create_webset_search(webset_id: args[:webset_id], **search_params)
|
|
204
204
|
|
|
205
205
|
# Format and output result
|
|
206
|
-
output = Exa::CLI::Formatters::
|
|
206
|
+
output = Exa::CLI::Formatters::SearchFormatter.format(search, output_format)
|
|
207
207
|
puts output
|
|
208
|
+
$stdout.flush
|
|
208
209
|
|
|
209
210
|
rescue Exa::ConfigurationError => e
|
|
210
211
|
$stderr.puts "Configuration error: #{e.message}"
|
|
@@ -78,8 +78,9 @@ begin
|
|
|
78
78
|
search = client.get_webset_search(webset_id: webset_id, id: search_id)
|
|
79
79
|
|
|
80
80
|
# Format and output
|
|
81
|
-
output = Exa::CLI::Formatters::
|
|
81
|
+
output = Exa::CLI::Formatters::SearchFormatter.format(search, output_format)
|
|
82
82
|
puts output
|
|
83
|
+
$stdout.flush
|
|
83
84
|
|
|
84
85
|
rescue Exa::NotFound => e
|
|
85
86
|
$stderr.puts "Search not found: #{e.message}"
|
data/exe/exa-ai-webset-update
CHANGED
|
@@ -41,6 +41,11 @@ module Exa
|
|
|
41
41
|
body = env[:body]
|
|
42
42
|
|
|
43
43
|
if body.is_a?(Hash)
|
|
44
|
+
# Prioritize "message" field for detailed error descriptions
|
|
45
|
+
return body["message"] if body["message"]
|
|
46
|
+
return body[:message] if body[:message]
|
|
47
|
+
|
|
48
|
+
# Fall back to "error" field
|
|
44
49
|
return body["error"] if body["error"]
|
|
45
50
|
return body[:error] if body[:error]
|
|
46
51
|
end
|
data/lib/exa/services/search.rb
CHANGED
|
@@ -5,9 +5,13 @@ require_relative "parameter_converter"
|
|
|
5
5
|
module Exa
|
|
6
6
|
module Services
|
|
7
7
|
class Search
|
|
8
|
+
VALID_SEARCH_TYPES = ["fast", "deep", "keyword", "auto"].freeze
|
|
9
|
+
DEFAULT_SEARCH_TYPE = "fast"
|
|
10
|
+
|
|
8
11
|
def initialize(connection, **params)
|
|
9
12
|
@connection = connection
|
|
10
|
-
@params = params
|
|
13
|
+
@params = normalize_params(params)
|
|
14
|
+
validate_search_type!
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
def call
|
|
@@ -23,6 +27,22 @@ module Exa
|
|
|
23
27
|
cost_dollars: body["costDollars"]
|
|
24
28
|
)
|
|
25
29
|
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def normalize_params(params)
|
|
34
|
+
normalized = params.dup
|
|
35
|
+
# Set default search type if not provided
|
|
36
|
+
normalized[:type] = DEFAULT_SEARCH_TYPE unless normalized.key?(:type)
|
|
37
|
+
normalized
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def validate_search_type!
|
|
41
|
+
search_type = @params[:type]
|
|
42
|
+
return if VALID_SEARCH_TYPES.include?(search_type)
|
|
43
|
+
|
|
44
|
+
raise ArgumentError, "Invalid search type: '#{search_type}'. Must be one of: #{VALID_SEARCH_TYPES.join(', ')}"
|
|
45
|
+
end
|
|
26
46
|
end
|
|
27
47
|
end
|
|
28
48
|
end
|
data/lib/exa/version.rb
CHANGED