char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
0021a77de
char/aliceai-t5-moe
1import { 2BuiltInTool , 3JsonSchemaType , 4MimeTypeAudio , 5MimeTypeImage , 6ToolCallType 7} from '$lib/enums' ; 8import type { OpenAIToolDefinition } from '$lib/types' ; 9 10export const READ_MEDIA_TOOL_NAME = BuiltInTool . BROWSER_READ_MEDIA ; 11 12// header lines of the tool result, parsed back by the read_media renderer 13export const PREFIX_FILE = 'File: ' ; 14export const PREFIX_SIZE = 'Size: ' ; 15export const PREFIX_MIME = 'MIME: ' ; 16 17/** Byte count of the `Size: ` header line, e.g. `Size: 12345 bytes` -> capture group 1 is `12345`. */ 18export const READ_MEDIA_SIZE_REGEX = new RegExp ( `^ ${ PREFIX_SIZE } \\s*(\\d+)\\s*bytes` ); 19 20/** Image extensions the tool accepts. The server decodes images with stb_image, which has no webp or tiff. */ 21export const READ_MEDIA_IMAGE_MIME :Record < string , string > = { 22gif :MimeTypeImage . GIF , 23jpeg :MimeTypeImage . JPEG , 24jpg :MimeTypeImage . JPEG , 25png :MimeTypeImage . PNG 26} as const ; 27 28/** Audio extensions the tool accepts. The `input_audio` API only takes wav and mp3. */ 29export const READ_MEDIA_AUDIO_MIME :Record < string , string > = { 30mp3 :MimeTypeAudio . MP3_MPEG , 31wav :MimeTypeAudio . WAV 32} as const ; 33 34/** 35* Build the read_media tool definition for the modalities the active model has. 36* At least one of the two flags must be true, otherwise the tool is not offered 37* at all - a model that cannot see or hear has nothing to do with the bytes. 38*/ 39export function buildReadMediaToolDefinition ( 40supportsVision :boolean , 41supportsAudio :boolean 42) :OpenAIToolDefinition { 43const kinds :string [] = []; 44 45if ( supportsVision ) kinds . push ( `images ( ${ Object . keys ( READ_MEDIA_IMAGE_MIME ). join ( ', ' )} )` ); 46 47if ( supportsAudio ) kinds . push ( `audio ( ${ Object . keys ( READ_MEDIA_AUDIO_MIME ). join ( ', ' )} )` ); 48 49return { 50function :{ 51description :`Read a media file and attach it to the conversation so it can be perceived directly. Supports ${ kinds . join ( ' and ' )} .` , 52name :READ_MEDIA_TOOL_NAME , 53parameters :{ 54properties :{ 55path :{ 56description :'Path to the media file' , 57type :JsonSchemaType . STRING 58} 59}, 60required :[ 'path' ], 61type :JsonSchemaType . OBJECT 62} 63}, 64type :ToolCallType . FUNCTION 65}; 66}