Chat tools
This commit is contained in:
parent
81959ad601
commit
a2684eda63
|
|
@ -409,6 +409,7 @@ namespace Prompt {
|
||||||
return {
|
return {
|
||||||
model: model.id,
|
model: model.id,
|
||||||
messages: applyVars(formattedMessages),
|
messages: applyVars(formattedMessages),
|
||||||
|
tools: Tools.getTools([...Tools.CHAT_ONLY_TOOLS]),
|
||||||
max_tokens: model.top_provider.max_completion_tokens || 2048,
|
max_tokens: model.top_provider.max_completion_tokens || 2048,
|
||||||
banned_tokens: state.bannedTokens,
|
banned_tokens: state.bannedTokens,
|
||||||
...state.generationSettings,
|
...state.generationSettings,
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ export namespace Tools {
|
||||||
|
|
||||||
const tool = <T extends TObject = TObject>(t: Tool<T>): Tool<T> => t;
|
const tool = <T extends TObject = TObject>(t: Tool<T>): Tool<T> => t;
|
||||||
|
|
||||||
const TOOLS: Record<string, Tool> = {
|
const TOOLS = {
|
||||||
'get_character': tool({
|
'get_character': tool({
|
||||||
handler: async (args, appState) => {
|
handler: async (args, appState) => {
|
||||||
if (!appState.currentStory) {
|
if (!appState.currentStory) {
|
||||||
|
|
@ -507,8 +507,13 @@ export namespace Tools {
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getTools(): LLM.Tool[] {
|
export type ToolName = keyof typeof TOOLS;
|
||||||
return Object.entries(TOOLS).map(([key, tool]) => ({
|
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',
|
type: 'function',
|
||||||
function: {
|
function: {
|
||||||
name: key,
|
name: key,
|
||||||
|
|
@ -518,6 +523,8 @@ export namespace Tools {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const CHAT_ONLY_TOOLS = ['generate_image'] as const;
|
||||||
|
|
||||||
function parseArg(arg: unknown): unknown {
|
function parseArg(arg: unknown): unknown {
|
||||||
if (typeof arg !== 'string') return arg;
|
if (typeof arg !== 'string') return arg;
|
||||||
|
|
||||||
|
|
@ -541,6 +548,10 @@ export namespace Tools {
|
||||||
const { function: fn } = toolCall;
|
const { function: fn } = toolCall;
|
||||||
const args = parseArg(fn.arguments);
|
const args = parseArg(fn.arguments);
|
||||||
|
|
||||||
|
if (!isToolName(fn.name)) {
|
||||||
|
return `Unknown tool: ${fn.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
const tool = TOOLS[fn.name];
|
const tool = TOOLS[fn.name];
|
||||||
if (!tool) {
|
if (!tool) {
|
||||||
return `Unknown tool: ${fn.name}`;
|
return `Unknown tool: ${fn.name}`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue