discourse/plugins/discourse-ai/lib/ai_tool_scripts/presets/exchange_rate.js
Keegan George ce2e2788bc
FEATURE: add image generation tools (#35946)
## 🔍 Overview

This update adds the ability to quickly create image generation tools
from common providers in the AI tools menu. Once the image generation
tool is created it can be used in a variety of AI features including AI
bot and illustrate post.

This updates also moves the AI tool preset scripts to their own `js`
files for easier maintainability.

## 📹 Preview
<img width="283" height="277" alt="Screenshot 2025-11-10 at 10 11 14"
src="https://github.com/user-attachments/assets/7196a963-8564-48ad-bb0f-923bc2e55289"
/>

<img width="245" height="375" alt="Screenshot 2025-11-10 at 10 11 19"
src="https://github.com/user-attachments/assets/f9c5d9a7-3ca6-4724-ad2e-ee4cc4a3f69b"
/>


https://github.com/user-attachments/assets/5375af6a-3737-40d0-9bb1-04fb894343d4
2025-11-18 07:47:49 -08:00

33 lines
1,020 B
JavaScript
Vendored

/* eslint-disable no-undef, no-unused-vars */
// note: this script uses the open.er-api.com service, it is only updated
// once every 24 hours, for more up to date rates see: https://www.exchangerate-api.com
function invoke(params) {
const url = `https://open.er-api.com/v6/latest/${params.base_currency}`;
const result = http.get(url);
if (result.status !== 200) {
return { error: "Failed to fetch exchange rates" };
}
const data = JSON.parse(result.body);
const rate = data.rates[params.target_currency];
if (!rate) {
return { error: "Target currency not found" };
}
const rval = {
base_currency: params.base_currency,
target_currency: params.target_currency,
exchange_rate: rate,
last_updated: data.time_last_update_utc,
};
if (params.amount) {
rval.original_amount = params.amount;
rval.converted_amount = params.amount * rate;
}
return rval;
}
function details() {
return "<a href='https://www.exchangerate-api.com'>Rates By Exchange Rate API</a>";
}