-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jhancock532/add-group-script-and-drawing-club
Add new group script and drawing group
- Loading branch information
Showing
11 changed files
with
194 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "Drawing Club Bristol", | ||
"slug": "drawing-club-bristol", | ||
"description": "Friendly & informal art club! Weekly meets in Bristol city centre (circa 2015). No fees.", | ||
"details": "", | ||
"tags": ["art", "drawing"], | ||
"type": "Regular", | ||
"events": [ | ||
{ | ||
"name": "Weekly Drawing Club", | ||
"details": "", | ||
"time": { | ||
"frequency": "Weekly", | ||
"weekday": "Tuesday", | ||
"start": "Jan 1, 1970 18:00", | ||
"end": "Jan 1, 1970 22:00", | ||
"details": "" | ||
}, | ||
"location": { | ||
"address": "The Robin Hood, 56 Saint Michael's Hill, BS2 8DX", | ||
"latitude": "51.458572", | ||
"longitude": "-2.599590", | ||
"googleMapsLink": "https://maps.app.goo.gl/E2kTQuDEmiaqhtr19" | ||
}, | ||
"cost": { | ||
"sessionPrice": 0, | ||
"details": "No fees" | ||
}, | ||
"booking": { | ||
"required": false | ||
}, | ||
"url": "https://www.eventbrite.co.uk/e/drawing-club-bristol-free-central-tickets-1013863301427" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* eslint-disable no-console */ | ||
import Anthropic from '@anthropic-ai/sdk'; | ||
import fs from 'fs'; | ||
import readline from 'readline'; | ||
import path from 'path'; | ||
import { config } from 'dotenv'; | ||
import { logAnthropicAPICost } from './utils.mjs'; | ||
|
||
config(); | ||
|
||
const anthropic = new Anthropic({ | ||
apiKey: process.env.ANTHROPIC_API_KEY, | ||
}); | ||
|
||
// Array of representative groups to use as examples for the AI | ||
const EXAMPLE_GROUP_SLUGS = [ | ||
'chance-and-counters', | ||
'girls-who-walk-bristol', | ||
'rebel-book-club', | ||
'super-miner-battle-farm', | ||
'ride-bristol', | ||
]; | ||
|
||
const rl = readline.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
async function loadExampleGroups() { | ||
const exampleGroups = []; | ||
for (const slug of EXAMPLE_GROUP_SLUGS) { | ||
const groupPath = path.join('data/groups', slug, 'details.json'); | ||
if (fs.existsSync(groupPath)) { | ||
const groupData = fs.readFileSync(groupPath, 'utf-8'); | ||
exampleGroups.push(JSON.parse(groupData)); | ||
} | ||
} | ||
return exampleGroups; | ||
} | ||
|
||
async function generateGroupDetails(groupSlug, userInput, exampleGroups) { | ||
const msg = await anthropic.messages.create({ | ||
model: process.env.ANTHROPIC_MODEL, | ||
max_tokens: 1000, | ||
system: `You are a programming assistant that generates group detail JSON files based on a group slug and optional user input. You return only valid JSON, and make no other comments. Use the following example groups as context for how your output should be formatted: \n${JSON.stringify(exampleGroups)}\n Return a JSON response to the user's input, only including fields that match the above examples.`, | ||
messages: [ | ||
{ | ||
role: 'user', | ||
content: `Create a group details object for the group with the URL slug of "${groupSlug}". Additional information: ${userInput}`, | ||
}, | ||
], | ||
}); | ||
|
||
logAnthropicAPICost(msg.usage, process.env.ANTHROPIC_MODEL); | ||
|
||
return msg.content[0].text; | ||
} | ||
|
||
async function createGroup() { | ||
const groupSlug = await new Promise((resolve) => { | ||
rl.question( | ||
'\x1b[1mEnter the group name as a slug, e.g. "bristol-hot-air-balloonists" :\x1b[0m ', | ||
resolve, | ||
); | ||
}); | ||
|
||
const groupFolderPath = path.join('data/groups', groupSlug); | ||
|
||
if (fs.existsSync(groupFolderPath)) { | ||
console.error( | ||
`The group you've specified "${groupSlug}" already exists.`, | ||
); | ||
rl.close(); | ||
process.exit(1); | ||
} | ||
|
||
const userInput = await new Promise((resolve) => { | ||
rl.question( | ||
'\x1b[1mEnter any additional information for the AI (optional):\x1b[0m ', | ||
resolve, | ||
); | ||
}); | ||
|
||
try { | ||
const exampleGroups = await loadExampleGroups(); | ||
const groupDetails = await generateGroupDetails( | ||
groupSlug, | ||
userInput, | ||
exampleGroups, | ||
); | ||
|
||
const groupDetailsFilePath = path.join(groupFolderPath, 'details.json'); | ||
|
||
fs.mkdirSync(groupFolderPath, { | ||
recursive: true, | ||
}); | ||
|
||
fs.writeFileSync(groupDetailsFilePath, groupDetails); | ||
|
||
console.log(`\n\x1b[32mGroup created successfully!\x1b[0m\n`); | ||
} catch (error) { | ||
console.error('Error creating group:', error); | ||
} | ||
|
||
rl.close(); | ||
} | ||
|
||
createGroup(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.