import Component from "@glimmer/component"; import { tracked } from "@glimmer/tracking"; import { fn } from "@ember/helper"; import { on } from "@ember/modifier"; import { action } from "@ember/object"; import DButton from "discourse/components/d-button"; import DModal from "discourse/components/d-modal"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; import I18n from "discourse-i18n"; import { jsonToHtml } from "../../lib/utilities"; export default class AiToolTestModal extends Component { @tracked testResult; @tracked isLoading = false; parameterValues = {}; @action updateParameter(name, event) { this.parameterValues[name] = event.target.value; } @action async runTest() { this.isLoading = true; try { const response = await ajax( "/admin/plugins/discourse-ai/ai-tools/test.json", { type: "POST", data: JSON.stringify({ ai_tool: this.args.model.tool, parameters: this.parameterValues, }), contentType: "application/json", } ); this.testResult = jsonToHtml(response.output); } catch (error) { popupAjaxError(error); } finally { this.isLoading = false; } } }