#!/bin/bash [ ! -f .env ] || export $(grep -v '^#' .env | xargs) [ ! -f .teagent ] || export $(grep -v '^#' .teagent | xargs) if [ -z "$REPO" ]; then exit 1 fi # Default 5 minute maximum TIMEOUT_MAX="${TIMEOUT_MAX:-300}" SERVER="${OLLAMA_HOST:-http://localhost:11434}" MODEL="${OLLAMA_MODEL:-llama3.2}" echo "${SERVER}" for FILE in agent/ast/*.py; do PROMPT=$(cat << EOF You are an engineer in charge of freshening up old code. For this task, you will be given a source file. Please update documentation as necessary and propose any changes to better suit the code. The code is in Python. To do this task, you will be drafting a PR. Therefore, you will output three pieces: a 'title' for the PR, the 'discussion' of the PR, and the 'code' of the PR. (You may treat any called functions from the histclass package as correctly working functions) File contents: `cat "${FILE}"` EOF ) echo "${PROMPT}" SCHEMA="json" OPTS='{"num_ctx": 8192}' SCHEMA='{"type": "object", "properties": {"code": {"type": "string"}, "title": {"type": "string"}, "discussion": {"type": "string"}}, "required": ["code", "title", "dicussion"]}' CDATA="$(jq -n --arg model "$MODEL" --arg prompt "$PROMPT" --argjson options "$OPTS" --argjson schema "$SCHEMA" \ '{model:$model, prompt:$prompt, options: $options, stream:false, format: $schema}')" echo "${CDATA}" RESPONSE=$(timeout "${TIMEOUT_MAX}" curl -s "$SERVER/api/generate" \ -H "Content-Type: application/json" \ -d "${CDATA}") # '{model:$model, prompt:$prompt, stream:false}')" \ # | jq -r '.response') echo "${RESPONSE}" #echo "${RESPONSE}" | jq -r '.response' | jq echo "${RESPONSE}" | jq -r '.response' | jq -r '.title' echo "${RESPONSE}" | jq -r '.response' | jq -r '.discussion' echo "${RESPONSE}" | jq -r '.response' | jq -r '.code' TITLE="`echo "${RESPONSE}" | jq -r '.response' | jq -r '.title'`" DISCUSSION="`echo "${RESPONSE}" | jq -r '.response' | jq -r '.discussion'`" CODE="`echo "${RESPONSE}" | jq -r '.response' | jq -r '.code'`" SOURCE_FILE="`head -n1 \"${FILE}\"`" SOURCE_FILE="${SOURCE_FILE### Function derived from }" BODY=$(cat << EOF File Source: ${SOURCE_FILE} # Details ${DISCUSSION} # Code \`\`\`python3 ${CODE} \`\`\` EOF ) echo "${BODY}" echo "${TITLE}" tea issues create --title "${TITLE}" --body "${BODY}" --login teagent --repo "cc/HistClass" done