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

fix: 4209 - Inconsistent max tokens value persistence #4213

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions web/containers/ModelDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
)

const isModelSupportRagAndTools = useCallback((model: Model) => {
return (

Check warning on line 102 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

102 line is not covered with tests
model?.engine === InferenceEngine.openai ||
isLocalEngine(model?.engine as InferenceEngine)
)
Expand All @@ -110,7 +110,7 @@
configuredModels
.concat(
downloadedModels.filter(
(e) => !configuredModels.some((x) => x.id === e.id)

Check warning on line 113 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

113 line is not covered with tests
)
)
.filter((e) =>
Expand All @@ -120,24 +120,24 @@
if (searchFilter === 'local') {
return isLocalEngine(e.engine)
}
if (searchFilter === 'remote') {
return !isLocalEngine(e.engine)

Check warning on line 124 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

123-124 lines are not covered with tests
}
})
.sort((a, b) => a.name.localeCompare(b.name))

Check warning on line 127 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

127 line is not covered with tests
.sort((a, b) => {
const aInDownloadedModels = downloadedModels.some(
(item) => item.id === a.id

Check warning on line 130 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

129-130 lines are not covered with tests
)
const bInDownloadedModels = downloadedModels.some(
(item) => item.id === b.id

Check warning on line 133 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

132-133 lines are not covered with tests
)
if (aInDownloadedModels && !bInDownloadedModels) {
return -1
} else if (!aInDownloadedModels && bInDownloadedModels) {
return 1

Check warning on line 138 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

135-138 lines are not covered with tests
} else {
return 0

Check warning on line 140 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

140 line is not covered with tests
}
}),
[configuredModels, searchText, searchFilter, downloadedModels]
Expand All @@ -145,7 +145,7 @@

useEffect(() => {
if (open && searchInputRef.current) {
searchInputRef.current.focus()

Check warning on line 148 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

148 line is not covered with tests
}
}, [open])

Expand All @@ -162,9 +162,9 @@

const onClickModelItem = useCallback(
async (modelId: string) => {
const model = downloadedModels.find((m) => m.id === modelId)
setSelectedModel(model)
setOpen(false)

Check warning on line 167 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

165-167 lines are not covered with tests

if (activeThread) {
// Change assistand tools based on model support RAG
Expand All @@ -187,15 +187,19 @@
],
})

const overriddenSettings =
model?.settings.ctx_len && model.settings.ctx_len > 4096
? { ctx_len: 4096 }
: {}
const defaultContextLength = Math.min(
8192,
model?.settings.ctx_len ?? 8192
)
const overriddenParameters = {
ctx_len: Math.min(8192, model?.settings.ctx_len ?? 8192),
max_tokens: defaultContextLength,
}

const modelParams = {
...model?.parameters,
...model?.settings,
...overriddenSettings,
...overriddenParameters,
}

// Update model parameter to the thread state
Expand Down
23 changes: 15 additions & 8 deletions web/hooks/useCreateNewThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,21 @@ export const useCreateNewThread = () => {
enabled: true,
settings: assistant.tools && assistant.tools[0].settings,
}
const overriddenSettings =
defaultModel?.settings.ctx_len && defaultModel.settings.ctx_len > 2048
? { ctx_len: 4096 }
: {}

const overriddenParameters = defaultModel?.parameters.max_tokens
? { max_tokens: 4096 }
: {}

// Default context length is 8192
const defaultContextLength = Math.min(
8192,
defaultModel?.settings.ctx_len ?? 8192
)

const overriddenSettings = {
ctx_len: defaultContextLength,
}

// Use ctx length by default
const overriddenParameters = {
max_tokens: defaultContextLength,
}

const createdAt = Date.now()
let instructions: string | undefined = assistant.instructions
Expand Down
Loading