Skip to content

$fn.callGenerativeAI(param)

This function allows you to asynchronously call text generation, summarization, translation, and other AI-powered processes from actions by integrating with generative AI services. [Async]
The main use case is to pass user input or application data to the AI and obtain generated text or analysis results.
This function was added in v4.0.0.

Supported External Services

The following external services can be integrated:

  • AWS Bedrock
  • Azure OpenAI
  • GCP VertexAI

Arguments

NameTypeDescription
paramobjectParameters to pass to the AI (prompt, options, etc.)

Details of param:

provider property

NameTypeRequiredDefaultDescription
providerstringYesNoneAcceptable values:
1. bedrock
2. azureopenai
3. vertex-ai

model property

NameTypeRequiredDefaultDescription
modelstringYesNoneIdentifier of the AI model supported by the provider

prompt property

NameTypeRequiredDefaultDescription
promptstringYesNonePrompt string to pass to the generative AI

systemPrompt property

NameTypeRequiredDefaultDescription
systemPromptstringNoNoneSystem prompt string for the generative AI

credentialPath property

NameTypeRequiredDefaultDescription
credentialPathstringYesNonePath to the credential file placed in the file manager

Credential File

Provider Content
AWS Bedrock
            
{
    "function": {
        "credentials": {
            "accessKeyId": <ACCESS_KEY_ID (string) *>,
            "secretAccessKey": <SECRET_ACCESS_KEY (string) *>
        }
    }
}
            
        
Azure OpenAI
            
{
    "function":{
        "azureOpenAIApiKey": <API_KEY (string) *>
    }
}
            
        
GCP Vertex AI
            
{
    "function": {
        "authOptions": {
            "credentials": <Service Account Key File JSON (object) *>,
            "projectId": <PROJECT_ID (string) *>
        }
    }
}
            
        

options property

NameTypeRequiredDefaultDescription
optionsobjectNoNoneOptional parameters for the external generative AI

Amazon Bedrock

PropertyDescriptionExample Value
regionAWS region where the Bedrock model is runningus-east-1
topPTop-p sampling percentage for next word selection0.9
temperatureAdjusts output randomness0.7
maxTokensMaximum number of tokens to generate500
stopStrings or tokens to stop output generation[“END”,“\n\n\n”]

Azure OpenAI

PropertyDescriptionExample Value
azureOpenAIApiDeploymentNameDeployment name of the model created in Azure OpenAIgpt-4o-deployment
azureOpenAIApiInstanceNameName of the Azure OpenAI resource to usemy-openai-resource
azureOpenAIApiVersionVersion of Azure OpenAI to use2024-06-01
topPTop-p sampling percentage for next word selection0.9
temperatureAdjusts output randomness (creativity)0.7
maxTokensMaximum number of tokens to generate500
stopStrings or tokens to stop output generation[“END”, “\n\n\n”]
frequencyPenaltyDegree to suppress repetition of the same word0.5
presencePenaltyDegree to encourage introduction of new topics0.3

GCP Vertex AI

PropertyDescriptionExample Value
topPTop-p sampling percentage for next word selection0.9
topKMaximum number of tokens (k) to consider as next word candidates40
temperatureAdjusts output randomness0.7
maxOutputTokensMaximum number of output tokens500
safetySettingsSafety policy settings for output (harmful/inappropriate content)[{ category: “HARM_CATEGORY_DANGEROUS_CONTENT”, threshold: “BLOCK_LOW_AND_ABOVE” }]
stopSequencesStrings or tokens to stop output generation[“END”,“\n\n\n”]

Return Value

TypeDescription
objectReceives the response object from the generative AI service

Example Responses by Provider

AWS Bedrock

{
"success": true,
"message": "AI response generated successfully",
"provider": "bedrock",
"data": {
"success": true,
"result": {
"content": "# The Last Letter\n\nOn a spring day when cherry blossoms danced in the air, she found a letter in the drawer of an old desk. Written in her late grandmother's hand, it was a message to her first love, separated during the war. 'Even if we can't meet, I have always loved you.' As she read the last line, tears streamed down her cheeks.",
"modelId": "global.anthropic.claude-sonnet-4-5-20250929-v1:0",
"stopReason": "end_turn",
"usage": {
"inputTokens": 20,
"outputTokens": 130,
"totalTokens": 150
}
},
"metadata": {
"provider": "bedrock",
"model": "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
}
}
}

Azure OpenAI

{
"success": true,
"message": "AI response generated successfully",
"provider": "azureopenai",
"data": {
"success": true,
"result": {
"content": "Here is the latest information (as of 2024) on India's total population and GDP.\n\n### India's Total Population\n- **About 1.42 billion** (1,420,000,000 people)\n - According to estimates by the UN and World Bank, India became the world's most populous country in 2023, surpassing China.\n\n### India's Gross Domestic Product (GDP)\n- **Nominal GDP: About $3.75 trillion** (2023 estimate, World Bank/IMF data)\n - 5th largest in the world.\n - Per capita GDP is about $2,600.\n\n#### Notes\n- The economic growth rate has remained high at 6-7% in recent years.\n- The service and IT industries drive economic growth, but agriculture still employs many people.\n\nIf you would like more detailed statistics or comparisons with the past, please let us know.",
"modelId": "gpt-4.1",
"stopReason": "stop",
"usage": {
"inputTokens": 23,
"outputTokens": 249,
"totalTokens": 272
}
},
"metadata": {
"provider": "azureopenai",
"model": "gpt-4.1"
}
}
}

GCP Vertex AI

{
"success": true,
"message": "AI response generated successfully",
"provider": "vertex-ai",
"data": {
"success": true,
"result": {
"content": "Here is the latest data on India's total population and GDP.\n\n**Total Population (as of 2023)**\n\n* About 1,428,630,000 (UN estimate)\n\nIndia became the world's most populous country in 2023, surpassing China.\n\n**Gross Domestic Product (GDP) (as of 2022)**\n\n* Nominal GDP: About $3.4686 trillion (World Bank)\n* Real GDP growth rate: 7.2% (FY2022)\n\nIndia is the world's 5th largest economy and has achieved high economic growth in recent years.\n\n**Notes**\n\n* Population figures are estimates and subject to change.\n* GDP figures are published by various organizations and may differ slightly.\n* GDP growth rates vary by year.\n\nFor more detailed or up-to-date information, please refer to the following sources:\n\n* **UN:** [https://www.un.org/en/](https://www.un.org/en/)\n* **World Bank:** [https://www.worldbank.org/](https://www.worldbank.org/)\n* **IMF:** [https://www.imf.org/](https://www.imf.org/)\n\nThese organizations' websites provide the latest statistics and analysis reports on India's economy and population.",
"modelId": "gemini-2.0-flash",
"stopReason": "STOP",
"usage": {
"inputTokens": 13,
"outputTokens": 334,
"totalTokens": 347
}
},
"metadata": {
"provider": "vertex-ai",
"model": "gemini-2.0-flash"
}
}
}

Example

// Example: Requesting text summarization from AI
const response = await $fn.callGenerativeAI({
provider: "bedrock",
model: "us.anthropic.claude-sonnet-4-20250514-v1:0",
prompt: "Please optimize the code.",
systemPrompt: "You are a JavaScript expert.",
credentialPath: "/credentials/bedrock.json",
options: {
region: "us-west-2",
topP: 0.9,
temperature: 0.2,
maxTokens: 512,
stop: ["\n\n\n"],
},
});