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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4cc4ccfc59e93013765b9289621cdb0447c4cc5bbc24e1585376ebae4b7b6ff0
4
- data.tar.gz: 45cbb8655d636906d1230651896aeab9375720e655ca4d18c74f12a425ea5bd7
3
+ metadata.gz: 9f9d0670c6b642073a66e32d8ecdd46702931e4b17f66bd6970b976a51ec5c56
4
+ data.tar.gz: 2f9126068c6e0672cf7ac67b2d18e188396dbd3785285c4683b2deb99b97d14d
5
5
  SHA512:
6
- metadata.gz: 4d569c43e3d9071accaeb081c6c8b51bbd0248258aa36331a8874ae17b648686bf22da5d73faee00b0a8d4a6b2b5a62dc47bcec5e4d4d7202d20870dca4ebb4e
7
- data.tar.gz: 41c7f61f7de1dcc31fec84588cc2ed6287ddec597554cc18d7a9afbc0b044a790792a598ddfaef68e12174178a373081c3274e6240f6c91f908db14101fc4887
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-api answer QUERY [OPTIONS]
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-api answer "What is the capital of France?"
59
- exa-api answer "Latest AI breakthroughs" --stream
60
- exa-api answer "Latest AI breakthroughs" --text
61
- exa-api answer "Ruby best practices" --output-format pretty
62
- exa-api answer "What is the capital of France?" --output-schema '{"type":"object","properties":{"city":{"type":"string"},"state":{"type":"string"}}}'
63
- exa-api answer "What is Paris?" --system-prompt "Respond in the voice of a pirate"
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-api answer --help' for usage information"
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-api context <query> [options]"
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-api context 'React hooks'"
59
- puts " exa-api context 'authentication with JWT in Ruby' --tokens-num 5000"
60
- puts " exa-api context 'React hooks' --output-format text"
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-api context --help' for usage information."
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
@@ -79,6 +79,7 @@ begin
79
79
  # Format and output
80
80
  output = Exa::CLI::Formatters::EnrichmentFormatter.format(enrichment, output_format)
81
81
  puts output
82
+ $stdout.flush
82
83
 
83
84
  rescue Exa::NotFound => e
84
85
  $stderr.puts "Enrichment not found: #{e.message}"
@@ -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}"
@@ -93,6 +93,7 @@ begin
93
93
  # Format and output
94
94
  output = Exa::CLI::Formatters::EnrichmentFormatter.format(result, output_format)
95
95
  puts output
96
+ $stdout.flush
96
97
 
97
98
  rescue Exa::NotFound => e
98
99
  $stderr.puts "Enrichment not found: #{e.message}"
@@ -79,6 +79,7 @@ begin
79
79
  # Format and output
80
80
  output = Exa::CLI::Formatters::EnrichmentFormatter.format(enrichment, output_format)
81
81
  puts output
82
+ $stdout.flush
82
83
 
83
84
  rescue Exa::NotFound => e
84
85
  $stderr.puts "Enrichment not found: #{e.message}"
@@ -74,6 +74,7 @@ begin
74
74
  # Format and output
75
75
  output = Exa::CLI::Formatters::EnrichmentFormatter.format_collection(collection, output_format)
76
76
  puts output
77
+ $stdout.flush
77
78
 
78
79
  rescue Exa::NotFound => e
79
80
  $stderr.puts "Webset not found: #{e.message}"
@@ -142,6 +142,7 @@ begin
142
142
  # Format and output
143
143
  output = Exa::CLI::Formatters::EnrichmentFormatter.format(enrichment, output_format)
144
144
  puts output
145
+ $stdout.flush
145
146
 
146
147
  rescue Exa::NotFound => e
147
148
  $stderr.puts "Enrichment not found: #{e.message}"
@@ -215,6 +215,7 @@ begin
215
215
  # Format and output result
216
216
  output = Exa::CLI::Formatters::SearchFormatter.format(result, output_format)
217
217
  puts output
218
+ $stdout.flush
218
219
 
219
220
  rescue Exa::ConfigurationError => e
220
221
  $stderr.puts "Configuration error: #{e.message}"
@@ -164,7 +164,7 @@ end
164
164
 
165
165
  def print_help
166
166
  puts <<~HELP
167
- Usage: exa-api get-contents <urls> [options]
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-api get-contents 'https://example.com'
207
- exa-api get-contents 'https://example.com' --text
208
- exa-api get-contents 'https://example.com' --text --text-max-characters 3000 --include-html-tags
209
- exa-api get-contents 'url1,url2' --summary --summary-query "Be terse"
210
- exa-api get-contents 'https://example.com' --subpages 1 --subpage-target about
211
- exa-api get-contents 'https://example.com' --links 5 --image-links 10
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-api get-contents --help' for usage information."
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
@@ -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-api research-get <research_id> [options]
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-api research-get research_123
43
- exa-api research-get research_123 --events
44
- exa-api research-get research_123 --stream
45
- exa-api research-get research_123 --output-format pretty
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-api research-get <research_id> [options]"
63
- warn "Try 'exa-api research-get --help' for more information"
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
 
