Skip to content

Commit

Permalink
Merge pull request #3685 from continuedev/dallin/toolsapalooza
Browse files Browse the repository at this point in the history
Ollama tool support + tool bug fixes
  • Loading branch information
sestinj authored Jan 11, 2025
2 parents 4448c46 + 8293beb commit ce56149
Show file tree
Hide file tree
Showing 14 changed files with 375 additions and 197 deletions.
1 change: 0 additions & 1 deletion core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,6 @@ export interface ExperimentalConfig {
* This is needed to crawl a large number of documentation sites that are dynamically rendered.
*/
useChromiumForDocsCrawling?: boolean;
useTools?: boolean;
modelContextProtocolServers?: MCPOptions[];
}

Expand Down
11 changes: 6 additions & 5 deletions core/llm/autodetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
xWinCoderEditPrompt,
zephyrEditPrompt,
} from "./templates/edit.js";
import { PROVIDER_TOOL_SUPPORT } from "./toolSupport.js";

const PROVIDER_HANDLES_TEMPLATING: string[] = [
"lmstudio",
Expand Down Expand Up @@ -87,11 +88,11 @@ const MODEL_SUPPORTS_IMAGES: string[] = [
];

function modelSupportsTools(modelName: string, provider: string) {
return (
provider === "anthropic" &&
modelName.includes("claude") &&
(modelName.includes("3-5") || modelName.includes("3.5"))
);
const providerSupport = PROVIDER_TOOL_SUPPORT[provider];
if (!providerSupport) {
return false;
}
return providerSupport(modelName) ?? false;
}

function modelSupportsImages(
Expand Down
23 changes: 10 additions & 13 deletions core/llm/constructMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,17 @@ function constructSystemPrompt(
provider: string,
useTools: boolean,
): string | null {
if (
useTools &&
CUSTOM_SYS_MSG_MODEL_FAMILIES.some((family) => model.includes(family))
) {
return SYSTEM_MESSAGE + "\n\n" + TOOL_USE_RULES;
} else if (
CUSTOM_SYS_MSG_MODEL_FAMILIES.some((family) => model.includes(family))
) {
return SYSTEM_MESSAGE;
} else if (useTools && modelSupportsTools(model, provider)) {
return TOOL_USE_RULES;
let systemMessage = "";
if (CUSTOM_SYS_MSG_MODEL_FAMILIES.some((family) => model.includes(family))) {
systemMessage = SYSTEM_MESSAGE;
}

return null;
if (useTools && modelSupportsTools(model, provider)) {
if (systemMessage) {
systemMessage += "\n\n";
}
systemMessage += TOOL_USE_RULES;
}
return systemMessage || null;
}

const CANCELED_TOOL_CALL_MESSAGE =
Expand Down
Loading

0 comments on commit ce56149

Please sign in to comment.