-
Notifications
You must be signed in to change notification settings - Fork 33
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
Added logic for sorting the retry options #344
Conversation
Thanks for breaking this up into separate pull req |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's fix this at the source, so it works for every user of models
, which we get from the useModels()
hook:
chatcraft.org/src/hooks/use-models.tsx
Line 57 in a24f51d
models.sort(); |
If you change the way we do the sort there, it should mean we're good in all UI situations.
Deploying with Cloudflare Pages
|
src/hooks/use-models.tsx
Outdated
@@ -54,7 +54,8 @@ export const ModelsProvider: FC<{ children: ReactNode }> = ({ children }) => { | |||
isFetching.current = true; | |||
try { | |||
const models = await queryModels(apiKey).then((models) => { | |||
models.sort(); | |||
// models.sort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can delete vs. comment-out code
Given that we ultimately want the pretty names to be sorted, let's do that in the hook (i.e., convert the models to ChatCraftModel instances, then sort on the |
src/hooks/use-models.tsx
Outdated
@@ -54,8 +54,7 @@ export const ModelsProvider: FC<{ children: ReactNode }> = ({ children }) => { | |||
isFetching.current = true; | |||
try { | |||
const models = await queryModels(apiKey).then((models) => { | |||
// models.sort(); | |||
models.sort((a, b) => a.localeCompare(b)); | |||
models.sort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't bother sorting here if you're going to sort again later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
src/hooks/use-models.tsx
Outdated
@@ -74,7 +73,7 @@ export const ModelsProvider: FC<{ children: ReactNode }> = ({ children }) => { | |||
}, [settings.apiUrl, settings.apiKey]); | |||
|
|||
const value = { | |||
models: models || defaultModels, | |||
models: models?.sort((a, b) => a.prettyModel.localeCompare(b.prettyModel)) || defaultModels, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this above on line 60 so you cache the result in state vs. doing it for every consumer:
models.sort((a, b) => a.prettyModel.localeCompare(b.prettyModel))
setModels(models);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code change looks good to me. Get some of your colleagues to test the change at the UI level and/or put in some screenshots of it doing what you expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to land. this will be very helpful
Fixes #316