Files
cleveragents-core/examples/make_context.sh

81 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
set -e
set -x
export PYTHONPATH=/app/src
TIMEOUT_DURATION=${TIMEOUT_DURATION:-180}
run_step() {
echo "================================================================"
if ! timeout "${TIMEOUT_DURATION}s" "$@"; then
status=$?
echo "Command failed (exit ${status}): $*"
exit ${status}
fi
}
run_step_with_capture() {
echo "================================================================"
capture_tmpfile=$(mktemp)
tail -n +1 -f "${capture_tmpfile}" &
capture_tail_pid=$!
if ! timeout "${TIMEOUT_DURATION}s" "$@" >"${capture_tmpfile}" 2>&1; then
status=$?
kill "${capture_tail_pid}" 2>/dev/null || true
wait "${capture_tail_pid}" 2>/dev/null || true
echo "Command failed (exit ${status}): $*"
rm -f "${capture_tmpfile}"
exit ${status}
fi
kill "${capture_tail_pid}" 2>/dev/null || true
wait "${capture_tail_pid}" 2>/dev/null || true
RUN_STEP_CAPTURE_OUTPUT=$(cat "${capture_tmpfile}")
rm -f "${capture_tmpfile}"
}
run_step python -m cleveragents context delete --all --yes
run_step python -m cleveragents run -t 0 --unsafe --config examples/scientific_paper_writer.yaml --context "bookmark" -p "Hello"
while IFS= read -r prompt; do
[ -z "${prompt}" ] && continue
run_step python -m cleveragents run -t 0 --unsafe --config examples/scientific_paper_writer.yaml --context "bookmark" -p "${prompt}"
done <<'EOF'
!next
COVID19
20000 words
Scientists
I will not be publishing it
latex
None, no other additional requirements
Suggest something
Lets go with #1
!next
Suggest 5 or more high quality peer-reviewed sources
!next
Add a few numbered subsections for each one of the main sections, afterall we have 20000 words to fill!
!next
EOF
while :; do
for prompt in "Suggest five additional sources specific to this section to the list" "!write" "!proofread" "!accept"; do
if [ "${prompt}" = "!accept" ]; then
run_step_with_capture python -m cleveragents run -t 0 --unsafe --config examples/scientific_paper_writer.yaml --context "bookmark" -p "${prompt}"
case "${RUN_STEP_CAPTURE_OUTPUT}" in
*!next*)
break 2
;;
esac
else
run_step python -m cleveragents run -t 0 --unsafe --config examples/scientific_paper_writer.yaml --context "bookmark" -p "${prompt}"
fi
done
done
run_step rm -rf at_bookmark.json
run_step python -m cleveragents context export bookmark at_bookmark.json
run_step python -m cleveragents run -t 0 --unsafe --config examples/scientific_paper_writer.yaml --load-context at_bookmark.json -p '!next'