Skip to content

feat:Improve API Key Error Handling (#428) #82

feat:Improve API Key Error Handling (#428)

feat:Improve API Key Error Handling (#428) #82

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: AIOS Application
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Git Clone Action
# You may pin to the exact commit or the version.
# uses: sudosubin/git-clone-action@8a93ce24d47782e30077508cccacf8a05a891bae
uses: sudosubin/[email protected]
with:
# Repository owner and name. Ex: sudosubin/git-clone-action
repository: agiresearch/Cerebrum
path: Cerebrum
- name: Install cerebrum special edition
run: |
python -m pip install -e Cerebrum/
- name: Download and install Ollama
run: |
curl -fsSL https://ollama.com/install.sh | sh
- name: Pull Ollama models
run: |
ollama pull llama3:8b
- name: Run Ollama serve
run: |
ollama serve 2>&1 | tee ollama-llm.log &
# Wait for ollama to start
for i in {1..30}; do
if curl -s http://localhost:11434/api/version > /dev/null; then
echo "Ollama is running"
break
fi
echo "Waiting for ollama to start... ($i/30)"
sleep 1
done
# Verify ollama is running
curl -s http://localhost:11434/api/version || (echo "Failed to start ollama" && exit 1)
- name: Run AIOS kernel in background
run: |
bash runtime/launch_kernel.sh &>logs &
KERNEL_PID=$!
# Set maximum wait time (20 seconds)
max_wait=20
start_time=$SECONDS
# Dynamically check if the process is running until it succeeds or times out
while true; do
if ! ps -p $KERNEL_PID > /dev/null; then
echo "Kernel process died. Checking logs:"
cat logs
exit 1
fi
if nc -z localhost 8000; then
if curl -s http://localhost:8000/health > /dev/null; then
echo "Kernel successfully started and healthy"
break
fi
fi
# Check if timed out
elapsed=$((SECONDS - start_time))
if [ $elapsed -ge $max_wait ]; then
echo "Timeout after ${max_wait} seconds. Kernel failed to start properly."
cat logs
exit 1
fi
echo "Waiting for kernel to start... (${elapsed}s elapsed)"
sleep 1
done
- name: Run the run-agent code
run: |
# Debug: Show source of code
echo "=== Code Source Info ==="
echo "Source Repo: ${{ github.event.pull_request.head.repo.full_name || github.repository }}"
echo "Source Branch: ${{ github.head_ref || github.ref_name }}"
echo "Commit: $(git rev-parse --short HEAD)"
echo "PR: ${{ github.event.pull_request.html_url || 'Not a PR' }}"
# Run agent and capture exit code
run-agent \
--llm_name llama3:8b \
--llm_backend ollama \
--agent_name_or_path demo_author/demo_agent \
--task "Tell me what is core idea of AIOS" \
--aios_kernel_url http://localhost:8000 \
2>&1 | tee agent.log
# Check for specific error patterns in the log
if grep -q "Failed to initialize client: 500 Server Error" agent.log; then
echo "Error: LLM initialization failed. Please check your API key configuration."
exit 1
fi
# Check if the agent actually completed successfully
if ! grep -q "Final Result:" agent.log; then
echo "Error: Agent did not complete successfully"
exit 1
fi
- name: Upload a Build Artifact
if: always() # Upload logs even if job fails
uses: actions/[email protected]
with:
name: logs
path: |
logs
agent.log
- name: Collect debug information
if: failure()
run: |
echo "=== Kernel Logs ==="
cat logs
echo "=== Environment Variables ==="
env | grep -i api_key || true
echo "=== Process Status ==="
ps aux | grep kernel