Skip to content

Commit

Permalink
feat: npm script for sync
Browse files Browse the repository at this point in the history
  • Loading branch information
emcelroy committed Jan 3, 2025
1 parent c294240 commit c034024
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
13 changes: 8 additions & 5 deletions ai-assistant-settings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@ This is a repository of AI assistant settings values for which we want simple ve

## Directory Structure

Each assistant in the DAVAI project has its own subdirectory containing text files for the specific settings we track. The assistant's Instructions setting value is saved to instructions.txt. Each of the asistant's defined Functions are saved to individual text files in the assistant's `functions` subdirectory.
Each assistant in the DAVAI project has its own subdirectory containing:

- `instructions.txt`: Stores the assistant's Instructions setting value.
- `functions/`: Contains individual text files for each defined function.

## Workflow

Since non-developers can modify settings but are unlikely to update this repository, developers should follow these steps to ensure the repository stays reasonably up-to-date:

1. Before making changes, copy the value(s) from platform.openai.com and commit any changes not already recorded here. (The sync-settings.mts script can be used to automatically copy the values from platform.openai.com via the OpenAI API.)
2. Make your changes on platform.openai.com, then update the corresponding files here and commit the changes.
1. **Before making changes, sync existing values.** Use the `sync:assistant-settings` npm script to fetch the latest settings from platform.openai.com, then commit any changes.
2. **Update settings.** Make changes on platform.openai.com, then update the corresponding files here and commit.

## Scripts

sync-settings.mts in the `scripts` directory can be used to automatically update the assistant settings files with values from platform.openai.com via the OpenAI API.
The `sync:assistant-settings` npm script uses `sync-settings.mts` in the `scripts` directory to fetch and update assistant settings automatically via the OpenAI API.

### Usage:
`node --loader ts-node/esm sync-settings.mts`
`npm run sync:assistant-settings`
10 changes: 7 additions & 3 deletions ai-assistant-settings/scripts/sync-settings.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ import fs from "fs";
import process from "node:process";
import path from "path";
import dotenv from "dotenv";
import { fileURLToPath } from "url";

dotenv.config({ path: "../../.env" });
// Polyfill for __dirname in ESM
const __dirname = path.dirname(fileURLToPath(import.meta.url));

dotenv.config({ path: path.resolve(__dirname, "../../.env") });

const requiredEnvVars = ["REACT_APP_OPENAI_API_KEY", "REACT_APP_OPENAI_BASE_URL"];
const missingEnvVars = requiredEnvVars.filter((key) => !process.env[key]);
Expand Down Expand Up @@ -45,7 +49,7 @@ const getAssistants = async () => {
};

const writeAssistantFiles = (assistant: any) => {
const assistantDir = path.resolve("../assistants", assistant.id);
const assistantDir = path.resolve(__dirname, "../assistants", assistant.id);

fs.mkdirSync(assistantDir, { recursive: true });
fs.writeFileSync(path.join(assistantDir, "instructions.txt"), assistant.instructions);
Expand All @@ -62,7 +66,7 @@ const writeAssistantFiles = (assistant: any) => {

const syncSettings = async () => {
const assistants = await getAssistants();
const assistantsDir = path.resolve("../assistants");
const assistantsDir = path.resolve(__dirname, "../assistants");

fs.rmSync(assistantsDir, { recursive: true, force: true });
fs.mkdirSync(assistantsDir);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"test:cypress:open": "cypress open",
"test:coverage:cypress:open": "cypress open --env coverage=true",
"test:full": "npm-run-all test test:cypress",
"strings:pull": "node bin/pull-strings.js --prefix=DG.plugin --out=./src/strings.json"
"strings:pull": "node bin/pull-strings.js --prefix=DG.plugin --out=./src/strings.json",
"sync:assistant-settings": "node --loader ts-node/esm \"./ai-assistant-settings/scripts/sync-settings.mts\""
},
"repository": {
"type": "git",
Expand Down

0 comments on commit c034024

Please sign in to comment.