Skip to content

Commit

Permalink
Merge branch 'master' into test-add-first-chat-test
Browse files Browse the repository at this point in the history
  • Loading branch information
kinance authored May 27, 2023
2 parents c7168c4 + e05c000 commit 9618530
Show file tree
Hide file tree
Showing 65 changed files with 691 additions and 13,505 deletions.
5 changes: 4 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
## EXIT_KEY - Key to exit AUTO-GPT
# EXIT_KEY=n

## PLAIN_OUTPUT - Enabeling plain output will disable spinner (Default: False)
## Note: Spinner is used to indicate that Auto-GPT is working on something in the background
# PLAIN_OUTPUT=False

## DISABLED_COMMAND_CATEGORIES - The list of categories of commands that are disabled. Each of the below are an option:
## autogpt.commands.analyze_code
## autogpt.commands.audio_text
Expand All @@ -30,7 +34,6 @@
## autogpt.commands.google_search
## autogpt.commands.image_gen
## autogpt.commands.improve_code
## autogpt.commands.twitter
## autogpt.commands.web_selenium
## autogpt.commands.write_tests
## autogpt.app
Expand Down
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Exclude VCR cassettes from stats
tests/**/cassettes/**.y*ml linguist-generated
tests/Auto-GPT-test-cassettes/**/**.y*ml linguist-generated

# Mark documentation as such
docs/**.md linguist-documentation
148 changes: 105 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: Python CI

on:
push:
branches: [ master ]
branches: [ master, ci-test*]
paths-ignore:
- 'tests/Auto-GPT-test-cassettes'
pull_request_target:
branches: [ master, stable ]
branches: [ master, stable , ci-test*]

concurrency:
group: ${{ format('ci-{0}', github.head_ref && format('pr-{0}', github.event.pull_request.number) || github.sha) }}
Expand Down Expand Up @@ -71,6 +73,33 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
token: ${{ secrets.PAT_REVIEW }}

- name: Use cassettes previously sent
if: ${{ github.event_name == 'pull_request_target' }}
run: |
new_branch="${{ github.event.pull_request.user.login }}-${{ github.event.pull_request.head.ref }}"
git config --global user.name "Github Actions"
git config --global user.email "[email protected]"
cd tests/Auto-GPT-test-cassettes
if git ls-remote --exit-code --heads origin $new_branch ; then
git fetch origin $new_branch:$new_branch
git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
git checkout $new_branch
if git merge --no-commit --no-ff ${{ github.event.pull_request.base.ref }}; then
echo "No merge conflict detected. We can use the cassettes previously sent."
else
echo "Merge conflict detected. This means we cannot use the cassettes previously sent, so we will take the cassettes of ${{ github.event.pull_request.base.ref }}."
git merge --abort
git checkout ${{ github.event.pull_request.base.ref }}
fi
else
echo "Branch $new_branch does not exist. We will use the cassettes of ${{ github.event.pull_request.base.ref }}"
fi
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
Expand All @@ -82,7 +111,7 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run unittest tests with coverage
- name: Run pytest tests with coverage
run: |
pytest -n auto --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term
env:
Expand All @@ -94,48 +123,81 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3

- name: Stage Files and Check for New Cassettes
id: stage_files_and_check
- name: Update cassette submodule to push target if push event
if: ${{ github.event_name == 'push' }}
run: |
find tests -type f -name '*.yaml' -print0 | xargs -0 git add
# Check for new cassettes added in PR after the commit
NEW_CASSETTES_ADDED_IN_PR=$(git diff --name-only $(git merge-base ${{ github.event.pull_request.base.sha }} HEAD)..HEAD -- 'tests/**/cassettes/**/*.yaml' | wc -l)
if [[ "$NEW_CASSETTES_ADDED_IN_PR" -gt 0 ]]
then
echo "NEW_CASSETTES_ADDED_IN_PR=true" >> $GITHUB_ENV
else
echo "NEW_CASSETTES_ADDED_IN_PR=false" >> $GITHUB_ENV
fi
- name: Beat new challenges
if: ${{ env.NEW_CASSETTES_ADDED_IN_PR}}
cd tests/Auto-GPT-test-cassettes
current_branch=$(echo ${{ github.ref }} | sed -e "s/refs\/heads\///g")
git fetch origin $current_branch
git config --global user.name "Auto-GPT-Bot"
git config --global user.email "[email protected]"
git add .
# Check if there are any changes
if ! git diff-index --quiet HEAD; then
git commit -m "Auto-update cassettes after Push event"
git pull --rebase origin $current_branch
git push origin HEAD:refs/heads/$current_branch
cd ../..
git add tests/Auto-GPT-test-cassettes
git commit -m "Update submodule reference"
git push origin HEAD:refs/heads/$current_branch
else
echo "No changes to commit"
exit 0
fi
- name: Update cassette submodule to submodule branch if PR event
if: ${{ github.event_name == 'pull_request_target' }}
run: |
echo "This step will run the challenges soon."
new_branch="${{ github.event.pull_request.user.login }}-${{ github.event.pull_request.head.ref }}"
- name: Commit, Config, and Push
id: commit_and_push
run: |
git diff --cached --quiet tests && echo "No changes to commit" && exit 0
find tests -type f -name '*.yaml' -print0 | xargs -0 git add
echo '${{ secrets.PAT_REVIEW }}' | gh auth login --with-token
gh repo set-default ${{ github.repository }}
gh pr checkout ${{ github.event.pull_request.number }}
cd tests/Auto-GPT-test-cassettes
git config --global user.name "Auto-GPT-Bot"
git config --global user.email "[email protected]"
git commit -m "Add new cassettes"
git push origin ${{ github.head_ref }}
TIMESTAMP_COMMIT=$(date +%Y%m%d%H%M%S) # generate a timestamp
echo "TIMESTAMP_COMMIT=$TIMESTAMP_COMMIT" >> $GITHUB_ENV
- name: Inform of auto commit.
if: ${{ env.TIMESTAMP_COMMIT != null }}
uses: thollander/actions-comment-pull-request@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
message: |
We committed some changes to this branch, please run
```
git fetch
git rebase origin/${{ github.head_ref }}
```
before pushing more changes to the remote.
git add .
# Check if there are any changes
if ! git diff-index --quiet HEAD; then
git commit -m "Auto-update cassettes after merging PR #$pr_number"
git push -f origin HEAD:refs/heads/$new_branch
else
echo "No changes to commit"
exit 0
fi
git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} || echo "DIFF_EXISTS=false" >> $GITHUB_ENV
differences=$(git diff origin/$new_branch origin/${{ github.event.pull_request.base.ref }})
if [ -n "$differences" ]; then
echo "DIFF_EXISTS=true" >> $GITHUB_ENV
else
echo "DIFF_EXISTS=false" >> $GITHUB_ENV
fi

