Skip to content

Instantly share code, notes, and snippets.

@bakks
Created March 8, 2023 19:51
Show Gist options
  • Save bakks/690d931b8588d695738499027e417f22 to your computer and use it in GitHub Desktop.
Save bakks/690d931b8588d695738499027e417f22 to your computer and use it in GitHub Desktop.
Script to generate a chart using butterfish and python
#!/bin/bash
# This script receives a prompt as an argument, the prompt describes a dataset and a chart output to. This script does the folliwng steps:
# 1. Generate a CSV file of data for the chart using butterfish CLI
# 2. Generate a Python script that uses matplotlib to generate the chart using the input CSV using Butterfish CLI
# 3. Run the Python script to generate the chart
prompt=("$@")
echo "Prompt: $prompt"
# Generate CSV file
# The CSV file is generated in the current directory
csvPrompt="The user wants to find data related to this question and output it as a CSV file. Print only the CSV contents, do not add quotes or any other description. The question is: $prompt"
echo "Generating CSV file..."
butterfish prompt -m "text-davinci-003" "$csvPrompt" > data.csv
cat data.csv
# Generate Python script
pyPrompt="The user wants to generate a python script that uses matplotlib to generate a chart using the input CSV to answer a question from the user. The python script should accept a csv file as a command line argument. Print only the Python script, do not add quotes or any other description. The question is: $prompt"
echo "Generating Python script..."
butterfish prompt -m "text-davinci-003" "$pyPrompt" > chart.py
cat chart.py
# Run Python script
echo "Running Python script..."
python3 chart.py data.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment