Skip to content
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

- improve: implement baml to improve summary responses #42

Open
wants to merge 3 commits 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
92 changes: 92 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/async_client.ts
Original file line number Diff line number Diff line change
@@ -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> = T extends object
? {
[P in keyof T]?: RecursivePartialNull<T[P]>;
}
: 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<YoutubeVideoSummary> {
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<RecursivePartialNull<YoutubeVideoSummary>, 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<RecursivePartialNull<YoutubeVideoSummary>, YoutubeVideoSummary>(
raw,
(a): a is RecursivePartialNull<YoutubeVideoSummary> => 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)
27 changes: 27 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/globals.ts
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/index.ts
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 25 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/inlinedbaml.ts
Original file line number Diff line number Diff line change
@@ -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<llm> 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// [email protected]\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;
}
63 changes: 63 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/sync_client.ts
Original file line number Diff line number Diff line change
@@ -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> = T extends object
? {
[P in keyof T]?: RecursivePartialNull<T[P]>;
}
: 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)
33 changes: 33 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/tracing.ts
Original file line number Diff line number Diff line change
@@ -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 }
82 changes: 82 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/type_builder.ts
Original file line number Diff line number Diff line change
@@ -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 extends string>(name: Name): ClassBuilder<Name> {
return this.tb.addClass(name);
}

addEnum<Name extends string>(name: Name): EnumBuilder<Name> {
return this.tb.addEnum(name);
}
}
32 changes: 32 additions & 0 deletions apps/shinkai-tool-youtube-summary/baml_client/types.ts
Original file line number Diff line number Diff line change
@@ -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[]

}
Loading
Loading