unwrap errors in tool calls
This commit is contained in:
parent
3af56906bc
commit
77efd730b7
3 changed files with 14 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
|
||||
import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall";
|
||||
import {
|
||||
acceptToolCall,
|
||||
|
|
@ -23,8 +23,7 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
}
|
||||
|
||||
if (!state.config.defaultModelTitle) {
|
||||
console.error("Cannot call tools, no model selected");
|
||||
return;
|
||||
throw new Error("No model selected");
|
||||
}
|
||||
|
||||
dispatch(setCalling());
|
||||
|
|
@ -40,12 +39,17 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
dispatch(acceptToolCall());
|
||||
|
||||
// Send to the LLM to continue the conversation
|
||||
dispatch(
|
||||
const response = await dispatch(
|
||||
streamResponseAfterToolCall({
|
||||
toolCallId: toolCallState.toolCall.id,
|
||||
toolOutput: contextItems,
|
||||
}),
|
||||
);
|
||||
unwrapResult(response);
|
||||
} else {
|
||||
throw new Error(
|
||||
`Failed to call tool ${toolCallState.toolCall.function.name}: ${result.error}`,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit";
|
||||
import { ChatMessage, PromptLog } from "core";
|
||||
import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall";
|
||||
import { selectDefaultModel } from "../slices/configSlice";
|
||||
|
|
@ -70,7 +70,8 @@ export const streamNormalInput = createAsyncThunk<
|
|||
toolSettings[toolCallState.toolCall.function.name] ===
|
||||
"allowedWithoutPermission"
|
||||
) {
|
||||
await dispatch(callTool());
|
||||
const response = await dispatch(callTool());
|
||||
unwrapResult(response);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ export const streamResponseAfterToolCall = createAsyncThunk<
|
|||
const defaultModel = selectDefaultModel(state);
|
||||
|
||||
if (!defaultModel) {
|
||||
console.error("No default model found");
|
||||
return;
|
||||
throw new Error("No model selected");
|
||||
}
|
||||
|
||||
resetStateForNewMessage();
|
||||
|
|
@ -68,7 +67,8 @@ export const streamResponseAfterToolCall = createAsyncThunk<
|
|||
defaultModel.provider,
|
||||
useTools,
|
||||
);
|
||||
unwrapResult(await dispatch(streamNormalInput(messages)));
|
||||
const output = await dispatch(streamNormalInput(messages));
|
||||
unwrapResult(output);
|
||||
}),
|
||||
);
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue