Thanks Sam,
Easier for some than other. I am in the latter category 
I am fiddling around with this and haven’t got this to work. I have no tool experience so actually looking forward to getting this working to think about other ways to use tools.
I tried using the code from your blog with an API key which did not work. AI suggested I use a hard coded url so I tried that without success.
The API Key was not called and there are no logs that were created with errors.
This is used to automatically categorize topics on creation
I will classify the topic “Insights from Jesus’ early years and miracles” into the category of New Testament, as it relates to the life and teachings of Jesus.
Moving the topic now…
This is what I tried.
/**
- Tool API Quick Reference
- Entry Functions
- invoke(parameters): Main function. Receives parameters (Object). Must return a JSON-serializable value.
- Example:
- function invoke(parameters) { return “result”; }
- details(): Optional. Returns a string describing the tool.
- Example:
- function details() { return “Tool description.”; }
- Provided Objects
-
- http
- http.get(url, options?): Performs an HTTP GET request.
- Parameters:
-
url (string): The request URL.
-
options (Object, optional):
-
headers (Object): Request headers.
- Returns:
-
{ status: number, body: string }
- http.post(url, options?): Performs an HTTP POST request.
- Parameters:
-
url (string): The request URL.
-
options (Object, optional):
-
headers (Object): Request headers.
-
body (string): Request body.
- Returns:
-
{ status: number, body: string }
- (also available: http.put, http.patch, http.delete)
- Note: Max 20 HTTP requests per execution.
-
- llm
- llm.truncate(text, length): Truncates text to a specified token length.
- Parameters:
-
text (string): Text to truncate.
-
length (number): Max tokens.
- Returns:
-
Truncated string.
-
- index
- index.search(query, options?): Searches indexed documents.
- Parameters:
-
query (string): Search query.
-
options (Object, optional):
-
filenames (Array): Limit search to specific files.
-
limit (number): Max fragments (up to 200).
- Returns:
-
Array of { fragment: string, metadata: string }
-
- upload
- upload.create(filename, base_64_content): Uploads a file.
- Parameters:
-
filename (string): Name of the file.
-
base_64_content (string): Base64 encoded file content.
- Returns:
-
{ id: number, short_url: string }
-
- chain
- chain.setCustomRaw(raw): Sets the body of the post and exist chain.
- Parameters:
-
raw (string): raw content to add to post.
- Constraints
- Execution Time: ≤ 2000ms
- Memory: ≤ 10MB
- HTTP Requests: ≤ 20 per execution
- Exceeding limits will result in errors or termination.
- Security
- Sandboxed Environment: No access to system or global objects.
- No File System Access: Cannot read or write files.
*/
/**
- Discourse Topic Categorizer
- This tool allows you to change the category of a Discourse topic
- using the Discourse API.
*/
/**
- Discourse Topic Categorizer
- This tool allows you to change the category of a Discourse topic
- using the Discourse API.
*/
/**
- Discourse Topic Categorizer
- This tool allows you to change the category of a Discourse topic
- using the Discourse API.
*/
function invoke(params) {
// Required parameters validation
if (!params.topic_id) {
return { error: “Missing required parameter: topic_id” };
}
if (!params.category_id) {
return { error: “Missing required parameter: category_id” };
}
// Base URL for your Discourse instance
const baseUrl = “https://community.mysite.com”;
// Full API endpoint URL for updating a topic
const apiUrl = ${baseUrl}/t/${params.topic_id}.json
;
// Prepare request body
const requestBody = {
category_id: params.category_id
};
// Optional parameter: update the title if provided
if (params.title) {
requestBody.title = params.title;
}
// Use your provided API key
const apiKey = “Discourse-API-Key”;
try {
// Make PUT request to update the topic
const response = http.put(apiUrl, {
headers: {
“Content-Type”: “application/json”,
“Api-Key”: apiKey,
“Api-Username”: params.api_username || “system”
},
body: JSON.stringify(requestBody)
});
if (response.status >= 200 && response.status < 300) {
return {
success: true,
topic_id: params.topic_id,
category_id: params.category_id,
response: JSON.parse(response.body)
};
} else {
return {
error: `Failed to update topic category. Status: ${response.status}`,
details: response.body
};
}
} catch (error) {
return {
error: “An error occurred while updating the topic category”,
details: error.toString()
};
}
}
function details() {
return “Categorizes a topic by moving it to a specified category”;
}