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

Migration fix for settings.providers #537

Merged
merged 1 commit into from
Mar 28, 2024
Merged

Migration fix for settings.providers #537

merged 1 commit into from
Mar 28, 2024

Conversation

kliu57
Copy link
Collaborator

@kliu57 kliu57 commented Mar 28, 2024

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.

{"model":"openai/gpt-3.5-turbo","temperature":0,"enterBehaviour":"send","countTokens":false,"sidebarVisible":false,"alwaysSendFunctionResult":false,"textToSpeech":{"announceMessages":false,"voice":"alloy"},"providers":{"OpenAI":{"id":"Jnc3KkY4--dQm7KwMWy7Y","name":"OpenAI","apiUrl":"https://api.openai.com/v1","apiKey":"aaaaaaaa"},"OpenRouter.ai":{"id":"XG_lpq_xG-nMIbD1ZRCG-","name":"OpenRouter.ai","apiUrl":"https://openrouter.ai/api/v1","apiKey":"bbbbbbbb"},"https://api.openai.com/v1":{"id":"Jnc3KkY4--dQm7KwMWy7Y","name":"OpenAI","apiUrl":"https://api.openai.com/v1","apiKey":"YOUR_OPENAI_KEY"},"https://openrouter.ai/api/v1":{"id":"XG_lpq_xG-nMIbD1ZRCG-","name":"OpenRouter.ai","apiUrl":"https://openrouter.ai/api/v1","apiKey":"YOUR_OPENROUTER_KEY"}},"currentProvider":{"id":"XG_lpq_xG-nMIbD1ZRCG-","name":"OpenRouter.ai","apiUrl":"https://openrouter.ai/api/v1","apiKey":"YOUR_OPENROUTER_KEY"},"compressionFactor":1,"maxCompressedFileSizeMB":20,"maxImageDimension":2048}

Part 3 - Removing unnecessary calls to getSettings() in useEffects to decrease how many times our deserializer runs

As 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

@kliu57 kliu57 marked this pull request as ready for review March 28, 2024 01:51
@kliu57 kliu57 requested review from Amnish04 and humphd March 28, 2024 01:51
@kliu57
Copy link
Collaborator Author

kliu57 commented Mar 28, 2024

@humphd This is the hotfix I was talking to you about on discord. I would like to get this merged as soon as possible since both I and Rachit will need to do minor code changes to our PRs following this.

@kliu57 kliu57 merged commit 170c115 into main Mar 28, 2024
4 checks passed
@kliu57 kliu57 deleted the issue-536 branch March 28, 2024 20:43
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.

Migration fix for settings.providers
2 participants