API for Advanced Data Analytics

You can prompt a code that provides the solution.

E.g. when you want to read a PDF you can just do this (this code is pretty old, I was using the old text-davinci-003 model here)

#!/usr/bin/env bash
set -x

# when you run the script you give it a filename $1 and ghostscript creates a tiff from the pdf
gs -sDEVICE=tiffg4 -o "output.tiff" "$1"

# and tesseract creates a hocr file
tesseract "output.tiff" "test" -l eng --psm 6 hocr

# and yaml needs less memory
yaml=$(xml2yaml test.hocr)

## Create an key here: https://beta.openai.com/account/api-keys
export OPENAI_API_KEY=''

## AI Model
model=text-davinci-003

# I bet you can make a better prompt - this is just a 15 second thing
request="write a python script that gives me some insights on this data: \n\n ${yaml}"

hocrprompt="${request//$'\n'/ }"
hocrprompt="${hocrprompt//\\n/ }"
hocrprompt="${hocrprompt//\'/ }"
hocrprompt="${hocrprompt//\"/ }"


response=$(curl -s https://api.openai.com/v1/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d "{\"model\": \"$model\", \"prompt\": \"${hocrprompt}\", \"temperature\": 0.5, \"max_tokens\": 1024}")

echo ${hocrprompt} | jq . >> ~/.openai-gpt-3-history
echo ";\n\n\n\n"  >> ~/.openai-gpt-3-history

echo "$response" | jq . >> ~/.openai-gpt-3-history
echo ";\n\n\n\n"  >> ~/.openai-gpt-3-history

echo "$response" | jq -r .choices[0].text

And then you can just run the python script on a secured container…

2 Likes