Migration fix for settings.providers #537
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #536
Code changes:
Part 1 - Changing settings.providers to use name as the key
Files:
src/components/Message/AppMessage/Instructions.tsx
src/components/PreferencesModal.tsx
src/lib/settings.ts
Part 2 - Deserializing settings.providers in
settings.ts
To test this you can set your settings json to the following (replace YOUR_OPENAI_KEY with your key). Using my json you start with two openai providers and two openrouter providers and after navigating to or refreshing chatcraft the deserializer will change it to having two.
Part 3 - Removing unnecessary calls to
getSettings()
in useEffects to decrease how many times our deserializer runsAs discussed with @Amnish04 already, there are some locations where we can call
getSettings()
a lesser amount of times.Files:
src/hooks/use-chat-openai.ts
,src/lib/ai.ts
@Rachit1313 If this PR is merged to main before your PR#535, then I need you to merge the code from main into your branch and then modify your code to use the name as the key instead of the apiUrl as the key whenever you access
settings.providers