@inductiv/node-red-openai-api
Version:
Enhance your Node-RED projects with advanced AI capabilities.
250 lines (238 loc) • 7.78 kB
HTML
<script type="text/javascript">
RED.nodes.registerType("OpenAI API", {
category: "AI",
color: "#B8B1FB",
defaults: {
name: { value: "" },
property: { value: "payload", required: true },
propertyType: { value: "msg" },
service: { value: "", type: "Service Host", required: true },
method: { value: "", required: true },
},
inputs: 1,
outputs: 1,
icon: "icon.png",
label: function () {
return this.name || this.method || "OpenAI API";
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function () {
var selectedMethod = $("#node-input-method option:selected");
if (!selectedMethod.val()) {
var methods = $("#node-input-method").children();
var firstMethod = methods.first();
$("#node-input-method").val(firstMethod.val());
};
// set the default property type value to "payload"
if (this.property === undefined) {
$("#node-input-property").val("payload");
}
$("#node-input-property").typedInput({
default: "msg",
value: "payload",
types: ["msg", "flow", "global"],
typeField: "#node-input-propertyType"
})
}
});
</script>
<script type="text/html" data-template-name="OpenAI API">
<div class="form-row">
<label for="node-input-name"
><i class="fa fa-tag"></i>
<span data-i18n="node-red:common.label.name"></span
></label>
<input
type="text"
id="node-input-name"
data-i18n="[placeholder]node-red:common.label.name"
/>
</div>
<hr />
<div class="form-row">
<label for="node-input-service"
><i class="fa fa-cloud"></i>
<span data-i18n="OpenaiApi.label.serviceHost"></span
></label>
<input type="text" id="node-input-service" />
</div>
<div class="form-row">
<label for="node-input-property"
><i class="fa fa-ellipsis-h"></i>
<span data-i18n="OpenaiApi.label.property"></span
></label>
<input type="text" id="node-input-property">
<input type="hidden" id="node-input-propertyType">
</div>
<div class="form-row">
<label for="node-input-method"
><i class="fa fa-tasks"></i>
<span data-i18n="OpenaiApi.label.method"></span
></label>
<select id="node-input-method">
@@include('./assistants/template.html')
@@include('./audio/template.html')
@@include('./batch/template.html')
@@include('./chat/template.html')
@@include('./container-files/template.html')
@@include('./containers/template.html')
@@include('./embeddings/template.html')
@@include('./files/template.html')
@@include('./fine-tuning/template.html')
@@include('./images/template.html')
@@include('./messages/template.html')
@@include('./models/template.html')
@@include('./moderations/template.html')
@@include('./responses/template.html')
@@include('./runs/template.html')
@@include('./threads/template.html')
@@include('./uploads/template.html')
@@include('./vector-stores/template.html')
@@include('./vector-store-files/template.html')
@@include('./vector-store-file-batches/template.html')
</select>
</div>
</script>
<script type="text/html" data-help-name="OpenAI API">
<p>
OpenAI Platform Services API. Please see the
<a href="https://platform.openai.com/docs/api-reference" target="_blank"
>OpenAI API Reference</a
>
for more details.
</p>
<p><b>Reference</b></p>
@@include('./assistants/help.html')
@@include('./audio/help.html')
@@include('./batch/help.html')
@@include('./chat/help.html')
@@include('./container-files/help.html')
@@include('./containers/help.html')
@@include('./embeddings/help.html')
@@include('./files/help.html')
@@include('./fine-tuning/help.html')
@@include('./images/help.html')
@@include('./messages/help.html')
@@include('./models/help.html')
@@include('./moderations/help.html')
@@include('./responses/help.html')
@@include('./runs/help.html')
@@include('./threads/help.html')
@@include('./uploads/help.html')
@@include('./vector-stores/help.html')
@@include('./vector-store-files/help.html')
@@include('./vector-store-file-batches/help.html')
</script>
<script type="text/javascript">
RED.nodes.registerType("Service Host", {
category: "config",
defaults: {
apiBase: { value: "https://api.openai.com/v1", required: true },
secureApiKeyHeaderOrQueryName: { value: "Authorization" },
organizationId: { value: "" },
secureApiKeyIsQuery: { value: false },
name: { value: "" },
},
credentials: {
secureApiKeyValue: { type: "password" },
temp: { type: "text" },
},
label: function () {
return this.name || this.host;
},
labelStyle: function () {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function () {
$("#node-config-input-secureApiKeyIsQuery-label").hide();
$("#node-config-input-secureApiKeyIsQuery").hide();
var selected = $(
"#node-config-input-secureApiKeyIsQuery option:selected",
);
if (!selected.val()) {
$("#node-config-input-secureApiKeyIsQuery").val(false);
};
},
});
</script>
<script type="text/html" data-template-name="Service Host">
<div class="form-row">
<label id="node-config-input-apiBase-label" for="node-config-input-apiBase"
><i class="fa fa-list"></i>
<span data-i18n="OpenaiApi.label.apiBase"></span
></label>
<input
type="text"
id="node-config-input-apiBase"
placeholder="https://api.openai.com/v1"
/>
</div>
<div class="form-row">
<label
id="node-config-input-secureApiKeyHeaderOrQueryName-label"
for="node-config-input-secureApiKeyHeaderOrQueryName"
><i class="fa fa-list"></i>
<span data-i18n="OpenaiApi.label.header"></span
></label>
<input
type="text"
id="node-config-input-secureApiKeyHeaderOrQueryName"
placeholder=""
/>
</div>
<div class="form-row">
<label
id="node-config-input-secureApiKeyValue-label"
for="node-config-input-secureApiKeyValue"
><i class="fa fa-lock"></i>
<span data-i18n="OpenaiApi.label.apiKey"></span
></label>
<input
type="password"
id="node-config-input-secureApiKeyValue"
placeholder=""
/>
</div>
<div class="form-row">
<label
id="node-config-input-organizationId-label"
for="node-config-input-organizationId"
><i class="fa fa-list"></i>
<span data-i18n="OpenaiApi.label.organizationId"></span
></label>
<input
type="text"
id="node-config-input-organizationId"
placeholder="OpenAI Organization Id"
/>
</div>
<div class="form-row">
<label
id="node-config-input-secureApiKeyIsQuery-label"
for="node-config-input-secureApiKeyIsQuery"
><i class="fa fa-dot-circle-o"></i>
<span data-i18n="OpenaiApi.label.isQuery"></span
></label>
<select id="node-config-input-secureApiKeyIsQuery">
<option value="true">true</option>
<option value="false">false</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-name"
><i class="fa fa-tag"></i>
<span data-i18n="node-red:common.label.name"></span
></label>
<input
type="text"
id="node-config-input-name"
data-i18n="[placeholder]node-red:common.label.name"
/>
</div>
</script>
<script type="text/html" data-help-name="Service Host">
<p><b>Header</b>: Variable name to set API key</p>
<p><b>Value</b>: Value of API key</p>
</script>