Skip to content

Commit

Permalink
Merge pull request #8 from fixie-ai/juberti/fetch
Browse files Browse the repository at this point in the history
Simplify bench.yml
  • Loading branch information
benlower authored Apr 27, 2024
2 parents bd39eca + f1a0e2a commit 10354de
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 54 deletions.
34 changes: 12 additions & 22 deletions .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ name: Update LLM Benchmark Data
on:
schedule:
# Runs at 08:00 UTC every day
- cron: '0 8 * * *'
- cron: "0 8 * * *"
workflow_dispatch:

jobs:
run-benchmarks:
runs-on: ubuntu-latest

steps:
- name: Send Benchmark Requests
run: |
regions=("sea" "iad" "cdg")
for region in "${regions[@]}"
do
curl -X POST 'https://ai-benchmarks.fly.dev/bench?mode=text&max_tokens=20&store=true' -H "fly-prefer-region: $region"
done
- name: Send Benchmark Requests
run: |
regions=("sea" "iad" "cdg")
for region in "${regions[@]}"
do
curl -X POST 'https://ai-benchmarks.fly.dev/bench?mode=text&max_tokens=20&store=true' -H "fly-prefer-region: $region"
done
generate-latest-data:
needs: run-benchmarks
Expand All @@ -34,19 +34,8 @@ jobs:

- name: Get data and update file
run: |
TEMP_FILE="/tmp/$(date +%s).tmp"
OUTPUT="$(node ./utils/GenerateLatestData.js 2>"$TEMP_FILE")"
if [[ -s "$TEMP_FILE" ]]; then
# Read the file contents and echo them so they are captured by the GitHub Actions runner
while read -r line; do
echo "$line"
done < "$TEMP_FILE"
# Delete the file
rm "$TEMP_FILE"
exit 1
elif [ -n "$OUTPUT" ]; then
OUTPUT=$(node ./utils/GenerateLatestData.js) || { echo "Failed to generate latest data."; exit 1; }
if [ -n "$OUTPUT" ]; then
echo "$OUTPUT" > ./website/public/data/latest.json
git config --local user.email "[email protected]"
Expand All @@ -56,6 +45,7 @@ jobs:
git push
else
echo "No data generated, skipping Git operations."
exit 1
fi
build-and-deploy-site:
Expand Down
48 changes: 16 additions & 32 deletions utils/GenerateLatestData.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
// Define the regions to search for files
const regions = ['cdg', 'sea', 'iad'];
const regions = ["cdg", "sea", "iad"];

// Function to fetch data from a given URL
async function fetchData(url) {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error('File not found');
}
return await response.json();
} catch (error) {
console.error(`Error fetching data from ${url}: ${error}`);
return null;
}
const response = await fetch(url);
return await response.json();
}

// Main function to fetch files from all regions and merge them
async function fetchAndMergeFiles(date) {
if (!date) {
console.error('Invalid date provided.');
return;
}

const baseUrl = 'https://storage.googleapis.com/thefastest-data';
const promises = regions.map(region => fetchData(`${baseUrl}/${region}/text/${date}.json`));
const results = await Promise.all(promises);

// Filter out any null results (files not found)
const validResults = results.filter(result => result !== null);

// If no files were found, do not update "latest.json"
if (validResults.length === 0) {
return;
}

// Output the merged data to the console
process.stdout.write(JSON.stringify(validResults, null, 2));
const baseUrl = "https://storage.googleapis.com/thefastest-data";
const promises = regions.map((region) =>
fetchData(`${baseUrl}/${region}/text/${date}.json`)
);
const results = await Promise.all(promises);
process.stdout.write(JSON.stringify(results, null, 2));
}

// Example usage with the current date
const currentDate = new Date().toISOString().split('T')[0]; // Format: YYYY-MM-DD
fetchAndMergeFiles(currentDate);
const currentDate = new Date().toISOString().split("T")[0]; // Format: YYYY-MM-DD
try {
fetchAndMergeFiles(currentDate);
} catch (error) {
console.error(error);
process.exit(1);
}

0 comments on commit 10354de

Please sign in to comment.