char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Aleksander Grygierui: Refactor Built-In Tools naming (Server/Browser) (#27271)0021a77de

char/aliceai-t5-moe
1.4 KiB38 linesraw
1import { CLI_FLAGS } from './cli-flags.constants';
2import { BuiltInTool, JsonSchemaType, ToolCallType } from '$lib/enums';
3import type { OpenAIToolDefinition } from '$lib/types';
4
5// get_info is served by the server, but the browser falls back to this
6// implementation when the server does not provide it - same wire name.
7export const BROWSER_INFO_TOOL_NAME = BuiltInTool.SERVER_GET_INFO;
8
9/** UA token to OS name, first match wins - Android and iOS UAs also carry the Linux / Mac OS X tokens */
10export const BROWSER_INFO_OS_UA_PATTERNS: readonly [RegExp, string][] = [
11	[/Windows NT/, 'Windows'],
12	[/Android/, 'Android'],
13	[/iPhone|iPad|iPod/, 'iOS'],
14	[/CrOS/, 'ChromeOS'],
15	[/Mac OS X/, 'macOS'],
16	[/Linux/, 'Linux']
17];
18
19export const BROWSER_INFO_OS_UNKNOWN = 'unknown';
20
21/** Sent to the model as the `note` field of the tool result, next to the OS name */
22export const BROWSER_INFO_NOTE = `This environment is browser-only, it cannot read or modify local files, and it cannot run shell commands. To get local file access, tell user to launch llama-server with the ${CLI_FLAGS.AGENT} argument.`;
23
24export function buildBrowserInfoToolDefinition(): OpenAIToolDefinition {
25	return {
26		function: {
27			description:
28				'Get runtime info (OS name), may call when user asks about local files or shell commands',
29			name: BROWSER_INFO_TOOL_NAME,
30			parameters: {
31				properties: {},
32				required: [],
33				type: JsonSchemaType.OBJECT
34			}
35		},
36		type: ToolCallType.FUNCTION
37	};
38}