From 52764628a641673a19aea38b0a4c8a0f77072841 Mon Sep 17 00:00:00 2001 From: Alfredo Gallardo Date: Fri, 6 Sep 2024 20:53:51 -0400 Subject: [PATCH 1/3] - improve: implement baml to improve summary responses --- .../baml_client/async_client.ts | 92 ++++++++++++++++ .../baml_client/globals.ts | 27 +++++ .../baml_client/index.ts | 22 ++++ .../baml_client/inlinedbaml.ts | 25 +++++ .../baml_client/sync_client.ts | 63 +++++++++++ .../baml_client/tracing.ts | 33 ++++++ .../baml_client/type_builder.ts | 82 ++++++++++++++ .../baml_client/types.ts | 32 ++++++ .../baml_src/generators.baml | 19 ++++ .../baml_src/summarize-youtube-video.baml | 70 ++++++++++++ .../shinkai-tool-youtube-summary/project.json | 6 +- .../src/index.test.ts | 9 +- .../shinkai-tool-youtube-summary/src/index.ts | 101 ++++++++++++------ baml_client/async_client.ts | 92 ++++++++++++++++ baml_client/globals.ts | 27 +++++ baml_client/index.ts | 22 ++++ baml_client/inlinedbaml.ts | 25 +++++ baml_client/sync_client.ts | 63 +++++++++++ baml_client/tracing.ts | 33 ++++++ baml_client/type_builder.ts | 82 ++++++++++++++ baml_client/types.ts | 32 ++++++ package-lock.json | 101 ++++++++++++++++++ package.json | 1 + 23 files changed, 1022 insertions(+), 37 deletions(-) create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/async_client.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/globals.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/index.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/inlinedbaml.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/sync_client.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/tracing.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/type_builder.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_client/types.ts create mode 100644 apps/shinkai-tool-youtube-summary/baml_src/generators.baml create mode 100644 apps/shinkai-tool-youtube-summary/baml_src/summarize-youtube-video.baml create mode 100644 baml_client/async_client.ts create mode 100644 baml_client/globals.ts create mode 100644 baml_client/index.ts create mode 100644 baml_client/inlinedbaml.ts create mode 100644 baml_client/sync_client.ts create mode 100644 baml_client/tracing.ts create mode 100644 baml_client/type_builder.ts create mode 100644 baml_client/types.ts diff --git a/apps/shinkai-tool-youtube-summary/baml_client/async_client.ts b/apps/shinkai-tool-youtube-summary/baml_client/async_client.ts new file mode 100644 index 0000000..46f7a86 --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/async_client.ts @@ -0,0 +1,92 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image, ClientRegistry } from "@boundaryml/baml" +import {YoutubeVideoSummary, YoutubeVideoSummarySection} from "./types" +import TypeBuilder from "./type_builder" +import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME } from "./globals" + +export type RecursivePartialNull = T extends object + ? { + [P in keyof T]?: RecursivePartialNull; + } + : T | null; + +export class BamlAsyncClient { + private runtime: BamlRuntime + private ctx_manager: BamlCtxManager + private stream_client: BamlStreamClient + + constructor(runtime: BamlRuntime, ctx_manager: BamlCtxManager) { + this.runtime = runtime + this.ctx_manager = ctx_manager + this.stream_client = new BamlStreamClient(runtime, ctx_manager) + } + + get stream() { + return this.stream_client + } + + + async SummarizeYoutubeVideo( + youtubeVideoUrl: string,transcript: string, + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } + ): Promise { + const raw = await this.runtime.callFunction( + "SummarizeYoutubeVideo", + { + "youtubeVideoUrl": youtubeVideoUrl,"transcript": transcript + }, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + __baml_options__?.clientRegistry, + ) + return raw.parsed() as YoutubeVideoSummary + } + +} + +class BamlStreamClient { + constructor(private runtime: BamlRuntime, private ctx_manager: BamlCtxManager) {} + + + SummarizeYoutubeVideo( + youtubeVideoUrl: string,transcript: string, + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } + ): BamlStream, YoutubeVideoSummary> { + const raw = this.runtime.streamFunction( + "SummarizeYoutubeVideo", + { + "youtubeVideoUrl": youtubeVideoUrl,"transcript": transcript + }, + undefined, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + __baml_options__?.clientRegistry, + ) + return new BamlStream, YoutubeVideoSummary>( + raw, + (a): a is RecursivePartialNull => a, + (a): a is YoutubeVideoSummary => a, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + ) + } + +} + +export const b = new BamlAsyncClient(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_client/globals.ts b/apps/shinkai-tool-youtube-summary/baml_client/globals.ts new file mode 100644 index 0000000..018ecbe --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/globals.ts @@ -0,0 +1,27 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlCtxManager, BamlRuntime } from '@boundaryml/baml' +import { getBamlFiles } from './inlinedbaml' + + +export const DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME = BamlRuntime.fromFiles( + 'baml_src', + getBamlFiles(), + process.env +) +export const DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX = new BamlCtxManager(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME) \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_client/index.ts b/apps/shinkai-tool-youtube-summary/baml_client/index.ts new file mode 100644 index 0000000..7ce3bc2 --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/index.ts @@ -0,0 +1,22 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ + +export { b } from "./async_client" + +export * from "./types" +export * from "./tracing" \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_client/inlinedbaml.ts b/apps/shinkai-tool-youtube-summary/baml_client/inlinedbaml.ts new file mode 100644 index 0000000..66fd636 --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/inlinedbaml.ts @@ -0,0 +1,25 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +const fileMap = { + + "generators.baml": "\n// This helps use auto generate libraries you can use in the language of\n// your choice. You can have multiple generators if you use multiple languages.\n// Just ensure that the output_dir is different for each generator.\ngenerator target {\n // Valid values: \"python/pydantic\", \"typescript\", \"ruby/sorbet\"\n output_type \"typescript\"\n // Where the generated code will be saved (relative to baml_src/)\n output_dir \"../\"\n // The version of the BAML package you have installed (e.g. same version as your baml-py or @boundaryml/baml).\n // The BAML VSCode extension version should also match this version.\n version \"0.54.2\"\n // Valid values: \"sync\", \"async\"\n // This controls what `b.FunctionName()` will be (sync or async).\n // Regardless of this setting, you can always explicitly call either of the following:\n // - b.sync.FunctionName()\n // - b.async_.FunctionName() (note the underscore to avoid a keyword conflict)\n default_client_mode async\n}", + "summarize-youtube-video.baml": "// Defining a data model.\r\nclass YoutubeVideoSummary {\r\n url string @description(\"URL of the YouTube video\")\r\n briefSummary string @description(\"Brief summary of the content\")\r\n sections YoutubeVideoSummarySection[] @description(\"Key sections along the video\")\r\n}\r\n\r\n// Defining a data model.\r\nclass YoutubeVideoSummarySection {\r\n url string @description(\"URL of the YouTube video for this section\")\r\n offset int @description(\"offset in seconds where this section start in the video\")\r\n title string @description(\"Title of this section\")\r\n keyPoints string[] @description(\"key points of this section\")\r\n}\r\n\r\nclient LlmClient {\r\n provider \"openai-generic\"\r\n options {\r\n model \"gpt-4o\"\r\n }\r\n}\r\n\r\n// Creating a function to summarize a YouTube video\r\nfunction SummarizeYoutubeVideo(youtubeVideoUrl: string, transcript: string) -> YoutubeVideoSummary {\r\n client LlmClient\r\n prompt #\"\r\n {{ _.role(\"system\") }}\r\n According to a transcription of a youtube video (which is in csv separated by ':::'):\r\n \r\n Write a brief summary of the video as instroduction.\r\n Then write more about the content divided in sections (at least 3) along the video.\r\n For every section define between 2-5 key points.\r\n For every section a links referencing where that section start in the video. The format for those links is https://www.youtube.com/watch?v={video_id}&t={offset} where 'offset' is a number and can be obtained from the transcription in csv format to generate the URL\r\n Format the answer using markdown.\r\n\r\n {{ ctx.output_format }}\r\n\r\n\r\n {{ _.role(\"user\") }}\r\n Youtube Video Url:\r\n ---\r\n {{ youtubeVideoUrl }}\r\n ---\r\n\r\n Csv:\r\n ---\r\n {{ transcript }}\r\n ---\r\n \"#\r\n}\r\n\r\n// Testing the function with a sample resume.\r\n// test vaibhav_resume {\r\n// functions [ExtractResume]\r\n// args {\r\n// resume #\"\r\n// Vaibhav Gupta\r\n// vbv@boundaryml.com\r\n\r\n// Experience:\r\n// - Founder at BoundaryML\r\n// - CV Engineer at Google\r\n// - CV Engineer at Microsoft\r\n\r\n// Skills:\r\n// - Rust\r\n// - C++\r\n// \"#\r\n// }\r\n// }\r\n", +} +export const getBamlFiles = () => { + return fileMap; +} \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_client/sync_client.ts b/apps/shinkai-tool-youtube-summary/baml_client/sync_client.ts new file mode 100644 index 0000000..da47feb --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/sync_client.ts @@ -0,0 +1,63 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlRuntime, FunctionResult, BamlCtxManager, BamlSyncStream, Image, ClientRegistry } from "@boundaryml/baml" +import {YoutubeVideoSummary, YoutubeVideoSummarySection} from "./types" +import TypeBuilder from "./type_builder" +import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME } from "./globals" + +export type RecursivePartialNull = T extends object + ? { + [P in keyof T]?: RecursivePartialNull; + } + : T | null; + +export class BamlSyncClient { + private runtime: BamlRuntime + private ctx_manager: BamlCtxManager + + constructor(private runtime: BamlRuntime, private ctx_manager: BamlCtxManager) {} + + /* + * @deprecated NOT IMPLEMENTED as streaming must by async. We + * are not providing an async version as we want to reserve the + * right to provide a sync version in the future. + */ + get stream() { + throw new Error("stream is not available in BamlSyncClient. Use `import { b } from 'baml_client/async_client") + } + + + SummarizeYoutubeVideo( + youtubeVideoUrl: string,transcript: string, + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } + ): YoutubeVideoSummary { + const raw = this.runtime.callFunctionSync( + "SummarizeYoutubeVideo", + { + "youtubeVideoUrl": youtubeVideoUrl,"transcript": transcript + }, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + __baml_options__?.clientRegistry, + ) + return raw.parsed() as YoutubeVideoSummary + } + +} + +export const b = new BamlSyncClient(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_client/tracing.ts b/apps/shinkai-tool-youtube-summary/baml_client/tracing.ts new file mode 100644 index 0000000..df2682e --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/tracing.ts @@ -0,0 +1,33 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlLogEvent } from '@boundaryml/baml'; +import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX } from './globals'; + +const traceAsync = +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.traceFnAsync.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) +const traceSync = +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.traceFnSync.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) +const setTags = +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.upsertTags.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) +const flush = () => { + DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.flush.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX)() +} +const onLogEvent = (callback: undefined | ((event: BamlLogEvent) => void)) => +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.onLogEvent(callback) + +export { traceAsync, traceSync, setTags, flush, onLogEvent } \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_client/type_builder.ts b/apps/shinkai-tool-youtube-summary/baml_client/type_builder.ts new file mode 100644 index 0000000..c42cd18 --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/type_builder.ts @@ -0,0 +1,82 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { FieldType } from '@boundaryml/baml/native' +import { TypeBuilder as _TypeBuilder, EnumBuilder, ClassBuilder } from '@boundaryml/baml/type_builder' + +export default class TypeBuilder { + private tb: _TypeBuilder; + + + + constructor() { + this.tb = new _TypeBuilder({ + classes: new Set([ + "YoutubeVideoSummary","YoutubeVideoSummarySection", + ]), + enums: new Set([ + + ]) + }); + + + } + + __tb() { + return this.tb._tb(); + } + + string(): FieldType { + return this.tb.string() + } + + int(): FieldType { + return this.tb.int() + } + + float(): FieldType { + return this.tb.float() + } + + bool(): FieldType { + return this.tb.bool() + } + + list(type: FieldType): FieldType { + return this.tb.list(type) + } + + null(): FieldType { + return this.tb.null() + } + + map(key: FieldType, value: FieldType): FieldType { + return this.tb.map(key, value) + } + + union(types: FieldType[]): FieldType { + return this.tb.union(types) + } + + addClass(name: Name): ClassBuilder { + return this.tb.addClass(name); + } + + addEnum(name: Name): EnumBuilder { + return this.tb.addEnum(name); + } +} \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_client/types.ts b/apps/shinkai-tool-youtube-summary/baml_client/types.ts new file mode 100644 index 0000000..948f971 --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_client/types.ts @@ -0,0 +1,32 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { Image } from "@boundaryml/baml" +export interface YoutubeVideoSummary { + url: string + briefSummary: string + sections: YoutubeVideoSummarySection[] + +} + +export interface YoutubeVideoSummarySection { + url: string + offset: number + title: string + keyPoints: string[] + +} diff --git a/apps/shinkai-tool-youtube-summary/baml_src/generators.baml b/apps/shinkai-tool-youtube-summary/baml_src/generators.baml new file mode 100644 index 0000000..701c52b --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_src/generators.baml @@ -0,0 +1,19 @@ + +// This helps use auto generate libraries you can use in the language of +// your choice. You can have multiple generators if you use multiple languages. +// Just ensure that the output_dir is different for each generator. +generator target { + // Valid values: "python/pydantic", "typescript", "ruby/sorbet" + output_type "typescript" + // Where the generated code will be saved (relative to baml_src/) + output_dir "../" + // The version of the BAML package you have installed (e.g. same version as your baml-py or @boundaryml/baml). + // The BAML VSCode extension version should also match this version. + version "0.54.2" + // Valid values: "sync", "async" + // This controls what `b.FunctionName()` will be (sync or async). + // Regardless of this setting, you can always explicitly call either of the following: + // - b.sync.FunctionName() + // - b.async_.FunctionName() (note the underscore to avoid a keyword conflict) + default_client_mode async +} \ No newline at end of file diff --git a/apps/shinkai-tool-youtube-summary/baml_src/summarize-youtube-video.baml b/apps/shinkai-tool-youtube-summary/baml_src/summarize-youtube-video.baml new file mode 100644 index 0000000..ed14398 --- /dev/null +++ b/apps/shinkai-tool-youtube-summary/baml_src/summarize-youtube-video.baml @@ -0,0 +1,70 @@ +// Defining a data model. +class YoutubeVideoSummary { + url string @description("URL of the YouTube video") + briefSummary string @description("Brief summary of the content") + sections YoutubeVideoSummarySection[] @description("Key sections along the video") +} + +// Defining a data model. +class YoutubeVideoSummarySection { + url string @description("URL of the YouTube video for this section") + offset int @description("offset in seconds where this section start in the video") + title string @description("Title of this section") + keyPoints string[] @description("key points of this section") +} + +client LlmClient { + provider "openai-generic" + options { + model "gpt-4o" + } +} + +// Creating a function to summarize a YouTube video +function SummarizeYoutubeVideo(youtubeVideoUrl: string, transcript: string) -> YoutubeVideoSummary { + client LlmClient + prompt #" + {{ _.role("system") }} + According to a transcription of a youtube video (which is in csv separated by ':::'): + + Write a brief summary of the video as instroduction. + Then write more about the content divided in sections (at least 3) along the video. + For every section define between 2-5 key points. + For every section a links referencing where that section start in the video. The format for those links is https://www.youtube.com/watch?v={video_id}&t={offset} where 'offset' is a number and can be obtained from the transcription in csv format to generate the URL + Format the answer using markdown. + + {{ ctx.output_format }} + + + {{ _.role("user") }} + Youtube Video Url: + --- + {{ youtubeVideoUrl }} + --- + + Csv: + --- + {{ transcript }} + --- + "# +} + +// Testing the function with a sample resume. +// test vaibhav_resume { +// functions [ExtractResume] +// args { +// resume #" +// Vaibhav Gupta +// vbv@boundaryml.com + +// Experience: +// - Founder at BoundaryML +// - CV Engineer at Google +// - CV Engineer at Microsoft + +// Skills: +// - Rust +// - C++ +// "# +// } +// } diff --git a/apps/shinkai-tool-youtube-summary/project.json b/apps/shinkai-tool-youtube-summary/project.json index 8dbb4fd..51fa24a 100644 --- a/apps/shinkai-tool-youtube-summary/project.json +++ b/apps/shinkai-tool-youtube-summary/project.json @@ -9,7 +9,11 @@ "executor": "nx:run-commands", "defaultConfiguration": "production", "options": { - "command": "npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-youtube-summary/src/index.ts --outputFolder ./dist/apps/shinkai-tool-youtube-summary" + "parallel": false, + "commands": [ + "npx baml-cli generate --from ./apps/shinkai-tool-youtube-summary/baml_src", + "npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-youtube-summary/src/index.ts --outputFolder ./dist/apps/shinkai-tool-youtube-summary" + ] }, "configurations": { "development": {}, diff --git a/apps/shinkai-tool-youtube-summary/src/index.test.ts b/apps/shinkai-tool-youtube-summary/src/index.test.ts index 833625e..ddb6014 100644 --- a/apps/shinkai-tool-youtube-summary/src/index.test.ts +++ b/apps/shinkai-tool-youtube-summary/src/index.test.ts @@ -11,8 +11,10 @@ test('transcript video', async () => { const result = await tool.run({ url: 'https://www.youtube.com/watch?v=SUj34OWkjXU', }); - expect(result.data.summary.length).toBeGreaterThan(0); - console.log(result.data.summary); + + expect(result.data.summary.url).toBeDefined(); + expect(result.data.summary.sections.length).toBeGreaterThan(0); + console.log("summmary", JSON.stringify(result.data.summary, null, 2)); }, 30000); @@ -25,6 +27,7 @@ test('transcript video', async () => { // const result = await tool.run({ // url: 'https://www.youtube.com/watch?v=CQdaQr3EW8g', // }); -// expect(result.data.summary.length).toBeGreaterThan(0); +// expect(result.data.summary.url).toBeDefined(); +// expect(result.data.summary.sections.length).toBeGreaterThan(0); // console.log(result.data.summary); // }, 30000); diff --git a/apps/shinkai-tool-youtube-summary/src/index.ts b/apps/shinkai-tool-youtube-summary/src/index.ts index 221cfec..d938ced 100644 --- a/apps/shinkai-tool-youtube-summary/src/index.ts +++ b/apps/shinkai-tool-youtube-summary/src/index.ts @@ -1,7 +1,8 @@ import { BaseTool, RunResult } from '@shinkai_protocol/shinkai-tools-builder'; import { ToolDefinition } from 'libs/shinkai-tools-builder/src/tool-definition'; import { YoutubeTranscript } from 'youtube-transcript'; -import OpenAI from 'openai'; +import { ClientRegistry } from '@boundaryml/baml'; +import { b, YoutubeVideoSummary } from 'baml_client'; type Config = { apiUrl?: string; @@ -11,7 +12,7 @@ type Config = { type Params = { url: string; }; -type Result = { summary: string }; +type Result = { summary: YoutubeVideoSummary }; export class Tool extends BaseTool { definition: ToolDefinition = { @@ -72,56 +73,90 @@ export class Tool extends BaseTool { type: 'object', properties: { summary: { - type: 'string', + type: 'object', + properties: { + url: { + type: 'string', + description: 'The URL of the YouTube video that was summarized.', + }, + briefSummary: { + type: 'string', + description: 'A concise overview of the entire video content.', + }, + sections: { + type: 'array', + description: + 'An array of sections representing key parts of the video.', + items: { + type: 'object', + properties: { + url: { + type: 'string', + description: + 'The URL of the YouTube video for this section.', + }, + title: { + type: 'string', + description: + 'The title for this section.', + }, + offset: { + type: 'integer', + description: 'The starting time of the section in seconds.', + }, + keyPoints: { + type: 'array', + description: + 'Main points or takeaways from this section of the video.', + items: { + type: 'string', + }, + }, + }, + required: ['offset', 'keyPoints'], + }, + }, + }, + required: ['url', 'briefSummary', 'sections'], description: - 'A markdown-formatted summary of the video content, divided into sections with timestamp links to relevant parts of the video.', + 'An object containing the detailed summary of the YouTube video.', }, }, required: ['summary'], + description: 'The result object containing the video summary.', }, }; async run(params: Params): Promise> { console.log(`transcripting ${params.url}`); + let url = this.config?.apiUrl || 'http://127.0.0.1:11435'; + url = url?.endsWith('/v1') ? url : `${url}/v1`; + + const cr = new ClientRegistry(); + cr.addLlmClient('LlmClient', 'openai', { + base_url: url, + model: this.config?.model || 'llama3.1:8b-instruct-q4_1', + api_key: this.config?.apiKey || '', + }); + cr.setPrimary('LlmClient'); + // Get transcription const transcript = await YoutubeTranscript.fetchTranscript(params.url); - // Send to ollama to build a formatted response - const message: OpenAI.ChatCompletionUserMessageParam = { - role: 'user', - content: ` - According to this transcription of a youtube video (which is in csv separated by ':::'): - - offset;text + const summary = await b.SummarizeYoutubeVideo( + params.url, + ` + offset:::text ${transcript.map((v) => `${Math.floor(v.offset)}:::${v.text}`).join('\n')} - --------------- - - The video URL is ${params.url} - - --------------- - - Write a detailed summary divided in sections along the video. - Format the answer using markdown. - Add markdown links referencing every section using this format https://www.youtube.com/watch?v={video_id}&t={offset} where 'offset' is a number and can be obtained from the transcription in csv format to generate the URL `, - }; + { clientRegistry: cr }, + ); - let url = this.config?.apiUrl || 'http://127.0.0.1:11435'; - url = url?.endsWith('/v1') ? url : `${url}/v1`; - const client = new OpenAI({ - baseURL: url, - apiKey: this.config?.apiKey || '', - }); try { - const response = await client.chat.completions.create({ - model: this.config?.model || 'llama3.1:8b-instruct-q4_1', - messages: [message], - stream: false, - }); return Promise.resolve({ data: { - summary: response.choices[0]?.message?.content || '', + summary, }, }); } catch (error) { diff --git a/baml_client/async_client.ts b/baml_client/async_client.ts new file mode 100644 index 0000000..85068a1 --- /dev/null +++ b/baml_client/async_client.ts @@ -0,0 +1,92 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlRuntime, FunctionResult, BamlCtxManager, BamlStream, Image, ClientRegistry } from "@boundaryml/baml" +import {YoutubeVideoSummary, YoutubeVideoSummarySection} from "./types" +import TypeBuilder from "./type_builder" +import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME } from "./globals" + +export type RecursivePartialNull = T extends object + ? { + [P in keyof T]?: RecursivePartialNull; + } + : T | null; + +export class BamlAsyncClient { + private runtime: BamlRuntime + private ctx_manager: BamlCtxManager + private stream_client: BamlStreamClient + + constructor(runtime: BamlRuntime, ctx_manager: BamlCtxManager) { + this.runtime = runtime + this.ctx_manager = ctx_manager + this.stream_client = new BamlStreamClient(runtime, ctx_manager) + } + + get stream() { + return this.stream_client + } + + + async SummarizeYoutubeVideo( + youtubeVideoUrl: string,transcript: string, + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } + ): Promise { + const raw = await this.runtime.callFunction( + "SummarizeYoutubeVideo", + { + "youtubeVideoUrl": youtubeVideoUrl,"transcript": transcript + }, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + __baml_options__?.clientRegistry, + ) + return raw.parsed() as YoutubeVideoSummary + } + +} + +class BamlStreamClient { + constructor(private runtime: BamlRuntime, private ctx_manager: BamlCtxManager) {} + + + SummarizeYoutubeVideo( + youtubeVideoUrl: string,transcript: string, + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } + ): BamlStream, YoutubeVideoSummary> { + const raw = this.runtime.streamFunction( + "SummarizeYoutubeVideo", + { + "youtubeVideoUrl": youtubeVideoUrl,"transcript": transcript + }, + undefined, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + __baml_options__?.clientRegistry, + ) + return new BamlStream, YoutubeVideoSummary>( + raw, + (a): a is RecursivePartialNull => a, + (a): a is YoutubeVideoSummary => a, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + ) + } + +} + +export const b = new BamlAsyncClient(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) \ No newline at end of file diff --git a/baml_client/globals.ts b/baml_client/globals.ts new file mode 100644 index 0000000..d68658c --- /dev/null +++ b/baml_client/globals.ts @@ -0,0 +1,27 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlCtxManager, BamlRuntime } from '@boundaryml/baml' +import { getBamlFiles } from './inlinedbaml' + + +export const DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME = BamlRuntime.fromFiles( + 'baml_src', + getBamlFiles(), + process.env +) +export const DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX = new BamlCtxManager(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME) \ No newline at end of file diff --git a/baml_client/index.ts b/baml_client/index.ts new file mode 100644 index 0000000..8f19f37 --- /dev/null +++ b/baml_client/index.ts @@ -0,0 +1,22 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ + +export { b } from "./async_client" + +export * from "./types" +export * from "./tracing" \ No newline at end of file diff --git a/baml_client/inlinedbaml.ts b/baml_client/inlinedbaml.ts new file mode 100644 index 0000000..69244eb --- /dev/null +++ b/baml_client/inlinedbaml.ts @@ -0,0 +1,25 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +const fileMap = { + + "../c:\\Users\\agall\\Documents\\GitHub\\shinkai-tools\\apps\\shinkai-tool-youtube-summary\\baml_src\\generators.baml": "\n// This helps use auto generate libraries you can use in the language of\n// your choice. You can have multiple generators if you use multiple languages.\n// Just ensure that the output_dir is different for each generator.\ngenerator target {\n // Valid values: \"python/pydantic\", \"typescript\", \"ruby/sorbet\"\n output_type \"typescript\"\n // Where the generated code will be saved (relative to baml_src/)\n output_dir \"../\"\n // The version of the BAML package you have installed (e.g. same version as your baml-py or @boundaryml/baml).\n // The BAML VSCode extension version should also match this version.\n version \"0.54.2\"\n // Valid values: \"sync\", \"async\"\n // This controls what `b.FunctionName()` will be (sync or async).\n // Regardless of this setting, you can always explicitly call either of the following:\n // - b.sync.FunctionName()\n // - b.async_.FunctionName() (note the underscore to avoid a keyword conflict)\n default_client_mode async\n}", + "../c:\\Users\\agall\\Documents\\GitHub\\shinkai-tools\\apps\\shinkai-tool-youtube-summary\\baml_src\\summarize-youtube-video.baml": "// Defining a data model.\r\nclass YoutubeVideoSummary {\r\n url string @description(\"URL of the YouTube video\")\r\n briefSummary string @description(\"Brief summary of the content\")\r\n sections YoutubeVideoSummarySection[] @description(\"Key sections along the video\")\r\n}\r\n\r\n// Defining a data model.\r\nclass YoutubeVideoSummarySection {\r\n url string @description(\"URL of the YouTube video for this section\")\r\n offset int @description(\"offset in seconds where this section start in the video\")\r\n title string @description(\"Title of this section\")\r\n keyPoints string[] @description(\"key points of this section\")\r\n}\r\n\r\nclient LlmClient {\r\n provider \"openai-generic\"\r\n options {\r\n model \"gpt-4o\"\r\n }\r\n}\r\n\r\n// Creating a function to summarize a YouTube video\r\nfunction SummarizeYoutubeVideo(youtubeVideoUrl: string, transcript: string) -> YoutubeVideoSummary {\r\n client LlmClient\r\n prompt #\"\r\n {{ _.role(\"system\") }}\r\n According to a transcription of a youtube video (which is in csv separated by ':::'):\r\n \r\n Write a brief summary of the video as instroduction.\r\n Then write more about the content divided in sections (at least 3) along the video.\r\n For every section define between 2-5 key points.\r\n For every section a links referencing where that section start in the video. The format for those links is https://www.youtube.com/watch?v={video_id}&t={offset} where 'offset' is a number and can be obtained from the transcription in csv format to generate the URL\r\n Format the answer using markdown.\r\n\r\n {{ ctx.output_format }}\r\n\r\n\r\n {{ _.role(\"user\") }}\r\n Youtube Video Url:\r\n ---\r\n {{ youtubeVideoUrl }}\r\n ---\r\n\r\n Csv:\r\n ---\r\n {{ transcript }}\r\n ---\r\n \"#\r\n}\r\n\r\n// Testing the function with a sample resume.\r\n// test vaibhav_resume {\r\n// functions [ExtractResume]\r\n// args {\r\n// resume #\"\r\n// Vaibhav Gupta\r\n// vbv@boundaryml.com\r\n\r\n// Experience:\r\n// - Founder at BoundaryML\r\n// - CV Engineer at Google\r\n// - CV Engineer at Microsoft\r\n\r\n// Skills:\r\n// - Rust\r\n// - C++\r\n// \"#\r\n// }\r\n// }\r\n", +} +export const getBamlFiles = () => { + return fileMap; +} \ No newline at end of file diff --git a/baml_client/sync_client.ts b/baml_client/sync_client.ts new file mode 100644 index 0000000..8ec6097 --- /dev/null +++ b/baml_client/sync_client.ts @@ -0,0 +1,63 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlRuntime, FunctionResult, BamlCtxManager, BamlSyncStream, Image, ClientRegistry } from "@boundaryml/baml" +import {YoutubeVideoSummary, YoutubeVideoSummarySection} from "./types" +import TypeBuilder from "./type_builder" +import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME } from "./globals" + +export type RecursivePartialNull = T extends object + ? { + [P in keyof T]?: RecursivePartialNull; + } + : T | null; + +export class BamlSyncClient { + private runtime: BamlRuntime + private ctx_manager: BamlCtxManager + + constructor(private runtime: BamlRuntime, private ctx_manager: BamlCtxManager) {} + + /* + * @deprecated NOT IMPLEMENTED as streaming must by async. We + * are not providing an async version as we want to reserve the + * right to provide a sync version in the future. + */ + get stream() { + throw new Error("stream is not available in BamlSyncClient. Use `import { b } from 'baml_client/async_client") + } + + + SummarizeYoutubeVideo( + youtubeVideoUrl: string,transcript: string, + __baml_options__?: { tb?: TypeBuilder, clientRegistry?: ClientRegistry } + ): YoutubeVideoSummary { + const raw = this.runtime.callFunctionSync( + "SummarizeYoutubeVideo", + { + "youtubeVideoUrl": youtubeVideoUrl,"transcript": transcript + }, + this.ctx_manager.cloneContext(), + __baml_options__?.tb?.__tb(), + __baml_options__?.clientRegistry, + ) + return raw.parsed() as YoutubeVideoSummary + } + +} + +export const b = new BamlSyncClient(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_RUNTIME, DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) \ No newline at end of file diff --git a/baml_client/tracing.ts b/baml_client/tracing.ts new file mode 100644 index 0000000..df2682e --- /dev/null +++ b/baml_client/tracing.ts @@ -0,0 +1,33 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { BamlLogEvent } from '@boundaryml/baml'; +import { DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX } from './globals'; + +const traceAsync = +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.traceFnAsync.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) +const traceSync = +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.traceFnSync.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) +const setTags = +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.upsertTags.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX) +const flush = () => { + DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.flush.bind(DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX)() +} +const onLogEvent = (callback: undefined | ((event: BamlLogEvent) => void)) => +DO_NOT_USE_DIRECTLY_UNLESS_YOU_KNOW_WHAT_YOURE_DOING_CTX.onLogEvent(callback) + +export { traceAsync, traceSync, setTags, flush, onLogEvent } \ No newline at end of file diff --git a/baml_client/type_builder.ts b/baml_client/type_builder.ts new file mode 100644 index 0000000..4a46d6e --- /dev/null +++ b/baml_client/type_builder.ts @@ -0,0 +1,82 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { FieldType } from '@boundaryml/baml/native' +import { TypeBuilder as _TypeBuilder, EnumBuilder, ClassBuilder } from '@boundaryml/baml/type_builder' + +export default class TypeBuilder { + private tb: _TypeBuilder; + + + + constructor() { + this.tb = new _TypeBuilder({ + classes: new Set([ + "YoutubeVideoSummary","YoutubeVideoSummarySection", + ]), + enums: new Set([ + + ]) + }); + + + } + + __tb() { + return this.tb._tb(); + } + + string(): FieldType { + return this.tb.string() + } + + int(): FieldType { + return this.tb.int() + } + + float(): FieldType { + return this.tb.float() + } + + bool(): FieldType { + return this.tb.bool() + } + + list(type: FieldType): FieldType { + return this.tb.list(type) + } + + null(): FieldType { + return this.tb.null() + } + + map(key: FieldType, value: FieldType): FieldType { + return this.tb.map(key, value) + } + + union(types: FieldType[]): FieldType { + return this.tb.union(types) + } + + addClass(name: Name): ClassBuilder { + return this.tb.addClass(name); + } + + addEnum(name: Name): EnumBuilder { + return this.tb.addEnum(name); + } +} \ No newline at end of file diff --git a/baml_client/types.ts b/baml_client/types.ts new file mode 100644 index 0000000..948f971 --- /dev/null +++ b/baml_client/types.ts @@ -0,0 +1,32 @@ +/************************************************************************************************* + +Welcome to Baml! To use this generated code, please run one of the following: + +$ npm install @boundaryml/baml +$ yarn add @boundaryml/baml +$ pnpm add @boundaryml/baml + +*************************************************************************************************/ + +// This file was generated by BAML: do not edit it. Instead, edit the BAML +// files and re-generate this code. +// +// tslint:disable +// @ts-nocheck +// biome-ignore format: autogenerated code +/* eslint-disable */ +import { Image } from "@boundaryml/baml" +export interface YoutubeVideoSummary { + url: string + briefSummary: string + sections: YoutubeVideoSummarySection[] + +} + +export interface YoutubeVideoSummarySection { + url: string + offset: number + title: string + keyPoints: string[] + +} diff --git a/package-lock.json b/package-lock.json index 96bd718..febeff9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "0.7.10", "license": "SEE LICENSE IN LICENSE", "dependencies": { + "@boundaryml/baml": "^0.54.2", "@coinbase/coinbase-sdk": "^0.0.16", "@nestjs/axios": "^3.0.3", "ajv": "^7.2.4", @@ -2050,6 +2051,106 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@boundaryml/baml": { + "version": "0.54.2", + "resolved": "https://registry.npmjs.org/@boundaryml/baml/-/baml-0.54.2.tgz", + "integrity": "sha512-jhPjOlJkx4DvKwoXQ8msSNVWJL4C/bXCEyvfDXxBXLMYiyy1J7biBLo5RqHQafh7vk11fJWATattYtbKbTFtTw==", + "license": "MIT", + "bin": { + "baml-cli": "cli.js" + }, + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@boundaryml/baml-darwin-arm64": "0.54.2", + "@boundaryml/baml-darwin-x64": "0.54.2", + "@boundaryml/baml-linux-arm64-gnu": "0.54.2", + "@boundaryml/baml-linux-x64-gnu": "0.54.2", + "@boundaryml/baml-win32-arm64-msvc": "0.54.2", + "@boundaryml/baml-win32-x64-msvc": "0.54.2" + } + }, + "node_modules/@boundaryml/baml-darwin-arm64": { + "version": "0.54.2", + "resolved": "https://registry.npmjs.org/@boundaryml/baml-darwin-arm64/-/baml-darwin-arm64-0.54.2.tgz", + "integrity": "sha512-hlalF1mFVYqsCuXz1XWW9y7dx/eDuDNQMovO448v7aAgVKDtBBtrzaP4Pd2JfV1tqJTc2Yo13uZp9ADqsC70oA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@boundaryml/baml-darwin-x64": { + "version": "0.54.2", + "resolved": "https://registry.npmjs.org/@boundaryml/baml-darwin-x64/-/baml-darwin-x64-0.54.2.tgz", + "integrity": "sha512-5lp/YJ4JdLOBZyJM1GpJ8JEuDlfzaYKDV+kt3VZ1ySrMmExaETTBWWdmk8ri3djZz/EaAAsDxxpqUvHQRL4zWQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@boundaryml/baml-linux-arm64-gnu": { + "version": "0.54.2", + "resolved": "https://registry.npmjs.org/@boundaryml/baml-linux-arm64-gnu/-/baml-linux-arm64-gnu-0.54.2.tgz", + "integrity": "sha512-FeU7tbd1LjJwXNB5eCbpBHmlm9L/NuSKgKhGvbHDd9+XOTGGrE20PBypuzz+LKrDxT2TziN9WqpM7GO14mMRZQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@boundaryml/baml-linux-x64-gnu": { + "version": "0.54.2", + "resolved": "https://registry.npmjs.org/@boundaryml/baml-linux-x64-gnu/-/baml-linux-x64-gnu-0.54.2.tgz", + "integrity": "sha512-JCboOsgSP4csMayNGj4oUTfYxoHMIaNDl2/0rzp6VUaS1b1zNWpV+vV6pEN6+MZQ0uk5E7S7SyWIz5CRaamEig==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@boundaryml/baml-win32-x64-msvc": { + "version": "0.54.2", + "resolved": "https://registry.npmjs.org/@boundaryml/baml-win32-x64-msvc/-/baml-win32-x64-msvc-0.54.2.tgz", + "integrity": "sha512-grD5R8qwg1zN4S8HJwwgfKazlTlMddWa7SXPPeQK0r4i3NHJrO7aE+02UM+LaZ5V/uWKzDIP6OT8ys7at2h8+w==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@coinbase/coinbase-sdk": { "version": "0.0.16", "resolved": "https://registry.npmjs.org/@coinbase/coinbase-sdk/-/coinbase-sdk-0.0.16.tgz", diff --git a/package.json b/package.json index af46c72..a943d0c 100644 --- a/package.json +++ b/package.json @@ -57,6 +57,7 @@ "npm": "10.x.x" }, "dependencies": { + "@boundaryml/baml": "^0.54.2", "@coinbase/coinbase-sdk": "^0.0.16", "@nestjs/axios": "^3.0.3", "ajv": "^7.2.4", From f6a5b711db3cc38337283e79a468a5628428aa42 Mon Sep 17 00:00:00 2001 From: Alfredo Gallardo Date: Fri, 6 Sep 2024 23:51:25 -0400 Subject: [PATCH 2/3] - fix: .node loader for esbuild --- apps/shinkai-tool-youtube-summary/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/shinkai-tool-youtube-summary/project.json b/apps/shinkai-tool-youtube-summary/project.json index 51fa24a..0972574 100644 --- a/apps/shinkai-tool-youtube-summary/project.json +++ b/apps/shinkai-tool-youtube-summary/project.json @@ -12,7 +12,7 @@ "parallel": false, "commands": [ "npx baml-cli generate --from ./apps/shinkai-tool-youtube-summary/baml_src", - "npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-youtube-summary/src/index.ts --outputFolder ./dist/apps/shinkai-tool-youtube-summary" + "npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-youtube-summary/src/index.ts --outputFolder ./dist/apps/shinkai-tool-youtube-summary --loader:.node=file" ] }, "configurations": { From 851bef7fdc316e1b0df30083cfe5748276358053 Mon Sep 17 00:00:00 2001 From: Alfredo Gallardo Date: Fri, 6 Sep 2024 23:52:22 -0400 Subject: [PATCH 3/3] - fix: .node loader --- apps/shinkai-tool-youtube-summary/project.json | 2 +- scripts/tool-bundler.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/shinkai-tool-youtube-summary/project.json b/apps/shinkai-tool-youtube-summary/project.json index 0972574..51fa24a 100644 --- a/apps/shinkai-tool-youtube-summary/project.json +++ b/apps/shinkai-tool-youtube-summary/project.json @@ -12,7 +12,7 @@ "parallel": false, "commands": [ "npx baml-cli generate --from ./apps/shinkai-tool-youtube-summary/baml_src", - "npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-youtube-summary/src/index.ts --outputFolder ./dist/apps/shinkai-tool-youtube-summary --loader:.node=file" + "npx ts-node scripts/tool-bundler.ts --entry ./apps/shinkai-tool-youtube-summary/src/index.ts --outputFolder ./dist/apps/shinkai-tool-youtube-summary" ] }, "configurations": { diff --git a/scripts/tool-bundler.ts b/scripts/tool-bundler.ts index 023b1a0..9a55b7b 100644 --- a/scripts/tool-bundler.ts +++ b/scripts/tool-bundler.ts @@ -13,6 +13,9 @@ build({ platform: 'node', target: 'node20.16', outfile: outputFile, + loader: { + '.node': 'file', + }, }) .then(async () => { const code = await fs.promises.readFile(outputFile, 'utf-8');