Skip to content

Publishing a flow directly to LLM Stack

Motivation

The Examples via LaunchPad Studio shows how you can use a no-code tool to build LLM Stack flows. This method is meant for users without development background.

However, there are some limitations with UI tool (some will be addressed in the future):

  • Not all parameters of blocks can be set as inputs. (For example, model_name or temperature of LLM block)
  • Some flows with multiple blocks of the same type might not work well. (For example, multiple LLM blocks)
  • Some blocks are available via APIs but might not be shown in UI tool.

Users with development background can use the LLM Stack APIs directly to overcome these challenges.

Publish Flow API

This API is used to publish a flow using YAML file. Here are the steps to do it.

Option 1: Obtaining Flow YAML File from LaunchPad Studio

To get a flow YAML file from LaunchPad Studio, you can follow the steps below:

  • Open either one of your existing flows or one of the template flows
  • Click More next the 💾 Save button on the left toolbar, followed by Export to YAML export-flow-yaml.png
  • Save the file to your local machine

Option 2: Creating your own Flow YAML file

You can also create your own flow YAML file. For more details about Flow YAML format and some examples, see this guide.

Publish Flow API

Here are some sample codes to publish a flow using the API.

Publish Flow example
# Pre-requisite: Set LLM_STACK_API_KEY environment variable to your API key
curl --location 'https://api.stack.govtext.gov.sg/v1/flows/publish' \
  --header "Authorization: Bearer ${LLM_STACK_API_KEY}" \
  --form 'flow_yaml_file=@"path/to/flow.yml"' \
  --form 'app_metadata="{\"title\": \"Sample Title\", \"description\": \"Sample Description\"}"'
# Pre-requisite: Set LLM_STACK_API_KEY environment variable to your API key
import requests
import os

url = "https://api.stack.govtext.gov.sg/v1/flows/publish"
LLM_STACK_API_KEY = os.environ["LLM_STACK_API_KEY"]

payload = {
    'app_metadata': '{"title": "Sample Title", "description": "Sample Description"}'
}
files = [
    ('flow_yaml_file', ('flow.yml', open('/path/to/flow.yml','rb'), 'application/octet-stream'))
]
headers = {
    'Authorization': f'Bearer {LLM_STACK_API_KEY}'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
// Pre-requisite: Set LLM_STACK_API_KEY environment variable to your API key
var url = "https://api.stack.govtext.gov.sg/v1/flows/publish"
var myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer " + process.env.LLM_STACK_API_KEY);

var formdata = new FormData();
formdata.append("flow_yaml_file", fileInput.files[0], "flow.yml");
formdata.append("app_metadata", "{\"title\": \"Sample Title\", \"description\": \"Sample Description\"}");

var requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: formdata,
  redirect: 'follow'
};

fetch(url, requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));

Note:

  • If flow_id is not defined in the yaml, a new flow id will be returned, to be used in /flows/execute or app.
  • If flow_id is defined in the yaml, it will update an existing published flow. But only the original publisher can update the flow.
  • As a result, ensure to add flow_id in the yaml if you want to update an existing flow.