mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 09:03:15 +00:00
refactor: tool calls sent when pending and after completion
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
ConversationState,
|
||||
Attachment,
|
||||
} from './conversationModels';
|
||||
import { ToolCallsType } from './types';
|
||||
|
||||
const initialState: ConversationState = {
|
||||
queries: [],
|
||||
@@ -110,11 +111,11 @@ export const fetchAnswer = createAsyncThunk<
|
||||
query: { sources: data.source ?? [] },
|
||||
}),
|
||||
);
|
||||
} else if (data.type === 'tool_calls') {
|
||||
} else if (data.type === 'tool_call') {
|
||||
dispatch(
|
||||
updateToolCalls({
|
||||
updateToolCall({
|
||||
index: targetIndex,
|
||||
query: { tool_calls: data.tool_calls },
|
||||
tool_call: data.data as ToolCallsType,
|
||||
}),
|
||||
);
|
||||
} else if (data.type === 'error') {
|
||||
@@ -280,12 +281,23 @@ export const conversationSlice = createSlice({
|
||||
state.queries[index].sources!.push(query.sources![0]);
|
||||
}
|
||||
},
|
||||
updateToolCalls(
|
||||
state,
|
||||
action: PayloadAction<{ index: number; query: Partial<Query> }>,
|
||||
) {
|
||||
const { index, query } = action.payload;
|
||||
state.queries[index].tool_calls = query?.tool_calls ?? [];
|
||||
updateToolCall(state, action) {
|
||||
const { index, tool_call } = action.payload;
|
||||
|
||||
if (!state.queries[index].tool_calls) {
|
||||
state.queries[index].tool_calls = [];
|
||||
}
|
||||
|
||||
const existingIndex = state.queries[index].tool_calls.findIndex(
|
||||
(call) => call.call_id === tool_call.call_id,
|
||||
);
|
||||
|
||||
if (existingIndex !== -1) {
|
||||
Object.assign(
|
||||
state.queries[index].tool_calls[existingIndex],
|
||||
tool_call,
|
||||
);
|
||||
} else state.queries[index].tool_calls.push(tool_call);
|
||||
},
|
||||
updateQuery(
|
||||
state,
|
||||
@@ -378,7 +390,7 @@ export const {
|
||||
updateConversationId,
|
||||
updateThought,
|
||||
updateStreamingSource,
|
||||
updateToolCalls,
|
||||
updateToolCall,
|
||||
setConversation,
|
||||
setAttachments,
|
||||
addAttachment,
|
||||
|
||||
@@ -3,5 +3,6 @@ export type ToolCallsType = {
|
||||
action_name: string;
|
||||
call_id: string;
|
||||
arguments: Record<string, any>;
|
||||
result: Record<string, any>;
|
||||
result?: Record<string, any>;
|
||||
status?: 'pending' | 'completed';
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user