Action [[Nodes]] can be used to make generic HTTP requests or use predefined [[Actions]] made available in the environment the cannoli is running in. Their color is orange. If you've added the updated cannoli college in the settings, check out an example canvas here: [Cannoli College](obsidian://open?vault=cannoli-test&file=Cannoli%20College%2F3.%20Special%20nodes%2F2.%20Action%20nodes.canvas) ![[Pasted image 20240719225448.png]] Any {{variable references}} will be replaced just like in [[AI nodes]] and [[Formatter nodes]] before the action is executed, so you can dynamically inject variables into any of the formats described below. Secrets (edit in the settings) can also be injected this way, allowing you to use actions that require an API key without exposing them on the canvas itself. If the response from an action node is in JSON, you can define the path of the part you want an arrow to pull out by writing it in the arrow label. This makes it easier to pull out just the part of the response you want for each outgoing arrow of an action node. If the outgoing arrow labels can't be resolved to a JSON path, the whole response will be passed along. ## Simple GET requests If the content of an action node is just a URL, the node will make a GET request to that URL, and pass the response to the outgoing arrows as text. ### Example ![[Pasted image 20240719225812.png]] ## HTTP requests If the action node is a JSON object defining an HTTP request, that request will be sent, and the response will be passed to the outgoing arrows as text. You can wrap this object in a JSON code block for ease of editing and viewing. ### Example ![[Pasted image 20240719225858.png]] ```json { "url": "https://api.openai.com/v1/chat/completions", "method": "POST", "headers": { "Content-Type": "application/json", "Authorization": "Bearer {{OPENAI_API_KEY}}" }, "body": { "model": "gpt-4o-mini", "messages": [ { "role": "user", "content": "{{prompt}}" } ] } } ``` In this example, we define an an HTTP request in a JSON object which calls the OpenAI API. We inject the prompt, as well as the API key. If you're using Cannoli in Obsidian, your LLM provider API keys are available as secrets already. ## HTTP templates Action nodes can also reference HTTP templates you've set up in your Cannoli environment. In Obsidian, you can do this in Cannoli settings by clicking "+ Template" in the "Action nodes" section. If you have an existing HTTP template, you can simply name it inside of an action node to use it. HTTP templates can also include variable references. ## Actions Actions are javascript/typescript functions that can be called from cannolis. There are built-in actions if you're in Obsidian, but if you're running the Cannoli using the package, you can write any action you'd like. To invoke an action defined in your Cannoli environment, you can simply write the name of the action in the action node. Alternatively, you can wrap the first line of the node in square brackets, and include content and variables below it. The name of the action will be retrieved from the first line, and the rest of the content of the node (after variable replacements) will be used as the first argument of the action. This makes it easier to work with actions where you want to template the first or only argument. ![[Pasted image 20240811224206.png]] In this example, we use the Dalle action to generate an image. We can pass the prompt in with an arrow or template the prompt inside the action node itself, because the "prompt" argument is the first argument in the action's function. Some actions arguments must come from [[Config arrows]], like the "size" one in the right example above. If you aren't sure what arguments an action needs, just put one in a cannoli with no arrows, the error message will give the info. ![[Pasted image 20240719231612.png]] Notice that the "OPENAI_API_KEY" variable isn't given in the successful actions above. That's because actions can have arguments which automatically look in the secrets first, and this API key is provided there.