Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading System Purposes from JSON file, overriding default data.ts va… #128

Closed
wants to merge 6 commits into from

Conversation

syberkitten
Copy link

Loading System Purposes from JSON file, overriding default data.ts values,
allows to extend without changing sourcecode.
  • Add Teacher and Default system purposes, update API host, and load systemPurposes from JSON file
  • Add .env.* to .gitignore
  • Modify src/data.ts to load systemPurposes from systemPurposes.json
  • Add Teacher and Default system purposes in systemPurposes.json

…lues,

allows to extend without changing sourcecode.
- Add Teacher and Default system purposes, update API host, and load systemPurposes from JSON file
- Add .env.* to .gitignore
- Modify src/data.ts to load systemPurposes from systemPurposes.json
- Add Teacher and Default system purposes in systemPurposes.json
@vercel
Copy link

vercel bot commented Jun 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
big-agi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 9, 2023 0:06am

@syberkitten
Copy link
Author

Hi Guys,
Amazing project!!!

by the way It may be preferred to put the systemPurposes.json inside the env vars section
such as:
OVERRIDE_SYSTEM_PURPOSES="systemPurposes.json"
so that it will be overloaded (extended) only when it exists.

Basically this idea comes from the fact that I'm using BigAGI in tandem with another
project and i want to get the latest features while still extending it
without having to have code collisions.

Ideas are welcome and I'll be glad to assist... )

@enricoros
Copy link
Owner

Thanks @syberkitten, good idea, smart implementation. Do you know whether the loading code runs at build time or runtime, and client or server? that 'require' is dark magic to me :)

@enricoros
Copy link
Owner

Another question @syberkitten: what do you think if we had the current SystemPurposes inside the JSON, with maybe 1-2 as fallback in case the JSON is loaded incorrectly?

This would allow for greater customization, since the current impl wouldn't allow removal, only add/override.

Also, there's an 'invisible' list of IDs in the store-purposes... maybe that should be loaded from a JSON the first time..

@syberkitten
Copy link
Author

syberkitten commented Jun 20, 2023

Thanks for the feedback @enricoros
As to the first question the require('../systemPurposes.json') dark magic is used on the server side during the build process.

When the code is bundled and built, the server will attempt to load the systemPurposes.json file and merge its contents with the SystemPurposes object which should be available on both the server and client sides after the build process.

I will also add the JSON validation and error handling so that if the json is malformed An error will be printed
and only the valid fields will be used.

As to the second question I'll give it a further dive and get back to you :)

@syberkitten
Copy link
Author

syberkitten commented Jun 20, 2023

@enricoros can you please specify which fallback purposes would you have as fallback??

@enricoros
Copy link
Owner

@enricoros can you please specify which fallback purposes would you have as fallback??

Good point, no need for those. Sorry for the lag, I had a few other changes to bring in before this. I've tried and it works.

@enricoros enricoros self-requested a review June 25, 2023 00:01
@DeFiFoFum
Copy link
Contributor

I'm also a fan of being able to drop in agent purposes with a JSON and to be able to back it up easily and share. 🔥

- Updated bpTileSize values in PurposeSelector.tsx
- Imported system-purposes.json in store-purposes.ts
- Updated hiddenPurposeIDs in usePurposeStore function
- Updated title in SystemPurposes object in data.ts
- Updated systemPurposesJson and validatedSystemPurposes in data.ts
@syberkitten
Copy link
Author

syberkitten commented Jul 4, 2023

Ok, I've made final changes to the Pull Request including these features:

  1. Moved the system-purposes.json (now it's called such to be more in par with naming conventions)
    the file is now inside a new folder called 'customization' so not to clutter the root. - other customizations can go there later on such as for branding etc....
  2. @enricoros system-purposes.json now has Settings key, with the hidden purposes IDS which are loaded from the json if they exist otherwise a default value inside store-purposes.ts will be used
  3. As a game I've added another purpose, you heard of DAN? it's now hidden and can be enabled with the normal "Edit" when selecting a purpose. (coming from the system-purposes.json)
  4. I've Enlarged a bit the purpose boxes so that a longer title will fit when editing them, perhaps it needs some more adjustment to look better, I'm not strong on the react layout side, yet....

Let me know if you have other remarks or ideas, looking forward to see this in as I've already started working on more stuff, so next PR is coming soon.... :)

…, added try-catch block to handle file import error, and updated default state and toggleHiddenPurposeId action.
@syberkitten
Copy link
Author

Hi @enricoros and @DeFiFoFum
I've added another fix to make sure that default "hiddenPurposeIDs" work even if the system-purposes.json is missing.

@DeFiFoFum
Copy link
Contributor

Hi @enricoros and @DeFiFoFum I've added another fix to make sure that default "hiddenPurposeIDs" work even if the system-purposes.json is missing.

@syberkitten This looks like a great start, but I would hope that users who are not building the application themselves would be able to upload their own custom configs (and also be able to save and back them up).

@syberkitten
Copy link
Author

Hi @DeFiFoFum
Yes for new users and old, we need to document this feature, so it'll be clear how to change such Personas.
so I will add a section to the readme.md or equivalent section.

Other then this, I wish is to be able to customize both branding as well.
a kind of a "snap in" plugin system that will allow the project be used for different use cases, would be amazing.

Some of the features here (for my use case) are not really needed, but they are "backed"
and make the project more complex to maintain.... I was actually pursuing just a simple chatGPT
client for React JS when I found out about BigAgi.

@enricoros
Copy link
Owner

enricoros commented Jul 24, 2023

@syberkitten I started merging this, but then went down a rabbit hole of trying to make an editing system. So can't merge yet as I wanted.
I'll probably have to restart on this from scratch as I accumulated too much experimental code but your request is quite straightforward.

I started using Zod for type validation, then did an overlay (instead of append) of the purposes, then renamed to personas, then changed the data structure, move to a 'zustand store' for user customization, etc etc.. -- basically, tried to boil the ocean and aren't done yet. I should probably land a minimal version of your patch first, and then restart with the big personas change.

@enricoros
Copy link
Owner

Hi @syberkitten, closing this as will be tracked with a new system of making personas dynamic. #35

@enricoros enricoros closed this Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants