export const toolsForOpenAI: ChatCompletionTool[] = [ ... { "type": "function", "function": { "name": "j2code_generate_angular_app_for_record_list_in_firestore", "description": "From a business record sample represented in a JSON string, generate a full angular application for maintaining the record list in a Google Firestore Database.", "parameters": { "type": "object", "properties": { "recordJSONString": { "type": "string", "description": "This is a valid JSON string representing a business record, which supports nested objects and arrays." } }, "required": ["recordJSONString"] } } },
/** * Generate a full angular application for maintaining the record list in a Google Firestore Database * @param recordJSONString */ async function _j2code_generate_angular_app_for_record_list_in_firestore(recordJSONString: string): Promise<string> { console.log(`[Tool Execution] generate_angular_application_for_record_list called for record like: "${recordJSONString}"`); try{ const json_string = recordJSONString if(!json_string || json_string.length < 1) return "Error: Empty Record JSON String" const codeGenUrl = 'http://j2code.app/api/angular/firestore'; if (!codeGenUrl) { throw new Error('Code generation API URL is not set'); } // Prepare the request to the code generation API // Note: The API expects a JSON string, so we send it as text/plain. const response = await fetch(codeGenUrl, { method: 'POST', headers: { 'Content-Type': 'text/plain', // Forced to pass json-string as text. //'Content-Type': 'application/json', // json-string will be parsed and req.body will be object. "Output-Length": 'short' }, body: json_string }) if (response){ const responseText = await response.text(); if (!response.ok) { throw new Error(`Server error: ${response.status} - ${responseText}`); } //------------------------------------------------ Response Received const responseData = JSON.parse(responseText) // json, steps, total, files, zip let str = '\n\n' str += responseData.json + "\n\n" str += responseData.steps + "\n\n" str += responseData.files + "\n\n" str += responseData.total + "\n\n" str += responseData.zip + "\n\n" //console.log(`Response from code generation API: ${str}`); // Debugging log return str //------------------------------------------------ } else { return "Error: No Response Returned" } } catch (error) { return "Error: Failed to call API to generate Angular App for Record List. " + error; } // end of try } // end of function