Liam Dyer commited on
Commit
572bcbe
·
unverified ·
1 Parent(s): 18d31a6

feat: skip tools when all disabled (#1205)

Browse files

* feat: skip tools when all disabled

* feat: ignore directly answer tool on check tools required

src/lib/server/textGeneration/index.ts CHANGED
@@ -19,6 +19,8 @@ import { generate } from "./generate";
19
  import { mergeAsyncGenerators } from "$lib/utils/mergeAsyncGenerators";
20
  import type { TextGenerationContext } from "./types";
21
  import type { ToolResult } from "$lib/types/Tool";
 
 
22
 
23
  export async function* textGeneration(ctx: TextGenerationContext) {
24
  yield* mergeAsyncGenerators([
@@ -61,7 +63,8 @@ async function* textGenerationWithoutTitle(
61
 
62
  if (model.tools && !conv.assistantId) {
63
  const tools = pickTools(toolsPreference, Boolean(assistant));
64
- toolResults = yield* runTools(ctx, tools, preprompt);
 
65
  }
66
 
67
  const processedMessages = await preprocessMessages(messages, webSearchResult, convId);
 
19
  import { mergeAsyncGenerators } from "$lib/utils/mergeAsyncGenerators";
20
  import type { TextGenerationContext } from "./types";
21
  import type { ToolResult } from "$lib/types/Tool";
22
+ import { toolHasName } from "../tools/utils";
23
+ import directlyAnswer from "../tools/directlyAnswer";
24
 
25
  export async function* textGeneration(ctx: TextGenerationContext) {
26
  yield* mergeAsyncGenerators([
 
63
 
64
  if (model.tools && !conv.assistantId) {
65
  const tools = pickTools(toolsPreference, Boolean(assistant));
66
+ const toolCallsRequired = tools.some((tool) => !toolHasName(directlyAnswer.name, tool));
67
+ if (toolCallsRequired) toolResults = yield* runTools(ctx, tools, preprompt);
68
  }
69
 
70
  const processedMessages = await preprocessMessages(messages, webSearchResult, convId);