1
0
Fork 0

Chat tools

This commit is contained in:
Pabloader 2026-04-14 20:43:46 +00:00
parent 81959ad601
commit a2684eda63
2 changed files with 22 additions and 10 deletions

View File

@ -409,6 +409,7 @@ namespace Prompt {
return {
model: model.id,
messages: applyVars(formattedMessages),
tools: Tools.getTools([...Tools.CHAT_ONLY_TOOLS]),
max_tokens: model.top_provider.max_completion_tokens || 2048,
banned_tokens: state.bannedTokens,
...state.generationSettings,

View File

@ -16,7 +16,7 @@ export namespace Tools {
const tool = <T extends TObject = TObject>(t: Tool<T>): Tool<T> => t;
const TOOLS: Record<string, Tool> = {
const TOOLS = {
'get_character': tool({
handler: async (args, appState) => {
if (!appState.currentStory) {
@ -507,8 +507,13 @@ export namespace Tools {
}),
};
export function getTools(): LLM.Tool[] {
return Object.entries(TOOLS).map(([key, tool]) => ({
export type ToolName = keyof typeof TOOLS;
export const isToolName = (name: string): name is ToolName => name in TOOLS;
export function getTools(only?: ToolName[]): LLM.Tool[] {
return Object.entries(TOOLS)
.filter(([key]) => !only || only.includes(key as ToolName))
.map(([key, tool]) => ({
type: 'function',
function: {
name: key,
@ -518,6 +523,8 @@ export namespace Tools {
}));
}
export const CHAT_ONLY_TOOLS = ['generate_image'] as const;
function parseArg(arg: unknown): unknown {
if (typeof arg !== 'string') return arg;
@ -541,6 +548,10 @@ export namespace Tools {
const { function: fn } = toolCall;
const args = parseArg(fn.arguments);
if (!isToolName(fn.name)) {
return `Unknown tool: ${fn.name}`;
}
const tool = TOOLS[fn.name];
if (!tool) {
return `Unknown tool: ${fn.name}`;