Skip to content

Instantly share code, notes, and snippets.

@matthewhand
Created November 9, 2023 18:38
Show Gist options
  • Save matthewhand/5f52327191f56b2873545e3c60527021 to your computer and use it in GitHub Desktop.
Save matthewhand/5f52327191f56b2873545e3c60527021 to your computer and use it in GitHub Desktop.
Update Flowise charts: export JSON, run script to alter models and set fields, then import back. For detailed instructions, see script comments.
#!/bin/bash
# Flowise Chart Update Instructions:
# Step 1: Export the chart from Flowise as a JSON file.
# Step 2: Run this script to update the exported JSON file. Use the command below:
# ./flowise-convert-oai-to-pplx.sh 'path/to/exported/chart.json' > 'path/to/updated/chart.json'
# Step 3: Import the updated JSON file back into Flowise.
# Note: The script updates model names, sets 'frequencyPenalty' to 0.1, and updates 'basepath' to the Perplexity API URL.
# If you intend to use OpenAI Embeddings then you will need to ensure the basepath is not set to the Perplexity API URL for that node.
#!/bin/bash
# Ensure jq is available
if ! command -v jq &> /dev/null; then
echo "jq could not be found, please install jq to use this script."
exit 1
fi
# Check for correct argument usage
if [ "$#" -ne 1 ]; then
echo "Usage: $0 path_to_json_file"
exit 1
fi
FILE="$1"
# Run jq to update the JSON file with model replacements and field updates
jq '
# Apply replacements to all string values
walk(
if type == "string" then
if test("^gpt-.*-turbo$") then
"llama-2-70b-chat"
elif test("^gpt-4") then
"pplx-70b-chat-alpha"
elif test("^gpt-3") then
"llama-2-13b-chat"
else
.
end
else
.
end
) |
# Recursively update frequencyPenalty and basepath wherever they are empty
(.. | .frequencyPenalty? // empty) |= if . == "" then "0.1" else . end |
(.. | .basepath? // empty) |= if . == "" then "https://api.perplexity.ai/" else . end
' "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment