Skip to content

Re-add sync bgl TS files to bgl.json script. #5613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 103 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/a2/bgl/_connector-template.bgl.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
},
"modules": {
"configurator": {
"code": "/**\n * @fileoverview Add a description for your module here.\n */\nimport { err, ok } from \"./a2/utils\";\nimport { createConfigurator } from \"./a2/connector-manager\";\nimport read from \"@read\";\nimport write from \"@write\";\nexport { invoke as default, describe };\nconst CONNECTOR_TITLE = \"{{ title }}\";\nconst { invoke, describe } = createConfigurator({\n title: CONNECTOR_TITLE,\n initialize: async () => {\n return { title: CONNECTOR_TITLE, configuration: {} };\n },\n});\n",
"code": "/**\n * @fileoverview Add a description for your module here.\n */\nimport { createConfigurator } from \"./a2/connector-manager\";\nexport { invoke as default, describe };\nconst CONNECTOR_TITLE = \"{{ title }}\";\nconst { invoke, describe } = createConfigurator({\n title: CONNECTOR_TITLE,\n initialize: async () => {\n return { title: CONNECTOR_TITLE, configuration: {} };\n },\n});\n",
"metadata": {
"title": "configurator",
"source": {
Expand Down
44 changes: 22 additions & 22 deletions packages/a2/bgl/a2.bgl.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/a2/bgl/audio-generator.bgl.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"modules": {
"main": {
"code": "/**\n * @fileoverview Generates audio (tts) output using supplied context.\n */\nimport gemini, { defaultSafetySettings, } from \"./a2/gemini\";\nimport { err, ok, llm, toLLMContent, toLLMContentInline, toLLMContentStored, toTextConcat, joinContent, toText, defaultLLMContent, } from \"./a2/utils\";\nimport { Template } from \"./a2/template\";\nimport { ToolManager } from \"./a2/tool-manager\";\nimport {} from \"./a2/common\";\nimport { ArgumentNameGenerator } from \"./a2/introducer\";\nimport { executeStep, } from \"./a2/step-executor\";\nimport { ListExpander } from \"./a2/lists\";\nconst VoiceMap = {\n \"Male (English)\": \"en-US-male\",\n \"Female (English)\": \"en-US-female\",\n}; // Use 'as const' for stricter type inference\nconst VOICES = Object.keys(VoiceMap);\nexport { invoke as default, describe };\nasync function callAudioGen(prompt, voice) {\n let voiceParam = \"en-US-female\";\n if (voice in VoiceMap) {\n voiceParam = VoiceMap[voice];\n }\n const executionInputs = {};\n const encodedPrompt = btoa(unescape(encodeURIComponent(prompt)));\n executionInputs[\"text_to_speak\"] = {\n chunks: [\n {\n mimetype: \"text/plain\",\n data: encodedPrompt,\n },\n ],\n };\n executionInputs[\"voice_key\"] = {\n chunks: [\n {\n mimetype: \"text/plain\",\n data: btoa(voiceParam),\n },\n ],\n };\n const inputParameters = [\"text_to_speak\"];\n const body = {\n planStep: {\n stepName: \"GenerateAudio\",\n modelApi: \"tts\",\n inputParameters: inputParameters,\n systemPrompt: \"\",\n output: \"generated_speech\",\n },\n execution_inputs: executionInputs,\n };\n const response = await executeStep(body);\n if (!ok(response)) {\n return toLLMContent(\"TTS generation failed: \" + response.$error);\n }\n if (!response.executionOutputs) {\n return toLLMContent(\"TTS returned no audio\");\n }\n let returnVal;\n for (let value of Object.values(response.executionOutputs)) {\n const mimetype = value.chunks[0].mimetype;\n if (mimetype.startsWith(\"audio\")) {\n if (mimetype.endsWith(\"/storedData\")) {\n returnVal = toLLMContentStored(mimetype.replace(\"/storedData\", \"\"), value.chunks[0].data);\n }\n else {\n returnVal = toLLMContentInline(mimetype, value.chunks[0].data);\n }\n }\n }\n if (!returnVal) {\n return toLLMContent(\"Error: No audio returned from backend\");\n }\n console.log(returnVal);\n return returnVal;\n}\nasync function invoke({ context, text, voice, ...params }) {\n context ??= [];\n let instructionText = \"\";\n if (text) {\n instructionText = toText(text).trim();\n }\n const template = new Template(toLLMContent(instructionText));\n const toolManager = new ToolManager(new ArgumentNameGenerator());\n const substituting = await template.substitute(params, async ({ path: url, instance }) => toolManager.addTool(url, instance));\n if (!ok(substituting)) {\n return substituting;\n }\n console.log(\"context\");\n console.log(context);\n console.log(\"instruction\");\n console.log(text);\n console.log(\"substituting\");\n console.log(substituting);\n const results = await new ListExpander(substituting, context).map(async (itemInstruction, itemContext) => {\n const combinedInstruction = toTextConcat(joinContent(toText(itemInstruction), itemContext, false));\n if (!combinedInstruction) {\n return toLLMContent(\"Please provide the text to be converted to speech.\");\n }\n console.log(\"PROMPT: \", combinedInstruction);\n return callAudioGen(combinedInstruction, voice);\n });\n if (!ok(results))\n return results;\n return { context: results };\n}\nasync function describe({ inputs: { text } }) {\n const template = new Template(text);\n return {\n inputSchema: {\n type: \"object\",\n properties: {\n context: {\n type: \"array\",\n items: { type: \"object\", behavior: [\"llm-content\"] },\n title: \"Context in\",\n behavior: [\"main-port\"],\n },\n text: {\n type: \"object\",\n behavior: [\"llm-content\", \"config\", \"hint-preview\"],\n title: \"Text\",\n description: \"Construct the inputs to be spoken with text-to-speech. Use @ to reference previous step outputs.\",\n default: defaultLLMContent(),\n },\n voice: {\n type: \"string\",\n behavior: [\"hint-text\", \"config\"],\n title: \"Voice\",\n icon: \"voice-selection\",\n enum: VOICES,\n description: \"The voice you'd like to generate with\",\n default: \"Female (English)\",\n },\n ...template.schemas(),\n },\n behavior: [\"at-wireable\"],\n ...template.requireds(),\n },\n outputSchema: {\n type: \"object\",\n properties: {\n context: {\n type: \"array\",\n items: { type: \"object\", behavior: [\"llm-content\"] },\n title: \"Context out\",\n behavior: [\"hint-audio\", \"main-port\"],\n },\n },\n additionalProperties: false,\n },\n title: \"Make Speech\",\n metadata: {\n icon: \"generative-audio\",\n tags: [\"quick-access\", \"generative\"],\n order: 3,\n },\n };\n}\n",
"code": "/**\n * @fileoverview Generates audio (tts) output using supplied context.\n */\nimport { ok, toLLMContent, toLLMContentInline, toLLMContentStored, toTextConcat, joinContent, toText, defaultLLMContent, } from \"./a2/utils\";\nimport { Template } from \"./a2/template\";\nimport { ToolManager } from \"./a2/tool-manager\";\nimport { ArgumentNameGenerator } from \"./a2/introducer\";\nimport { executeStep, } from \"./a2/step-executor\";\nimport { ListExpander } from \"./a2/lists\";\nconst VoiceMap = {\n \"Male (English)\": \"en-US-male\",\n \"Female (English)\": \"en-US-female\",\n}; // Use 'as const' for stricter type inference\nconst VOICES = Object.keys(VoiceMap);\nexport { invoke as default, describe };\nasync function callAudioGen(prompt, voice) {\n let voiceParam = \"en-US-female\";\n if (voice in VoiceMap) {\n voiceParam = VoiceMap[voice];\n }\n const executionInputs = {};\n const encodedPrompt = btoa(unescape(encodeURIComponent(prompt)));\n executionInputs[\"text_to_speak\"] = {\n chunks: [\n {\n mimetype: \"text/plain\",\n data: encodedPrompt,\n },\n ],\n };\n executionInputs[\"voice_key\"] = {\n chunks: [\n {\n mimetype: \"text/plain\",\n data: btoa(voiceParam),\n },\n ],\n };\n const inputParameters = [\"text_to_speak\"];\n const body = {\n planStep: {\n stepName: \"GenerateAudio\",\n modelApi: \"tts\",\n inputParameters: inputParameters,\n systemPrompt: \"\",\n output: \"generated_speech\",\n },\n execution_inputs: executionInputs,\n };\n const response = await executeStep(body);\n if (!ok(response)) {\n return toLLMContent(\"TTS generation failed: \" + response.$error);\n }\n if (!response.executionOutputs) {\n return toLLMContent(\"TTS returned no audio\");\n }\n let returnVal;\n for (let value of Object.values(response.executionOutputs)) {\n const mimetype = value.chunks[0].mimetype;\n if (mimetype.startsWith(\"audio\")) {\n if (mimetype.endsWith(\"/storedData\")) {\n returnVal = toLLMContentStored(mimetype.replace(\"/storedData\", \"\"), value.chunks[0].data);\n }\n else {\n returnVal = toLLMContentInline(mimetype, value.chunks[0].data);\n }\n }\n }\n if (!returnVal) {\n return toLLMContent(\"Error: No audio returned from backend\");\n }\n console.log(returnVal);\n return returnVal;\n}\nasync function invoke({ context, text, voice, ...params }) {\n context ??= [];\n let instructionText = \"\";\n if (text) {\n instructionText = toText(text).trim();\n }\n const template = new Template(toLLMContent(instructionText));\n const toolManager = new ToolManager(new ArgumentNameGenerator());\n const substituting = await template.substitute(params, async ({ path: url, instance }) => toolManager.addTool(url, instance));\n if (!ok(substituting)) {\n return substituting;\n }\n console.log(\"context\");\n console.log(context);\n console.log(\"instruction\");\n console.log(text);\n console.log(\"substituting\");\n console.log(substituting);\n const results = await new ListExpander(substituting, context).map(async (itemInstruction, itemContext) => {\n const combinedInstruction = toTextConcat(joinContent(toText(itemInstruction), itemContext, false));\n if (!combinedInstruction) {\n return toLLMContent(\"Please provide the text to be converted to speech.\");\n }\n console.log(\"PROMPT: \", combinedInstruction);\n return callAudioGen(combinedInstruction, voice);\n });\n if (!ok(results))\n return results;\n return { context: results };\n}\nasync function describe({ inputs: { text } }) {\n const template = new Template(text);\n return {\n inputSchema: {\n type: \"object\",\n properties: {\n context: {\n type: \"array\",\n items: { type: \"object\", behavior: [\"llm-content\"] },\n title: \"Context in\",\n behavior: [\"main-port\"],\n },\n text: {\n type: \"object\",\n behavior: [\"llm-content\", \"config\", \"hint-preview\"],\n title: \"Text\",\n description: \"Construct the inputs to be spoken with text-to-speech. Use @ to reference previous step outputs.\",\n default: defaultLLMContent(),\n },\n voice: {\n type: \"string\",\n behavior: [\"hint-text\", \"config\"],\n title: \"Voice\",\n icon: \"voice-selection\",\n enum: VOICES,\n description: \"The voice you'd like to generate with\",\n default: \"Female (English)\",\n },\n ...template.schemas(),\n },\n behavior: [\"at-wireable\"],\n ...template.requireds(),\n },\n outputSchema: {\n type: \"object\",\n properties: {\n context: {\n type: \"array\",\n items: { type: \"object\", behavior: [\"llm-content\"] },\n title: \"Context out\",\n behavior: [\"hint-audio\", \"main-port\"],\n },\n },\n additionalProperties: false,\n },\n title: \"Make Speech\",\n metadata: {\n icon: \"generative-audio\",\n tags: [\"quick-access\", \"generative\"],\n order: 3,\n },\n };\n}\n",
"metadata": {
"title": "main",
"source": {
Expand Down
Loading