- name: Apply or remove prompt change label and comment
if: ${{ github.event_name == 'pull_request_target' }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
TOKEN=${{ secrets.PAT_REVIEW }}
REPO=${{ github.repository }}
if [[ "${{ env.DIFF_EXISTS }}" == "true" ]]; then
echo "Adding label and comment..."
curl -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels \
-d '{"labels":["prompt change"]}'
echo $TOKEN | gh auth login --with-token
gh api repos/$REPO/issues/$PR_NUMBER/comments -X POST -F body="You changed AutoGPT's prompt. The cassettes have been updated and will be merged to the submodule when this Pull Request gets merged."
else
echo "Removing label..."
curl -X DELETE \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/prompt%20change
fi
79 changes: 41 additions & 38 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,44 @@ jobs:
timeout-minutes: 30
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- id: build
name: Build image
uses: docker/build-push-action@v3
with:
build-args: BUILD_TYPE=dev # include pytest
tags: ${{ env.IMAGE_NAME }}
load: true # save to docker images
# cache layers in GitHub Actions cache to speed up builds
cache-from: type=gha,scope=docker-dev
cache-to: type=gha,scope=docker-dev,mode=max

- id: test
name: Run tests
env:
CI: true
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
set +e
test_output=$(
docker run --env CI --env OPENAI_API_KEY --entrypoint python ${{ env.IMAGE_NAME }} -m \
pytest -n auto --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term 2>&1
)
test_failure=$?
echo "$test_output"
cat << $EOF >> $GITHUB_STEP_SUMMARY
# Tests $([ $test_failure = 0 ] && echo '✅' || echo '❌')
\`\`\`
$test_output
\`\`\`
$EOF
- name: Check out repository
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- id: build
name: Build image
uses: docker/build-push-action@v3
with:
build-args: BUILD_TYPE=dev # include pytest
tags: ${{ env.IMAGE_NAME }}
load: true # save to docker images
# cache layers in GitHub Actions cache to speed up builds
cache-from: type=gha,scope=docker-dev
cache-to: type=gha,scope=docker-dev,mode=max

- id: test
name: Run tests
env:
CI: true
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
set +e
test_output=$(
docker run --env CI --env OPENAI_API_KEY --entrypoint python ${{ env.IMAGE_NAME }} -m \
pytest -n auto --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term 2>&1
)
test_failure=$?
echo "$test_output"

cat << $EOF >> $GITHUB_STEP_SUMMARY
# Tests $([ $test_failure = 0 ] && echo '✅' || echo '❌')
\`\`\`
$test_output
\`\`\`
$EOF
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "tests/Auto-GPT-test-cassettes"]
path = tests/Auto-GPT-test-cassettes
url = https://github.com/Significant-Gravitas/Auto-GPT-test-cassettes
branch = master
81 changes: 36 additions & 45 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def signal_handler(signum, frame):
)
break
# Send message to AI, get response
with Spinner("Thinking... "):
with Spinner("Thinking... ", plain_output=cfg.plain_output):
assistant_reply = chat_with_ai(
self,
self.system_prompt,
Expand Down Expand Up @@ -274,6 +274,7 @@ def signal_handler(signum, frame):
command_name,
arguments,
self.config.prompt_generator,
config=cfg,
)
result = f"Command {command_name} returned: " f"{command_result}"

Expand Down
Loading

0 comments on commit 9618530

Please sign in to comment.