@@ -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-api research-list [options]
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-api research-list
39
- exa-api research-list --limit 20
40
- exa-api research-list --cursor next_page_cursor
41
- exa-api research-list --output-format pretty
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
@@ -39,7 +39,7 @@ def parse_args(argv)
39
39
  i += 2
40
40
  when "--help", "-h"
41
41
  puts <<~HELP
42
- Usage: exa-api research-start --instructions "TEXT" [OPTIONS]
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-api research-start --instructions "Find Ruby performance tips"
58
- exa-api research-start --instructions "Analyze AI trends" --wait --events
59
- exa-api research-start --instructions "Summarize papers" --model exa-research-pro --wait
60
- exa-api research-start --instructions "Find stats" --output-schema '{"type":"object"}'
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-api research-start --help' for usage information"
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-api research-get #{task.research_id}"
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
- args[:type] = argv[i + 1]
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-api search QUERY [OPTIONS]
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: keyword, neural, fast, or auto (default: auto)
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-api search "ruby programming"
164
- exa-api search "machine learning" --num-results 5 --type keyword
165
- exa-api search "Latest LLM research" --category "research paper"
166
- exa-api search "AI startups" --category company
167
- exa-api search "Anthropic" --linkedin company
168
- exa-api search "Dario Amodei" --linkedin person
169
- exa-api search "AI" --linkedin all
170
- exa-api search "AI research" --include-domains arxiv.org,scholar.google.com
171
- exa-api search "tutorials" --output-format pretty
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-api search --help' for usage information"
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}"
@@ -68,6 +68,7 @@ begin
68
68
  # Format and output
69
69
  output = Exa::CLI::Formatters::WebsetFormatter.format(webset, output_format)
70
70
  puts output
71
+ $stdout.flush
71
72
 
72
73
  rescue Exa::NotFound => e
73
74
  $stderr.puts "Webset not found: #{e.message}"
@@ -167,6 +167,7 @@ begin
167
167
  # Format and output result
168
168
  output = Exa::CLI::Formatters::WebsetFormatter.format(webset, output_format)
169
169
  puts output
170
+ $stdout.flush
170
171
 
171
172
  rescue Exa::ConfigurationError => e
172
173
  $stderr.puts "Configuration error: #{e.message}"
@@ -82,6 +82,7 @@ begin
82
82
  # Format and output
83
83
  output = Exa::CLI::Formatters::WebsetFormatter.format(result, output_format)
84
84
  puts output
85
+ $stdout.flush
85
86
 
86
87
  rescue Exa::NotFound => e
87
88
  $stderr.puts "Webset not found: #{e.message}"
@@ -68,6 +68,7 @@ begin
68
68
  # Format and output
69
69
  output = Exa::CLI::Formatters::WebsetFormatter.format(webset, output_format)
70
70
  puts output
71
+ $stdout.flush
71
72
 
72
73
  rescue Exa::NotFound => e
73
74
  $stderr.puts "Webset not found: #{e.message}"
@@ -80,6 +80,7 @@ begin
80
80
  # Format and output
81
81
  output = Exa::CLI::Formatters::WebsetItemFormatter.format(item, output_format)
82
82
  puts output
83
+ $stdout.flush
83
84
 
84
85
  rescue Exa::NotFound => e
85
86
  $stderr.puts "Item not found: #{e.message}"
@@ -69,6 +69,7 @@ begin
69
69
  # Format and output
70
70
  output = Exa::CLI::Formatters::WebsetItemFormatter.format_collection(items, output_format)
71
71
  puts output
72
+ $stdout.flush
72
73
 
73
74
  rescue Exa::NotFound => e
74
75
  $stderr.puts "Webset not found: #{e.message}"
@@ -65,6 +65,7 @@ begin
65
65
  # Format and output
66
66
  output = Exa::CLI::Formatters::WebsetFormatter.format_collection(collection, output_format)
67
67
  puts output
68
+ $stdout.flush
68
69
 
69
70
  rescue Exa::ConfigurationError => e
70
71
  $stderr.puts "Configuration error: #{e.message}"
@@ -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::WebsetSearchFormatter.format(search, output_format)
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::WebsetSearchFormatter.format(search, output_format)
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::WebsetSearchFormatter.format(search, output_format)
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}"
@@ -111,6 +111,7 @@ begin
111
111
  # Format and output
112
112
  output = Exa::CLI::Formatters::WebsetFormatter.format(webset, output_format)
113
113
  puts output
114
+ $stdout.flush
114
115
 
115
116
  rescue Exa::NotFound => e
116
117
  $stderr.puts "Webset not found: #{e.message}"
@@ -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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Exa
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exa-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Jackson