Skip to content

Commit

Permalink
feat: skip tools when all disabled (#1205)
Browse files Browse the repository at this point in the history
* feat: skip tools when all disabled

* feat: ignore directly answer tool on check tools required
  • Loading branch information
Saghen authored May 30, 2024
1 parent 3286583 commit 38872ee
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/server/textGeneration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { generate } from "./generate";
import { mergeAsyncGenerators } from "$lib/utils/mergeAsyncGenerators";
import type { TextGenerationContext } from "./types";
import type { ToolResult } from "$lib/types/Tool";
import { toolHasName } from "../tools/utils";
import directlyAnswer from "../tools/directlyAnswer";

export async function* textGeneration(ctx: TextGenerationContext) {
yield* mergeAsyncGenerators([
Expand Down Expand Up @@ -61,7 +63,8 @@ async function* textGenerationWithoutTitle(

if (model.tools && !conv.assistantId) {
const tools = pickTools(toolsPreference, Boolean(assistant));
toolResults = yield* runTools(ctx, tools, preprompt);
const toolCallsRequired = tools.some((tool) => !toolHasName(directlyAnswer.name, tool));
if (toolCallsRequired) toolResults = yield* runTools(ctx, tools, preprompt);
}

const processedMessages = await preprocessMessages(messages, webSearchResult, convId);
Expand Down

0 comments on commit 38872ee

Please sign in to comment.