@@ -10,16 +10,38 @@ set -e
1010# @env EXA_API_KEY! The api key
1111# @env LLM_OUTPUT=/dev/stdout The output path The output path
1212
13+
1314main () {
14- curl -fsS -X POST ' https://api.exa.ai/contents' \
15- -H " x-api-key: $EXA_API_KEY " \
16- -H ' Content-Type: application/json' \
17- -d ' {
18- "urls": ["' " $argc_url " ' "],
19- "text": true,
20- "livecrawlTimeout": 10000
21- }' | \
22- jq -r ' .results[0].text' >> " $LLM_OUTPUT "
15+ # Make the API request and capture the full response
16+ response=$( curl -fsS -X POST ' https://api.exa.ai/contents' \
17+ -H " x-api-key: $EXA_API_KEY " \
18+ -H ' Content-Type: application/json' \
19+ -d ' {
20+ "urls": ["' " $argc_url " ' "],
21+ "text": true,
22+ "livecrawlTimeout": 10000
23+ }' )
24+
25+ # Check if curl command succeeded
26+ if [ $? -ne 0 ]; then
27+ echo " Error: Failed to make API request" >> " $LLM_OUTPUT "
28+ exit 0
29+ fi
30+
31+ # Extract the status information
32+ status=$( echo " $response " | jq -r ' .statuses[0].status' )
33+ error_tag=$( echo " $response " | jq -r ' .statuses[0].error.tag // "none"' )
34+ http_status=$( echo " $response " | jq -r ' .statuses[0].error.httpStatusCode // 200' )
35+
36+ # Check if the status indicates an error
37+ if [ " $status " = " error" ] || [ " $http_status " != " 200" ]; then
38+ echo " Error: This page is unavailable" >> " $LLM_OUTPUT "
39+ exit 0
40+ fi
41+
42+ # If successful, extract and output the text
43+ echo " $response " | jq -r ' .results[0].text' >> " $LLM_OUTPUT "
2344}
2445
2546eval " $( argc --argc-eval " $0 " " $@ " ) "
47+
0 commit comments