summaryrefslogtreecommitdiff
path: root/cleanup_repo.sh
blob: 632757dc75e1e2154e3ed27f4933c89c0438f0f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash

[ ! -f .env ] || export $(grep -v '^#' .env | xargs)
[ ! -f .teagent ] || export $(grep -v '^#' .teagent | xargs)
if [ -z "$REPO" ]; then
  exit 1
fi

SERVER="${OLLAMA_HOST:-http://localhost:11434}"
MODEL="${OLLAMA_MODEL:-llama3.2}"

SOURCE_FILES=`find . -type f -iname \*.py`

for source_file in $SOURCE_FILES; do
  SOURCE=$(<"${source_file}")
  PROMPT=$(cat << EOF
Please clean up the following code, leaving ample documentation.
If the code seems clean already, simply write: DONE
EOF
)
  PROMPT="${PROMPT}
${SOURCE}"
  RESPONSE=$(curl -s "$SERVER/api/generate" \
    -H "Content-Type: application/json" \
    -d "$(jq -n --arg model "$MODEL" --arg prompt "$PROMPT" \
          '{model:$model, prompt:$prompt, stream:false}')" \
          | jq -r '.response')
  if [[ "$RESPONSE" = 'DONE'* ]]; then
    echo > /dev/null
  else
    tea issues create --title "Cleanup ${source_file} (TeAgent)" --body "${RESPONSE}" --login teagent --repo "${REPO}"
  fi
done