- type: clear
- type: ask
param: query
message: 'Please provide query:'
options: null
default: ''
vision:
enabled: false
mode: area
send: true
hint: ''
- type: request
url: api.openai.com/v1/chat/completions
method: post
headers:
Authorization: Bearer YOUR-API-KEY
Content-Type: application/json
body:
model: gpt-4o-search-preview
messages:
- role: user
content:
- type: text
text: '{{query}}'
response_format:
type: text
web_search_options:
search_context_size: high
user_location:
type: approximate
approximate:
country: US
store: true
auth:
enabled: false
username: ''
password: ''
param: response
bodyInvalid: false
headersInvalid: false
- type: say
message: |-
RAW response below
---
{{response}}
- code: >-
// Access the response object passed in via args
const { response, citations } = args;
console.log("Full response:", response);
// Parse the JSON body from the response
const data = response.body;
console.log("Parsed data:", data);
// Extract the assistant's message text
const assistantMessage = data?.choices?.[0]?.message?.content || "No content
found";
console.log("Assistant says:", assistantMessage);
// First try using citations passed via args; if empty, extract from the
response
let urlCitations = citations && citations.length ? citations : (
data?.choices?.[0]?.message?.annotations
?.filter(a => a.type === "url_citation")
.map(a => {
const { start_index, end_index, title, url } = a.url_citation;
return { start_index, end_index, title, url };
}) || []
);
// Function to clean up and normalize Markdown text
const cleanMarkdown = (text) => {
let cleaned = text.trim();
// Normalize multiple blank lines to a single double newline
cleaned = cleaned.replace(/(\n\s*\n)+/g, "\n\n");
return cleaned;
};
const assistantMessageMarkdown = cleanMarkdown(assistantMessage);
// Function to generate a Markdown citation list
const generateCitationList = (citationsArr) => {
if (!citationsArr || citationsArr.length === 0) return '';
return citationsArr
.map(c => `- [${c.title}](${c.url})`)
.join('\n');
};
const citationsMarkdown = generateCitationList(urlCitations);
// Combine the cleaned assistant message with a references section in
Markdown
const finalMarkdown = `${assistantMessageMarkdown}\n\n##
References\n\n${citationsMarkdown}`;
// Generate an HTML version of the response
const finalHtml = `
<div>
<p>${assistantMessage.replace(/\n/g, "<br>")}</p>
<h4>References</h4>
<ul>
${urlCitations.map(c => `<li><a href="${c.url}" target="_blank">${c.title}</a></li>`).join("\n")}
</ul>
</div>
`;
// Return all useful components for further processing or display
return {
fullData: data,
text: assistantMessage,
markdown: finalMarkdown,
citations: urlCitations,
html: finalHtml
};
label: JS_PARSED
type: js
args: response
param: JS_parsed
timeout: 15000
onFailure: ''
- message: |-
JS_parsed.markdown
---
{{JS_parsed.markdown}}
type: say
- message: |-
JS_parsed.citations
---
{{JS_parsed.citations}}
type: say
- message: |-
JS_parsed.html
---
{{JS_parsed.html}}
type: say
This automation command is created by a community member. HARPA AI team does not audit community commands.
Please review the command carefully and only install if you trust the creator.
All rights reserved © HARPA AI TECHNOLOGIES LLC, 2021 — 2025
Designed and engineered in Finland 🇫🇮