directus-extension-ai-sdk-bundle
Version:
A small bundle of Flow Operations which enable interaction with the [OpenAI](https://beta.openai.com/overview) and [Stability](https://stability.ai/) API's.
310 lines (308 loc) • 6.83 kB
JavaScript
import { defineOperationApp } from "@directus/extensions-sdk";
export default defineOperationApp({
id: "chatgpt-operation",
name: "ChatGPT Text Generator",
icon: "textsms",
description: "ChatGPT Text Generator!",
overview: ({ text }) => [
{
label: "Prompt",
text: text,
},
],
options: [
{
field: "system",
name: "System Prompt",
type: "text",
meta: {
width: "full",
interface: "input-multiline",
options: {
trim: true,
},
},
},
{
field: "text",
name: "Prompt",
type: "text",
meta: {
width: "full",
interface: "input-multiline",
options: {
trim: true,
},
},
},
{
field: "engine",
name: "Model",
type: "string",
schema: {
default_value: "gpt-4o",
},
meta: {
width: "full",
interface: "select-dropdown",
options: {
choices: [
{
value: "gpt-4o-mini",
text: "gpt-4o-mini",
},
{
value: "gpt-4o",
text: "gpt-4o",
},
{
value: "gpt-4",
text: "GPT-4",
},
{
value: "gpt-4-32k",
text: "GPT-4-32k",
},
],
},
},
},
{
field: "json_mode",
name: "JSON Mode",
type: "boolean",
meta: {
width: "full",
note: "Always return a JSON object. See the [OpenAI docs on JSON mode](https://platform.openai.com/docs/guides/text-generation/json-mode) for more information.",
},
schema: {
default_value: false,
},
},
{
field: "stream",
name: "Stream",
type: "boolean",
meta: {
width: "full",
note: "Stream the response before returning",
group: "advanced",
},
schema: {
default_value: false,
},
},
{
field: "temperature",
name: "Temperature",
type: "float",
schema: {
default_value: 0.5,
},
meta: {
field: "temperature",
special: null,
interface: "slider",
options: {
minValue: 0,
maxValue: 0,
stepInterval: 0.01,
alwaysShowValue: true,
},
width: "half",
group: "advanced",
},
},
{
field: "max_tokens",
name: "Maximum Length",
type: "integer",
schema: {
default_value: 2048,
},
meta: {
field: "max_tokens",
special: null,
interface: "slider",
options: {
minValue: 1,
maxValue: 4000,
stepInterval: 1,
alwaysShowValue: true,
},
width: "half",
group: "advanced",
},
},
{
field: "top_p",
name: "Top P",
type: "float",
schema: {
default_value: 1,
},
meta: {
field: "top_p",
special: null,
interface: "slider",
options: {
minValue: 0,
maxValue: 1,
stepInterval: 0.01,
alwaysShowValue: true,
},
width: "half",
group: "advanced",
},
},
{
field: "frequency_penalty",
name: "Frequency Penalty",
type: "float",
schema: {
default_value: 0,
},
meta: {
field: "frequency_penalty",
special: null,
interface: "slider",
options: {
minValue: 0,
maxValue: 2,
stepInterval: 0.01,
alwaysShowValue: true,
},
width: "half",
group: "advanced",
},
},
{
field: "presence_penalty",
name: "Presence Penalty",
type: "float",
schema: {
default_value: 0,
},
meta: {
field: "presence_penalty",
special: null,
interface: "slider",
options: {
minValue: 0,
maxValue: 2,
stepInterval: 0.01,
alwaysShowValue: true,
},
width: "half",
group: "advanced",
},
},
{
field: "api_key",
name: "OpenAI API Key",
type: "string",
meta: {
width: "full",
interface: "input",
special: null,
options: {
masked: true,
placeholder: "Use globally set key...",
},
group: "advanced",
},
},
{
field: "base_url",
name: "Base Url",
type: "string",
meta: {
width: "full",
interface: "input",
special: null,
options: {
masked: false,
placeholder: "Override the default base URL for the API",
},
group: "advanced",
},
},
{
field: "amodel",
name: "Model",
type: "string",
meta: {
width: "full",
interface: "input",
special: null,
options: {
masked: false,
placeholder: "If not using ChatGPT",
},
group: "advanced",
},
},
{
field: "advanced",
name: "Advanced Settings",
type: "alias",
meta: {
field: "advanced",
special: ["alias", "no-data", "group"],
interface: "group-detail",
options: {
start: "closed",
},
width: "full",
},
},
{
field: "thread",
name: "Messages",
type: "json",
meta: {
width: "full",
interface: "list",
options: {
fields: [
{
field: "role",
name: "Role",
type: "string",
meta: {
interface: "select-dropdown",
options: {
choices: [
{
text: "System",
value: "system",
},
{
text: "Assistant",
value: "assistant",
},
{
text: "User",
value: "user",
},
],
},
width: "full",
},
},
{
field: "content",
name: "Message",
type: "text",
meta: {
interface: "textarea",
width: "full",
},
},
],
},
note: "Visit the [docs of the AI Writer Operation extension](https://github.com/directus-labs/extension-ai-writer-operation/blob/main/README.md) to learn how to use the Messages field",
},
},
],
});