Skip to content

Commit a400548

Browse files
committed
rename exa fetch tool to match other files
1 parent 688a1b0 commit a400548

File tree

5 files changed

+96
-19
lines changed

5 files changed

+96
-19
lines changed

agents/openscader/index.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Openscader
2+
description: openscader
3+
version: 0.1.0
4+
instructions: |
5+
You are a professional 3d designer, openscad user. You consult this cheatsheet often - https://openscad.org/cheatsheet/
6+
7+
<tools>
8+
{{__tools__}}
9+
</tools>
10+
11+
<system>
12+
cwd: {{__cwd__}}
13+
</system>
14+

agents/openscader/tools.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
web_search_exa.sh
2+
fetch_url_via_exa.sh
3+
fs_cat.sh
4+
fs_write.sh
5+
execute_openscad.sh

tools/execute_openscad.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# @describe Execute the openscad file.
5+
# @option --path! Path of the file to execute.
6+
7+
# @meta require-tools openscad
8+
9+
# @env LLM_OUTPUT=/dev/stdout The output path
10+
11+
ROOT_DIR="${LLM_ROOT_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
12+
13+
main() {
14+
openscad "$argc_path" -o /tmp/aichat_openscad.echo || true
15+
cat /tmp/aichat_openscad.echo >> "$LLM_OUTPUT"
16+
}
17+
18+
eval "$(argc --argc-eval "$0" "$@")"

tools/fetch_url_via_exa.sh

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
1314
main() {
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

2546
eval "$(argc --argc-eval "$0" "$@")"
47+

tools/web_search_exa.sh

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -x
33

44
# @describe Perform a web search using Exa API to get a list of links to fetch.
55
# Use this when you need current information or feel a search could provide a better answer.
@@ -12,15 +12,33 @@ set -e
1212
# @env LLM_OUTPUT=/dev/stdout The output path The output path
1313

1414
main() {
15-
curl -fsS -X POST 'https://api.exa.ai/search' \
16-
-H "x-api-key: $EXA_API_KEY" \
17-
-H 'Content-Type: application/json' \
18-
-d '{
19-
"query": "'"$argc_query"'",
20-
"type": "keyword",
21-
"numResults": 20
22-
}' | \
23-
jq -r '.results[] | (.title, .url, "")' >> "$LLM_OUTPUT"
15+
json_escaped_query=$(jq -R -s . <<< "$argc_query")
16+
17+
response=$(curl -fsS -X POST 'https://api.exa.ai/search' \
18+
-H "x-api-key: $EXA_API_KEY" \
19+
-H 'Content-Type: application/json' \
20+
-d "{
21+
\"query\": $json_escaped_query,
22+
\"type\": \"keyword\",
23+
\"numResults\": 20
24+
}")
25+
26+
# Check if curl command succeeded
27+
if [ $? -ne 0 ]; then
28+
echo "Error: Failed to execute search request" >> "$LLM_OUTPUT"
29+
return 0
30+
fi
31+
32+
# Check if response contains results
33+
results_count=$(echo "$response" | jq -r '.results | length')
34+
35+
if [ "$results_count" -eq 0 ]; then
36+
echo "No results found for query: $argc_query" >> "$LLM_OUTPUT"
37+
else
38+
# Process results normally
39+
echo "$response" | jq -r '.results[] | (.title, .url, "")' >> "$LLM_OUTPUT"
40+
fi
2441
}
2542

43+
2644
eval "$(argc --argc-eval "$0" "$@")"

0 commit comments

Comments
 (0)