Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 311ad48

Browse files
committed
document and test new verbs
1 parent d4608d7 commit 311ad48

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

app/models/ai_tool.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def self.preamble
7373
* Returns:
7474
* { status: number, body: string }
7575
*
76+
* (also available: http.put, http.patch, http.delete)
77+
*
7678
* Note: Max 20 HTTP requests per execution.
7779
*
7880
* 2. llm

spec/models/ai_tool_spec.rb

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,37 @@ def create_tool(
3838
expect(runner.invoke).to eq("query" => "test")
3939
end
4040

41-
it "can perform POST HTTP requests" do
42-
script = <<~JS
43-
function invoke(params) {
44-
result = http.post("https://example.com/api",
45-
{
46-
headers: { TestHeader: "TestValue" },
47-
body: JSON.stringify({ data: params.data })
48-
}
49-
);
41+
it "can perform HTTP requests with various verbs" do
42+
[:post, :put, :delete, :patch].each do |verb|
43+
script = <<~JS
44+
function invoke(params) {
45+
result = http.#{verb}("https://example.com/api",
46+
{
47+
headers: { TestHeader: "TestValue" },
48+
body: JSON.stringify({ data: params.data })
49+
}
50+
);
5051
51-
return result.body;
52-
}
53-
JS
52+
return result.body;
53+
}
54+
JS
5455

55-
tool = create_tool(script: script)
56-
runner = tool.runner({ "data" => "test data" }, llm: nil, bot_user: nil, context: {})
56+
tool = create_tool(script: script)
57+
runner = tool.runner({ "data" => "test data" }, llm: nil, bot_user: nil, context: {})
5758

58-
stub_request(:post, "https://example.com/api").with(
59-
body: "{\"data\":\"test data\"}",
60-
headers: {
61-
"Accept" => "*/*",
62-
"Testheader" => "TestValue",
63-
"User-Agent" => "Discourse AI Bot 1.0 (https://www.discourse.org)",
64-
},
65-
).to_return(status: 200, body: "Success", headers: {})
59+
stub_request(verb, "https://example.com/api").with(
60+
body: "{\"data\":\"test data\"}",
61+
headers: {
62+
"Accept" => "*/*",
63+
"Testheader" => "TestValue",
64+
"User-Agent" => "Discourse AI Bot 1.0 (https://www.discourse.org)",
65+
},
66+
).to_return(status: 200, body: "Success", headers: {})
6667

67-
result = runner.invoke
68+
result = runner.invoke
6869

69-
expect(result).to eq("Success")
70+
expect(result).to eq("Success")
71+
end
7072
end
7173

7274
it "can perform GET HTTP requests, with 1 param" do

0 commit comments

Comments
 (0)