@@ -59,31 +59,64 @@ Submit a brief title in the conversation's language, following the parameter des
5959</tool_description>
6060</tools>` ;
6161
62- /**
63- * Parses titles from title functions based on the provided prompt.
64- * @param {string } prompt - The prompt containing the title function.
65- * @returns {string } The parsed title. "New Chat" if no title is found.
66- */
67- function parseTitleFromPrompt ( prompt ) {
68- const titleRegex = / < t i t l e > ( .+ ?) < \/ t i t l e > / ;
69- const titleMatch = prompt . match ( titleRegex ) ;
62+ const genTranslationPrompt = (
63+ translationPrompt ,
64+ ) => `In this environment you have access to a set of tools you can use to translate text.
65+
66+ You may call them like this:
67+ <function_calls>
68+ <invoke>
69+ <tool_name>$TOOL_NAME</tool_name>
70+ <parameters>
71+ <$PARAMETER_NAME>$PARAMETER_VALUE</$PARAMETER_NAME>
72+ ...
73+ </parameters>
74+ </invoke>
75+ </function_calls>
7076
71- if ( titleMatch && titleMatch [ 1 ] ) {
72- const title = titleMatch [ 1 ] . trim ( ) ;
77+ Here are the tools available:
78+ <tools>
79+ <tool_description>
80+ <tool_name>submit_translation</tool_name>
81+ <description>
82+ Submit a translation in the target language, following the parameter description and its language closely.
83+ </description>
84+ <parameters>
85+ <parameter>
86+ <name>translation</name>
87+ <type>string</type>
88+ <description>${ translationPrompt }
89+ ONLY include the generated translation without quotations, nor its related key</description>
90+ </parameter>
91+ </parameters>
92+ </tool_description>
93+ </tools>` ;
7394
74- // // Capitalize the first letter of each word; Note: unnecessary due to title case prompting
75- // const capitalizedTitle = title.replace(/\b\w/g, (char) => char.toUpperCase());
95+ /**
96+ * Parses specified parameter from the provided prompt.
97+ * @param {string } prompt - The prompt containing the desired parameter.
98+ * @param {string } paramName - The name of the parameter to extract.
99+ * @returns {string } The parsed parameter's value or a default value if not found.
100+ */
101+ function parseParamFromPrompt ( prompt , paramName ) {
102+ const paramRegex = new RegExp ( `<${ paramName } >([\\s\\S]+?)</${ paramName } >` ) ;
103+ const paramMatch = prompt . match ( paramRegex ) ;
76104
77- return title ;
105+ if ( paramMatch && paramMatch [ 1 ] ) {
106+ return paramMatch [ 1 ] . trim ( ) ;
78107 }
79108
80- return 'New Chat' ;
109+ if ( prompt && prompt . length ) {
110+ return `NO TOOL INVOCATION: ${ prompt } ` ;
111+ }
112+ return `No ${ paramName } provided` ;
81113}
82114
83115module . exports = {
84116 langPrompt,
85117 titleInstruction,
86118 createTitlePrompt,
87119 titleFunctionPrompt,
88- parseTitleFromPrompt,
120+ parseParamFromPrompt,
121+ genTranslationPrompt,
89122} ;
0 commit comments