exa-ai 0.3.1 → 0.4.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/README.md +58 -17
- data/exe/exa-ai +111 -6
- data/exe/exa-ai-enrichment-cancel +107 -0
- data/exe/exa-ai-enrichment-create +235 -0
- data/exe/exa-ai-enrichment-delete +121 -0
- data/exe/exa-ai-enrichment-get +103 -0
- data/exe/exa-ai-enrichment-list +98 -0
- data/exe/exa-ai-enrichment-update +170 -0
- data/exe/exa-ai-find-similar +240 -0
- data/exe/exa-ai-webset-cancel +96 -0
- data/exe/exa-ai-webset-create +192 -0
- data/exe/exa-ai-webset-delete +110 -0
- data/exe/exa-ai-webset-get +92 -0
- data/exe/exa-ai-webset-item-delete +111 -0
- data/exe/exa-ai-webset-item-get +104 -0
- data/exe/exa-ai-webset-item-list +93 -0
- data/exe/exa-ai-webset-list +90 -0
- data/exe/exa-ai-webset-search-cancel +103 -0
- data/exe/exa-ai-webset-search-create +233 -0
- data/exe/exa-ai-webset-search-get +104 -0
- data/exe/exa-ai-webset-update +139 -0
- data/lib/exa/cli/formatters/enrichment_formatter.rb +69 -0
- data/lib/exa/cli/formatters/webset_formatter.rb +68 -0
- data/lib/exa/cli/formatters/webset_item_formatter.rb +69 -0
- data/lib/exa/client.rb +171 -0
- data/lib/exa/resources/webset.rb +74 -0
- data/lib/exa/resources/webset_collection.rb +33 -0
- data/lib/exa/resources/webset_enrichment.rb +71 -0
- data/lib/exa/resources/webset_enrichment_collection.rb +28 -0
- data/lib/exa/resources/webset_search.rb +112 -0
- data/lib/exa/services/parameter_converter.rb +1 -0
- data/lib/exa/services/websets/cancel.rb +36 -0
- data/lib/exa/services/websets/cancel_enrichment.rb +35 -0
- data/lib/exa/services/websets/cancel_search.rb +44 -0
- data/lib/exa/services/websets/create.rb +45 -0
- data/lib/exa/services/websets/create_enrichment.rb +35 -0
- data/lib/exa/services/websets/create_search.rb +48 -0
- data/lib/exa/services/websets/create_search_validator.rb +128 -0
- data/lib/exa/services/websets/create_validator.rb +189 -0
- data/lib/exa/services/websets/delete.rb +36 -0
- data/lib/exa/services/websets/delete_enrichment.rb +35 -0
- data/lib/exa/services/websets/delete_item.rb +20 -0
- data/lib/exa/services/websets/get_item.rb +20 -0
- data/lib/exa/services/websets/get_search.rb +43 -0
- data/lib/exa/services/websets/list.rb +25 -0
- data/lib/exa/services/websets/list_items.rb +20 -0
- data/lib/exa/services/websets/retrieve.rb +47 -0
- data/lib/exa/services/websets/retrieve_enrichment.rb +35 -0
- data/lib/exa/services/websets/update.rb +37 -0
- data/lib/exa/services/websets/update_enrichment.rb +36 -0
- data/lib/exa/services/websets_parameter_converter.rb +45 -0
- data/lib/exa/version.rb +1 -1
- data/lib/exa.rb +25 -0
- metadata +64 -3
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "exa-ai"
|
|
5
|
+
|
|
6
|
+
# Parse command-line arguments
|
|
7
|
+
def parse_args(argv)
|
|
8
|
+
args = {
|
|
9
|
+
output_format: "json",
|
|
10
|
+
api_key: nil
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
# Extract URL (first non-flag argument)
|
|
14
|
+
url_found = false
|
|
15
|
+
i = 0
|
|
16
|
+
while i < argv.length
|
|
17
|
+
arg = argv[i]
|
|
18
|
+
case arg
|
|
19
|
+
when "--num-results"
|
|
20
|
+
args[:num_results] = argv[i + 1].to_i
|
|
21
|
+
i += 2
|
|
22
|
+
when "--exclude-source-domain"
|
|
23
|
+
args[:exclude_source_domain] = true
|
|
24
|
+
i += 1
|
|
25
|
+
when "--category"
|
|
26
|
+
category = argv[i + 1]
|
|
27
|
+
valid_categories = ["company", "research paper", "news", "pdf", "github", "tweet", "personal site", "linkedin profile", "financial report"]
|
|
28
|
+
unless valid_categories.include?(category)
|
|
29
|
+
$stderr.puts "Error: Category must be one of: #{valid_categories.map { |c| "\"#{c}\"" }.join(', ')}"
|
|
30
|
+
exit 1
|
|
31
|
+
end
|
|
32
|
+
args[:category] = category
|
|
33
|
+
i += 2
|
|
34
|
+
when "--include-domains"
|
|
35
|
+
args[:include_domains] = argv[i + 1].split(",").map(&:strip)
|
|
36
|
+
i += 2
|
|
37
|
+
when "--exclude-domains"
|
|
38
|
+
args[:exclude_domains] = argv[i + 1].split(",").map(&:strip)
|
|
39
|
+
i += 2
|
|
40
|
+
when "--start-published-date"
|
|
41
|
+
args[:start_published_date] = argv[i + 1]
|
|
42
|
+
i += 2
|
|
43
|
+
when "--end-published-date"
|
|
44
|
+
args[:end_published_date] = argv[i + 1]
|
|
45
|
+
i += 2
|
|
46
|
+
when "--start-crawl-date"
|
|
47
|
+
args[:start_crawl_date] = argv[i + 1]
|
|
48
|
+
i += 2
|
|
49
|
+
when "--end-crawl-date"
|
|
50
|
+
args[:end_crawl_date] = argv[i + 1]
|
|
51
|
+
i += 2
|
|
52
|
+
when "--include-text"
|
|
53
|
+
args[:include_text] ||= []
|
|
54
|
+
args[:include_text] << argv[i + 1]
|
|
55
|
+
i += 2
|
|
56
|
+
when "--exclude-text"
|
|
57
|
+
args[:exclude_text] ||= []
|
|
58
|
+
args[:exclude_text] << argv[i + 1]
|
|
59
|
+
i += 2
|
|
60
|
+
when "--text"
|
|
61
|
+
args[:text] = true
|
|
62
|
+
i += 1
|
|
63
|
+
when "--text-max-characters"
|
|
64
|
+
args[:text_max_characters] = argv[i + 1].to_i
|
|
65
|
+
i += 2
|
|
66
|
+
when "--include-html-tags"
|
|
67
|
+
args[:include_html_tags] = true
|
|
68
|
+
i += 1
|
|
69
|
+
when "--summary"
|
|
70
|
+
args[:summary] = true
|
|
71
|
+
i += 1
|
|
72
|
+
when "--summary-query"
|
|
73
|
+
args[:summary_query] = argv[i + 1]
|
|
74
|
+
i += 2
|
|
75
|
+
when "--summary-schema"
|
|
76
|
+
schema_arg = argv[i + 1]
|
|
77
|
+
args[:summary_schema] = if schema_arg.start_with?("@")
|
|
78
|
+
JSON.parse(File.read(schema_arg[1..]))
|
|
79
|
+
else
|
|
80
|
+
JSON.parse(schema_arg)
|
|
81
|
+
end
|
|
82
|
+
i += 2
|
|
83
|
+
when "--api-key"
|
|
84
|
+
args[:api_key] = argv[i + 1]
|
|
85
|
+
i += 2
|
|
86
|
+
when "--output-format"
|
|
87
|
+
args[:output_format] = argv[i + 1]
|
|
88
|
+
i += 2
|
|
89
|
+
when "--help", "-h"
|
|
90
|
+
puts <<~HELP
|
|
91
|
+
Usage: exa-ai find-similar URL [OPTIONS]
|
|
92
|
+
|
|
93
|
+
Find content similar to a given URL
|
|
94
|
+
|
|
95
|
+
Arguments:
|
|
96
|
+
URL URL to find similar content for (required)
|
|
97
|
+
|
|
98
|
+
Options:
|
|
99
|
+
--num-results N Number of results to return (default: 10)
|
|
100
|
+
--exclude-source-domain Exclude results from the source URL's domain
|
|
101
|
+
--category CAT Focus on specific data category
|
|
102
|
+
Options: "company", "research paper", "news", "pdf",
|
|
103
|
+
"github", "tweet", "personal site", "linkedin profile",
|
|
104
|
+
"financial report"
|
|
105
|
+
--include-domains D Comma-separated list of domains to include
|
|
106
|
+
--exclude-domains D Comma-separated list of domains to exclude
|
|
107
|
+
--start-published-date DATE Filter by published date (ISO 8601 format)
|
|
108
|
+
--end-published-date DATE Filter by published date (ISO 8601 format)
|
|
109
|
+
--start-crawl-date DATE Filter by crawl date (ISO 8601 format)
|
|
110
|
+
--end-crawl-date DATE Filter by crawl date (ISO 8601 format)
|
|
111
|
+
--include-text PHRASE Include results with exact phrase (repeatable)
|
|
112
|
+
--exclude-text PHRASE Exclude results with exact phrase (repeatable)
|
|
113
|
+
|
|
114
|
+
Content Extraction:
|
|
115
|
+
--text Include full webpage text
|
|
116
|
+
--text-max-characters N Max characters for webpage text
|
|
117
|
+
--include-html-tags Include HTML tags in text extraction
|
|
118
|
+
--summary Include AI-generated summary
|
|
119
|
+
--summary-query PROMPT Custom prompt for summary generation
|
|
120
|
+
--summary-schema FILE JSON schema for summary structure (@file syntax)
|
|
121
|
+
|
|
122
|
+
General Options:
|
|
123
|
+
--api-key KEY Exa API key (or set EXA_API_KEY env var)
|
|
124
|
+
--output-format FMT Output format: json, pretty, or text (default: json)
|
|
125
|
+
--help, -h Show this help message
|
|
126
|
+
|
|
127
|
+
Examples:
|
|
128
|
+
exa-ai find-similar "https://example.com/article"
|
|
129
|
+
exa-ai find-similar "https://techcrunch.com/ai-startup" --num-results 5
|
|
130
|
+
exa-ai find-similar "https://arxiv.org/paper" --category "research paper"
|
|
131
|
+
exa-ai find-similar "https://example.com" --exclude-source-domain
|
|
132
|
+
exa-ai find-similar "https://example.com" --output-format pretty
|
|
133
|
+
HELP
|
|
134
|
+
exit 0
|
|
135
|
+
else
|
|
136
|
+
unless url_found
|
|
137
|
+
args[:url] = arg
|
|
138
|
+
url_found = true
|
|
139
|
+
end
|
|
140
|
+
i += 1
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
args
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Build contents parameter from extracted flags
|
|
148
|
+
def build_contents(args)
|
|
149
|
+
contents = {}
|
|
150
|
+
|
|
151
|
+
# Text options
|
|
152
|
+
if args[:text]
|
|
153
|
+
if args[:text_max_characters] || args[:include_html_tags]
|
|
154
|
+
contents[:text] = {}
|
|
155
|
+
contents[:text][:max_characters] = args[:text_max_characters] if args[:text_max_characters]
|
|
156
|
+
contents[:text][:include_html_tags] = args[:include_html_tags] if args[:include_html_tags]
|
|
157
|
+
else
|
|
158
|
+
contents[:text] = true
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Summary options
|
|
163
|
+
if args[:summary]
|
|
164
|
+
if args[:summary_query] || args[:summary_schema]
|
|
165
|
+
contents[:summary] = {}
|
|
166
|
+
contents[:summary][:query] = args[:summary_query] if args[:summary_query]
|
|
167
|
+
contents[:summary][:schema] = args[:summary_schema] if args[:summary_schema]
|
|
168
|
+
else
|
|
169
|
+
contents[:summary] = true
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
contents.empty? ? nil : contents
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Main execution
|
|
177
|
+
begin
|
|
178
|
+
args = parse_args(ARGV)
|
|
179
|
+
|
|
180
|
+
# Validate URL
|
|
181
|
+
if args[:url].nil? || args[:url].empty?
|
|
182
|
+
$stderr.puts "Error: URL is required"
|
|
183
|
+
$stderr.puts "Run 'exa-ai find-similar --help' for usage information"
|
|
184
|
+
exit 1
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# Resolve API key
|
|
188
|
+
api_key = Exa::CLI::Base.resolve_api_key(args[:api_key])
|
|
189
|
+
|
|
190
|
+
# Resolve output format
|
|
191
|
+
output_format = Exa::CLI::Base.resolve_output_format(args[:output_format])
|
|
192
|
+
|
|
193
|
+
# Build client
|
|
194
|
+
client = Exa::CLI::Base.build_client(api_key)
|
|
195
|
+
|
|
196
|
+
# Prepare parameters
|
|
197
|
+
params = {}
|
|
198
|
+
params[:numResults] = args[:num_results] if args[:num_results]
|
|
199
|
+
params[:excludeSourceDomain] = args[:exclude_source_domain] if args[:exclude_source_domain]
|
|
200
|
+
params[:category] = args[:category] if args[:category]
|
|
201
|
+
params[:includeDomains] = args[:include_domains] if args[:include_domains]
|
|
202
|
+
params[:excludeDomains] = args[:exclude_domains] if args[:exclude_domains]
|
|
203
|
+
params[:start_published_date] = args[:start_published_date] if args[:start_published_date]
|
|
204
|
+
params[:end_published_date] = args[:end_published_date] if args[:end_published_date]
|
|
205
|
+
params[:start_crawl_date] = args[:start_crawl_date] if args[:start_crawl_date]
|
|
206
|
+
params[:end_crawl_date] = args[:end_crawl_date] if args[:end_crawl_date]
|
|
207
|
+
params[:include_text] = args[:include_text] if args[:include_text]
|
|
208
|
+
params[:exclude_text] = args[:exclude_text] if args[:exclude_text]
|
|
209
|
+
contents = build_contents(args)
|
|
210
|
+
params.merge!(contents) if contents
|
|
211
|
+
|
|
212
|
+
# Execute find_similar
|
|
213
|
+
result = client.find_similar(args[:url], **params)
|
|
214
|
+
|
|
215
|
+
# Format and output result
|
|
216
|
+
output = Exa::CLI::Formatters::SearchFormatter.format(result, output_format)
|
|
217
|
+
puts output
|
|
218
|
+
|
|
219
|
+
rescue Exa::ConfigurationError => e
|
|
220
|
+
$stderr.puts "Configuration error: #{e.message}"
|
|
221
|
+
exit 1
|
|
222
|
+
rescue Exa::Unauthorized => e
|
|
223
|
+
$stderr.puts "Authentication error: #{e.message}"
|
|
224
|
+
$stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
|
|
225
|
+
exit 1
|
|
226
|
+
rescue Exa::ClientError => e
|
|
227
|
+
$stderr.puts "Client error: #{e.message}"
|
|
228
|
+
exit 1
|
|
229
|
+
rescue Exa::ServerError => e
|
|
230
|
+
$stderr.puts "Server error: #{e.message}"
|
|
231
|
+
$stderr.puts "The Exa API may be experiencing issues. Please try again later."
|
|
232
|
+
exit 1
|
|
233
|
+
rescue Exa::Error => e
|
|
234
|
+
$stderr.puts "Error: #{e.message}"
|
|
235
|
+
exit 1
|
|
236
|
+
rescue StandardError => e
|
|
237
|
+
$stderr.puts "Unexpected error: #{e.message}"
|
|
238
|
+
$stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
|
|
239
|
+
exit 1
|
|
240
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "exa-ai"
|
|
5
|
+
|
|
6
|
+
# Parse arguments
|
|
7
|
+
webset_id = nil
|
|
8
|
+
api_key = nil
|
|
9
|
+
output_format = "json"
|
|
10
|
+
|
|
11
|
+
args = ARGV.dup
|
|
12
|
+
while args.any?
|
|
13
|
+
arg = args.shift
|
|
14
|
+
case arg
|
|
15
|
+
when "--api-key"
|
|
16
|
+
api_key = args.shift
|
|
17
|
+
when "--output-format"
|
|
18
|
+
output_format = args.shift
|
|
19
|
+
when "--help", "-h"
|
|
20
|
+
puts <<~HELP
|
|
21
|
+
Usage: exa-ai webset-cancel <webset_id> [OPTIONS]
|
|
22
|
+
|
|
23
|
+
Cancel a running webset
|
|
24
|
+
|
|
25
|
+
Arguments:
|
|
26
|
+
webset_id ID of the webset to cancel (required)
|
|
27
|
+
|
|
28
|
+
Options:
|
|
29
|
+
--api-key KEY Exa API key (or set EXA_API_KEY env var)
|
|
30
|
+
--output-format FMT Output format: json, pretty, or text (default: json)
|
|
31
|
+
--help, -h Show this help message
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
exa-ai webset-cancel ws_abc123
|
|
35
|
+
exa-ai webset-cancel ws_abc123 --output-format pretty
|
|
36
|
+
HELP
|
|
37
|
+
exit 0
|
|
38
|
+
else
|
|
39
|
+
# First positional argument is webset_id
|
|
40
|
+
if webset_id.nil?
|
|
41
|
+
webset_id = arg
|
|
42
|
+
else
|
|
43
|
+
$stderr.puts "Unknown option: #{arg}"
|
|
44
|
+
exit 1
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Validate
|
|
50
|
+
if webset_id.nil?
|
|
51
|
+
$stderr.puts "Error: webset_id argument is required"
|
|
52
|
+
$stderr.puts "Usage: exa-ai webset-cancel <webset_id> [OPTIONS]"
|
|
53
|
+
$stderr.puts "Try 'exa-ai webset-cancel --help' for more information"
|
|
54
|
+
exit 1
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
begin
|
|
58
|
+
# Resolve API key and format
|
|
59
|
+
api_key = Exa::CLI::Base.resolve_api_key(api_key)
|
|
60
|
+
output_format = Exa::CLI::Base.resolve_output_format(output_format)
|
|
61
|
+
|
|
62
|
+
# Build client
|
|
63
|
+
client = Exa::CLI::Base.build_client(api_key)
|
|
64
|
+
|
|
65
|
+
# Cancel webset
|
|
66
|
+
webset = client.cancel_webset(webset_id)
|
|
67
|
+
|
|
68
|
+
# Format and output
|
|
69
|
+
output = Exa::CLI::Formatters::WebsetFormatter.format(webset, output_format)
|
|
70
|
+
puts output
|
|
71
|
+
|
|
72
|
+
rescue Exa::NotFound => e
|
|
73
|
+
$stderr.puts "Webset not found: #{e.message}"
|
|
74
|
+
exit 1
|
|
75
|
+
rescue Exa::ConfigurationError => e
|
|
76
|
+
$stderr.puts "Configuration error: #{e.message}"
|
|
77
|
+
exit 1
|
|
78
|
+
rescue Exa::Unauthorized => e
|
|
79
|
+
$stderr.puts "Authentication error: #{e.message}"
|
|
80
|
+
$stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
|
|
81
|
+
exit 1
|
|
82
|
+
rescue Exa::ClientError => e
|
|
83
|
+
$stderr.puts "Client error: #{e.message}"
|
|
84
|
+
exit 1
|
|
85
|
+
rescue Exa::ServerError => e
|
|
86
|
+
$stderr.puts "Server error: #{e.message}"
|
|
87
|
+
$stderr.puts "The Exa API may be experiencing issues. Please try again later."
|
|
88
|
+
exit 1
|
|
89
|
+
rescue Exa::Error => e
|
|
90
|
+
$stderr.puts "Error: #{e.message}"
|
|
91
|
+
exit 1
|
|
92
|
+
rescue StandardError => e
|
|
93
|
+
$stderr.puts "Unexpected error: #{e.message}"
|
|
94
|
+
$stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
|
|
95
|
+
exit 1
|
|
96
|
+
end
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "exa-ai"
|
|
5
|
+
|
|
6
|
+
# Recursively convert hash keys from strings to symbols
|
|
7
|
+
def deep_symbolize_keys(obj)
|
|
8
|
+
case obj
|
|
9
|
+
when Hash
|
|
10
|
+
obj.each_with_object({}) do |(key, value), result|
|
|
11
|
+
result[key.to_sym] = deep_symbolize_keys(value)
|
|
12
|
+
end
|
|
13
|
+
when Array
|
|
14
|
+
obj.map { |item| deep_symbolize_keys(item) }
|
|
15
|
+
else
|
|
16
|
+
obj
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Parse JSON string or load from file (supports @file.json syntax)
|
|
21
|
+
def parse_json_or_file(value)
|
|
22
|
+
json_data = if value.start_with?("@")
|
|
23
|
+
file_path = value[1..]
|
|
24
|
+
JSON.parse(File.read(file_path))
|
|
25
|
+
else
|
|
26
|
+
JSON.parse(value)
|
|
27
|
+
end
|
|
28
|
+
deep_symbolize_keys(json_data)
|
|
29
|
+
rescue JSON::ParserError => e
|
|
30
|
+
$stderr.puts "Error: Invalid JSON: #{e.message}"
|
|
31
|
+
exit 1
|
|
32
|
+
rescue Errno::ENOENT => e
|
|
33
|
+
$stderr.puts "Error: File not found: #{e.message}"
|
|
34
|
+
exit 1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Parse command-line arguments
|
|
38
|
+
def parse_args(argv)
|
|
39
|
+
args = {
|
|
40
|
+
output_format: "json",
|
|
41
|
+
api_key: nil,
|
|
42
|
+
wait: false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
i = 0
|
|
46
|
+
while i < argv.length
|
|
47
|
+
arg = argv[i]
|
|
48
|
+
case arg
|
|
49
|
+
when "--search"
|
|
50
|
+
args[:search] = parse_json_or_file(argv[i + 1])
|
|
51
|
+
i += 2
|
|
52
|
+
when "--enrichments"
|
|
53
|
+
args[:enrichments] = parse_json_or_file(argv[i + 1])
|
|
54
|
+
i += 2
|
|
55
|
+
when "--exclude"
|
|
56
|
+
args[:exclude] = parse_json_or_file(argv[i + 1])
|
|
57
|
+
i += 2
|
|
58
|
+
when "--external-id"
|
|
59
|
+
args[:external_id] = argv[i + 1]
|
|
60
|
+
i += 2
|
|
61
|
+
when "--metadata"
|
|
62
|
+
args[:metadata] = parse_json_or_file(argv[i + 1])
|
|
63
|
+
i += 2
|
|
64
|
+
when "--wait"
|
|
65
|
+
args[:wait] = true
|
|
66
|
+
i += 1
|
|
67
|
+
when "--api-key"
|
|
68
|
+
args[:api_key] = argv[i + 1]
|
|
69
|
+
i += 2
|
|
70
|
+
when "--output-format"
|
|
71
|
+
args[:output_format] = argv[i + 1]
|
|
72
|
+
i += 2
|
|
73
|
+
when "--help", "-h"
|
|
74
|
+
puts <<~HELP
|
|
75
|
+
Usage: exa-ai webset-create --search JSON [OPTIONS]
|
|
76
|
+
|
|
77
|
+
Create a new webset with search criteria
|
|
78
|
+
|
|
79
|
+
Required:
|
|
80
|
+
--search JSON Search configuration (supports @file.json)
|
|
81
|
+
|
|
82
|
+
Options:
|
|
83
|
+
--enrichments JSON Array of enrichment configs (supports @file.json)
|
|
84
|
+
--exclude JSON Array of exclude configs (supports @file.json)
|
|
85
|
+
--external-id ID External identifier for the webset
|
|
86
|
+
--metadata JSON Custom metadata (supports @file.json)
|
|
87
|
+
--wait Wait for webset to reach idle status
|
|
88
|
+
--api-key KEY Exa API key (or set EXA_API_KEY env var)
|
|
89
|
+
--output-format FMT Output format: json, pretty, or text (default: json)
|
|
90
|
+
--help, -h Show this help message
|
|
91
|
+
|
|
92
|
+
Examples:
|
|
93
|
+
exa-ai webset-create --search '{"query":"AI startups","count":10}'
|
|
94
|
+
exa-ai webset-create --search @search.json --enrichments @enrichments.json
|
|
95
|
+
exa-ai webset-create --search @search.json --wait
|
|
96
|
+
HELP
|
|
97
|
+
exit 0
|
|
98
|
+
else
|
|
99
|
+
$stderr.puts "Unknown option: #{arg}"
|
|
100
|
+
exit 1
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
args
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# Main execution
|
|
108
|
+
begin
|
|
109
|
+
args = parse_args(ARGV)
|
|
110
|
+
|
|
111
|
+
# Validate required parameters
|
|
112
|
+
unless args[:search]
|
|
113
|
+
$stderr.puts "Error: --search is required"
|
|
114
|
+
$stderr.puts "Run 'exa-ai webset-create --help' for usage information"
|
|
115
|
+
exit 1
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Resolve API key
|
|
119
|
+
api_key = Exa::CLI::Base.resolve_api_key(args[:api_key])
|
|
120
|
+
|
|
121
|
+
# Resolve output format
|
|
122
|
+
output_format = Exa::CLI::Base.resolve_output_format(args[:output_format])
|
|
123
|
+
|
|
124
|
+
# Build client
|
|
125
|
+
client = Exa::CLI::Base.build_client(api_key)
|
|
126
|
+
|
|
127
|
+
# Prepare webset parameters
|
|
128
|
+
webset_params = { search: args[:search] }
|
|
129
|
+
webset_params[:enrichments] = args[:enrichments] if args[:enrichments]
|
|
130
|
+
webset_params[:exclude] = args[:exclude] if args[:exclude]
|
|
131
|
+
webset_params[:externalId] = args[:external_id] if args[:external_id]
|
|
132
|
+
webset_params[:metadata] = args[:metadata] if args[:metadata]
|
|
133
|
+
|
|
134
|
+
# Create webset
|
|
135
|
+
webset = client.create_webset(**webset_params)
|
|
136
|
+
|
|
137
|
+
# If --wait flag is set, poll until webset is idle
|
|
138
|
+
if args[:wait]
|
|
139
|
+
$stderr.print "Creating webset... "
|
|
140
|
+
|
|
141
|
+
begin
|
|
142
|
+
final_webset = Exa::CLI::Polling.poll(max_duration: 300, initial_delay: 2, max_delay: 10) do
|
|
143
|
+
current_webset = client.get_webset(webset.id)
|
|
144
|
+
|
|
145
|
+
# Show progress indicator
|
|
146
|
+
case current_webset.status
|
|
147
|
+
when "pending"
|
|
148
|
+
$stderr.print "⏳"
|
|
149
|
+
when "running"
|
|
150
|
+
$stderr.print "⚙️"
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
done = current_webset.idle?
|
|
154
|
+
{ done: done, result: current_webset, status: current_webset.status }
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
$stderr.puts " #{final_webset.status.upcase}"
|
|
158
|
+
webset = final_webset
|
|
159
|
+
|
|
160
|
+
rescue Exa::CLI::Polling::TimeoutError
|
|
161
|
+
$stderr.puts "\nWarning: Webset creation did not complete within timeout"
|
|
162
|
+
$stderr.puts "Webset ID: #{webset.id}"
|
|
163
|
+
$stderr.puts "Check status with: exa-ai webset-get #{webset.id}"
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Format and output result
|
|
168
|
+
output = Exa::CLI::Formatters::WebsetFormatter.format(webset, output_format)
|
|
169
|
+
puts output
|
|
170
|
+
|
|
171
|
+
rescue Exa::ConfigurationError => e
|
|
172
|
+
$stderr.puts "Configuration error: #{e.message}"
|
|
173
|
+
exit 1
|
|
174
|
+
rescue Exa::Unauthorized => e
|
|
175
|
+
$stderr.puts "Authentication error: #{e.message}"
|
|
176
|
+
$stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
|
|
177
|
+
exit 1
|
|
178
|
+
rescue Exa::ClientError => e
|
|
179
|
+
$stderr.puts "Client error: #{e.message}"
|
|
180
|
+
exit 1
|
|
181
|
+
rescue Exa::ServerError => e
|
|
182
|
+
$stderr.puts "Server error: #{e.message}"
|
|
183
|
+
$stderr.puts "The Exa API may be experiencing issues. Please try again later."
|
|
184
|
+
exit 1
|
|
185
|
+
rescue Exa::Error => e
|
|
186
|
+
$stderr.puts "Error: #{e.message}"
|
|
187
|
+
exit 1
|
|
188
|
+
rescue StandardError => e
|
|
189
|
+
$stderr.puts "Unexpected error: #{e.message}"
|
|
190
|
+
$stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
|
|
191
|
+
exit 1
|
|
192
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "exa-ai"
|
|
5
|
+
|
|
6
|
+
# Parse arguments
|
|
7
|
+
webset_id = nil
|
|
8
|
+
force = false
|
|
9
|
+
api_key = nil
|
|
10
|
+
output_format = "json"
|
|
11
|
+
|
|
12
|
+
args = ARGV.dup
|
|
13
|
+
while args.any?
|
|
14
|
+
arg = args.shift
|
|
15
|
+
case arg
|
|
16
|
+
when "--force"
|
|
17
|
+
force = true
|
|
18
|
+
when "--api-key"
|
|
19
|
+
api_key = args.shift
|
|
20
|
+
when "--output-format"
|
|
21
|
+
output_format = args.shift
|
|
22
|
+
when "--help", "-h"
|
|
23
|
+
puts <<~HELP
|
|
24
|
+
Usage: exa-ai webset-delete <webset_id> [OPTIONS]
|
|
25
|
+
|
|
26
|
+
Delete a webset
|
|
27
|
+
|
|
28
|
+
Arguments:
|
|
29
|
+
webset_id ID of the webset to delete (required)
|
|
30
|
+
|
|
31
|
+
Options:
|
|
32
|
+
--force Skip confirmation prompt
|
|
33
|
+
--api-key KEY Exa API key (or set EXA_API_KEY env var)
|
|
34
|
+
--output-format FMT Output format: json, pretty, or text (default: json)
|
|
35
|
+
--help, -h Show this help message
|
|
36
|
+
|
|
37
|
+
Examples:
|
|
38
|
+
exa-ai webset-delete ws_abc123
|
|
39
|
+
exa-ai webset-delete ws_abc123 --force
|
|
40
|
+
HELP
|
|
41
|
+
exit 0
|
|
42
|
+
else
|
|
43
|
+
# First positional argument is webset_id
|
|
44
|
+
if webset_id.nil?
|
|
45
|
+
webset_id = arg
|
|
46
|
+
else
|
|
47
|
+
$stderr.puts "Unknown option: #{arg}"
|
|
48
|
+
exit 1
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Validate
|
|
54
|
+
if webset_id.nil?
|
|
55
|
+
$stderr.puts "Error: webset_id argument is required"
|
|
56
|
+
$stderr.puts "Usage: exa-ai webset-delete <webset_id> [OPTIONS]"
|
|
57
|
+
$stderr.puts "Try 'exa-ai webset-delete --help' for more information"
|
|
58
|
+
exit 1
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
begin
|
|
62
|
+
# Resolve API key and format
|
|
63
|
+
api_key = Exa::CLI::Base.resolve_api_key(api_key)
|
|
64
|
+
output_format = Exa::CLI::Base.resolve_output_format(output_format)
|
|
65
|
+
|
|
66
|
+
# Confirm deletion unless --force is used
|
|
67
|
+
unless force
|
|
68
|
+
$stderr.print "Delete webset #{webset_id}? (y/N): "
|
|
69
|
+
response = $stdin.gets.chomp.downcase
|
|
70
|
+
unless response == "y" || response == "yes"
|
|
71
|
+
$stderr.puts "Cancelled"
|
|
72
|
+
exit 0
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Build client
|
|
77
|
+
client = Exa::CLI::Base.build_client(api_key)
|
|
78
|
+
|
|
79
|
+
# Delete webset
|
|
80
|
+
result = client.delete_webset(webset_id)
|
|
81
|
+
|
|
82
|
+
# Format and output
|
|
83
|
+
output = Exa::CLI::Formatters::WebsetFormatter.format(result, output_format)
|
|
84
|
+
puts output
|
|
85
|
+
|
|
86
|
+
rescue Exa::NotFound => e
|
|
87
|
+
$stderr.puts "Webset not found: #{e.message}"
|
|
88
|
+
exit 1
|
|
89
|
+
rescue Exa::ConfigurationError => e
|
|
90
|
+
$stderr.puts "Configuration error: #{e.message}"
|
|
91
|
+
exit 1
|
|
92
|
+
rescue Exa::Unauthorized => e
|
|
93
|
+
$stderr.puts "Authentication error: #{e.message}"
|
|
94
|
+
$stderr.puts "Check your API key (set EXA_API_KEY or use --api-key)"
|
|
95
|
+
exit 1
|
|
96
|
+
rescue Exa::ClientError => e
|
|
97
|
+
$stderr.puts "Client error: #{e.message}"
|
|
98
|
+
exit 1
|
|
99
|
+
rescue Exa::ServerError => e
|
|
100
|
+
$stderr.puts "Server error: #{e.message}"
|
|
101
|
+
$stderr.puts "The Exa API may be experiencing issues. Please try again later."
|
|
102
|
+
exit 1
|
|
103
|
+
rescue Exa::Error => e
|
|
104
|
+
$stderr.puts "Error: #{e.message}"
|
|
105
|
+
exit 1
|
|
106
|
+
rescue StandardError => e
|
|
107
|
+
$stderr.puts "Unexpected error: #{e.message}"
|
|
108
|
+
$stderr.puts e.backtrace.first(5) if ENV["DEBUG"]
|
|
109
|
+
exit 1
|
|
110
|
+
end
|