fix: clean up threads persistence and fix assistant update issue

This commit is contained in:
Louis 2025-04-17 21:49:32 +07:00
parent 0bb04e59d3
commit 2b732bc976
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
4 changed files with 28 additions and 28 deletions

View File

@ -465,7 +465,7 @@ pub async fn modify_thread_assistant<R: Runtime>(
{ {
if let Some(index) = assistants if let Some(index) = assistants
.iter() .iter()
.position(|a| a.get("id").and_then(|v| v.as_str()) == Some(assistant_id)) .position(|a| a.get("assistant_id").and_then(|v| v.as_str()) == Some(assistant_id))
{ {
assistants[index] = assistant.clone(); assistants[index] = assistant.clone();
let data = serde_json::to_string_pretty(&thread).map_err(|e| e.to_string())?; let data = serde_json::to_string_pretty(&thread).map_err(|e| e.to_string())?;

View File

@ -232,26 +232,6 @@ const ModelDropdown = ({
stopModel() stopModel()
if (activeThread) { if (activeThread) {
// Change assistand tools based on model support RAG
updateThreadMetadata({
...activeThread,
assistants: [
{
...activeAssistant,
tools: [
{
type: 'retrieval',
enabled: model?.engine === InferenceEngine.cortex,
settings: {
...(activeAssistant.tools &&
activeAssistant.tools[0]?.settings),
},
},
],
},
],
})
const contextLength = model?.settings.ctx_len const contextLength = model?.settings.ctx_len
? Math.min(8192, model?.settings.ctx_len ?? 8192) ? Math.min(8192, model?.settings.ctx_len ?? 8192)
: undefined : undefined
@ -273,11 +253,25 @@ const ModelDropdown = ({
// Update model parameter to the thread file // Update model parameter to the thread file
if (model) if (model)
updateModelParameter(activeThread, { updateModelParameter(
params: modelParams, activeThread,
modelId: model.id, {
engine: model.engine, params: modelParams,
}) modelId: model.id,
engine: model.engine,
},
// Update tools
[
{
type: 'retrieval',
enabled: model?.engine === InferenceEngine.cortex,
settings: {
...(activeAssistant.tools &&
activeAssistant.tools[0]?.settings),
},
},
]
)
} }
}, },
[ [

View File

@ -180,7 +180,7 @@ export const useCreateNewThread = () => {
updateThreadCallback(thread) updateThreadCallback(thread)
if (thread.assistants && thread.assistants?.length > 0) { if (thread.assistants && thread.assistants?.length > 0) {
setActiveAssistant(thread.assistants[0]) setActiveAssistant(thread.assistants[0])
updateAssistantCallback(thread.id, thread.assistants[0]) return updateAssistantCallback(thread.id, thread.assistants[0])
} }
}, },
[ [

View File

@ -1,6 +1,7 @@
import { useCallback } from 'react' import { useCallback } from 'react'
import { import {
AssistantTool,
ConversationalExtension, ConversationalExtension,
ExtensionTypeEnum, ExtensionTypeEnum,
InferenceEngine, InferenceEngine,
@ -51,7 +52,11 @@ export default function useUpdateModelParameters() {
) )
const updateModelParameter = useCallback( const updateModelParameter = useCallback(
async (thread: Thread, settings: UpdateModelParameter) => { async (
thread: Thread,
settings: UpdateModelParameter,
tools?: AssistantTool[]
) => {
if (!activeAssistant) return if (!activeAssistant) return
const toUpdateSettings = processStopWords(settings.params ?? {}) const toUpdateSettings = processStopWords(settings.params ?? {})
@ -70,6 +75,7 @@ export default function useUpdateModelParameters() {
const settingParams = extractModelLoadParams(updatedModelParams) const settingParams = extractModelLoadParams(updatedModelParams)
const assistantInfo = { const assistantInfo = {
...activeAssistant, ...activeAssistant,
tools: tools ?? activeAssistant.tools,
model: { model: {
...activeAssistant?.model, ...activeAssistant?.model,
parameters: runtimeParams, parameters: runtimeParams,