Skip to content

Commit

Permalink
tb fix (#721)
Browse files Browse the repository at this point in the history
- **Fix typebuilder for random enums**
- **0.44.0**
  • Loading branch information
aaronvg authored Jun 26, 2024
1 parent 73cf36d commit 3f34e55
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 53 deletions.
28 changes: 14 additions & 14 deletions engine/Cargo.lock

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

2 changes: 1 addition & 1 deletion engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal-baml-core = { path = "baml-lib/baml-core" }
internal-baml-jinja = { path = "baml-lib/jinja" }

[workspace.package]
version = "0.43.0"
version = "0.44.0"
authors = ["Boundary <[email protected]>"]

description = "BAML Toolchain"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export default class TypeBuilder {
}

addClass<Name extends string>(name: Name): ClassBuilder<Name> {
this.tb.addClass(name);
return this.tb.addClass(name);
}

addEnum<Name extends string>(name: Name): EnumBuilder<Name> {
this.tb.addEnum(name);
return this.tb.addEnum(name);
}
}
2 changes: 1 addition & 1 deletion engine/language_client_python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "baml-py"
version = "0.43.0"
version = "0.44.0"
description = "BAML python bindings (pyproject.toml)"
readme = "README.md"
authors = [["Boundary", "[email protected]"]]
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_ruby/baml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |spec|
spec.name = "baml"
spec.version = "0.43.0"
spec.version = "0.44.0"
spec.authors = ["BoundaryML"]
spec.email = ["[email protected]"]

Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_typescript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@boundaryml/baml",
"version": "0.43.0",
"version": "0.44.0",
"description": "BAML typescript bindings (package.json)",
"repository": {
"type": "git",
Expand Down
9 changes: 6 additions & 3 deletions engine/language_client_typescript/type_builder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ type CheckNever<T, TypeName extends string, Value extends string> = [T] extends
type ExcludeFrom<T, U> = T extends U ? never : T;
type RestrictNot<Name extends string, Value extends string, T extends string> = IsLiteral<T> extends true ? CheckNever<ExcludeFrom<Value, T>, Name, Value> : Value;
export declare class TypeBuilder {
protected classes: Set<String>;
protected enums: Set<String>;
private tb;
constructor(classes: Set<String>, enums: Set<String>);
protected classes: Set<string>;
protected enums: Set<string>;
constructor({ classes, enums }: {
classes: Set<string>;
enums: Set<string>;
});
_tb(): _TypeBuilder;
string(): FieldType;
int(): FieldType;
Expand Down
2 changes: 1 addition & 1 deletion engine/language_client_typescript/type_builder.d.ts.map

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

4 changes: 2 additions & 2 deletions engine/language_client_typescript/type_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.EnumBuilder = exports.ClassBuilder = exports.TypeBuilder = void 0;
const native_1 = require("./native");
class TypeBuilder {
tb;
classes;
enums;
tb;
constructor(classes, enums) {
constructor({ classes, enums }) {
this.classes = classes;
this.enums = enums;
this.tb = new native_1.TypeBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ type RestrictNot<Name extends string, Value extends string, T extends string> =

export class TypeBuilder {
private tb: _TypeBuilder
protected classes: Set<string>
protected enums: Set<string>

constructor(
protected classes: Set<String>,
protected enums: Set<String>,
) {
constructor({ classes, enums }: { classes: Set<string>; enums: Set<string> }) {
this.classes = classes
this.enums = enums
this.tb = new _TypeBuilder()
}

Expand Down
4 changes: 2 additions & 2 deletions integ-tests/typescript/baml_client/type_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export default class TypeBuilder {
}

addClass<Name extends string>(name: Name): ClassBuilder<Name> {
this.tb.addClass(name);
return this.tb.addClass(name);
}

addEnum<Name extends string>(name: Name): EnumBuilder<Name> {
this.tb.addEnum(name);
return this.tb.addEnum(name);
}
}
57 changes: 42 additions & 15 deletions integ-tests/typescript/tests/integ-tests.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert'
import { image_b64, audio_b64 } from './base64_test_data'
import { Image} from '@boundaryml/baml'
import { Image } from '@boundaryml/baml'
import { Audio } from '@boundaryml/baml'
import {
b,
Expand All @@ -15,7 +15,6 @@ import {
import TypeBuilder from '../baml_client/type_builder'
import { RecursivePartialNull } from '../baml_client/client'


describe('Integ tests', () => {
it('should work for all inputs', async () => {
let res = await b.TestFnNamedArgsSingleBool(true)
Expand Down Expand Up @@ -118,19 +117,19 @@ describe('Integ tests', () => {
})

it('should work with image from base 64', async () => {
let res = await b.TestImageInput(
Image.fromBase64('image/png', image_b64),
)
let res = await b.TestImageInput(Image.fromBase64('image/png', image_b64))
expect(res.toLowerCase()).toContain('green')
})

it('should work with audio base 64', async () => {
let res = await b.AudioInput(Audio.fromBase64('audio/mp3',audio_b64))
let res = await b.AudioInput(Audio.fromBase64('audio/mp3', audio_b64))
expect(res.toLowerCase()).toContain('yes')
})

it('should work with audio from url', async () => {
let res = await b.AudioInput(Audio.fromUrl("https://actions.google.com/sounds/v1/emergency/beeper_emergency_call.ogg"))
let res = await b.AudioInput(
Audio.fromUrl('https://actions.google.com/sounds/v1/emergency/beeper_emergency_call.ogg'),
)

expect(res.toLowerCase()).toContain('no')
})
Expand Down Expand Up @@ -237,7 +236,7 @@ describe('Integ tests', () => {
})('hi', 10)
})

it('should work with dynamic types', async () => {
it('should work with dynamic types single', async () => {
let tb = new TypeBuilder()
tb.Person.addProperty('last_name', tb.string().optional())
tb.Person.addProperty('height', tb.float().optional()).description('Height in meters')
Expand All @@ -255,28 +254,56 @@ describe('Integ tests', () => {
console.log(res)
})

it('should work with dynamic types enum', async () => {
let tb = new TypeBuilder()
const fieldEnum = tb.addEnum('Animal')
const animals = ['giraffe', 'elephant', 'lion']
for (const animal of animals) {
fieldEnum.addValue(animal.toUpperCase())
}
tb.Person.addProperty('animalLiked', fieldEnum.type())
const res = await b.ExtractPeople(
"My name is Harrison. My hair is black and I'm 6 feet tall. I'm pretty good around the hoop. I like giraffes.",
{ tb },
)
expect(res.length).toBeGreaterThan(0)
expect(res[0]['animalLiked']).toEqual('GIRAFFE')
})

it('should work with dynamic types class', async () => {
let tb = new TypeBuilder()
const animalClass = tb.addClass('Animal')
animalClass.addProperty('animal', tb.string()).description('The animal mentioned, in singular form.')
tb.Person.addProperty('animalLiked', animalClass.type())
const res = await b.ExtractPeople(
"My name is Harrison. My hair is black and I'm 6 feet tall. I'm pretty good around the hoop. I like giraffes.",
{ tb },
)
expect(res.length).toBeGreaterThan(0)
const animalLiked = res[0]['animalLiked']
expect(animalLiked['animal']).toContain('giraffe')
})

it('should work with dynamic inputs class', async () => {
let tb = new TypeBuilder()
tb.DynInputOutput.addProperty('new-key', tb.string().optional())

const res = await b.DynamicInputOutput({ 'new-key': 'hi', testKey: "myTest" }, { tb })
expect(res["new-key"]).toEqual('hi')
expect(res["testKey"]).toEqual('myTest')
const res = await b.DynamicInputOutput({ 'new-key': 'hi', testKey: 'myTest' }, { tb })
expect(res['new-key']).toEqual('hi')
expect(res['testKey']).toEqual('myTest')
})

it('should work with dynamic inputs list', async () => {
let tb = new TypeBuilder()
tb.DynInputOutput.addProperty('new-key', tb.string().optional())

const res = await b.DynamicListInputOutput([{ 'new-key': 'hi', testKey: "myTest" }], { tb })
expect(res[0]["new-key"]).toEqual('hi')
expect(res[0]["testKey"]).toEqual('myTest')
const res = await b.DynamicListInputOutput([{ 'new-key': 'hi', testKey: 'myTest' }], { tb })
expect(res[0]['new-key']).toEqual('hi')
expect(res[0]['testKey']).toEqual('myTest')
})

// test with extra list, boolean in the input as well.


it('should work with nested classes', async () => {
let stream = b.stream.FnOutputClassNested('hi!')
let msgs: RecursivePartialNull<TestClassNested[]> = []
Expand Down
2 changes: 1 addition & 1 deletion tools/versions/engine.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.43.0
current_version = 0.44.0
commit = False
tag = False
parse = ^(?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)$
Expand Down
2 changes: 1 addition & 1 deletion tools/versions/python.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.43.0
current_version = 0.44.0
commit = False
tag = False
parse = ^(?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)$
Expand Down
2 changes: 1 addition & 1 deletion tools/versions/ruby.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.43.0
current_version = 0.44.0
commit = False
tag = False
parse = ^(?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)$
Expand Down
2 changes: 1 addition & 1 deletion tools/versions/typescript.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.43.0
current_version = 0.44.0
commit = False
tag = False
parse = ^(?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)$
Expand Down
2 changes: 1 addition & 1 deletion tools/versions/vscode.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.43.0
current_version = 0.44.0
commit = False
tag = False
parse = ^(?P<major>\d+)\.(?P<minor>\d+).(?P<patch>\d+)$
Expand Down
2 changes: 1 addition & 1 deletion typescript/vscode-ext/packages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "baml-extension",
"displayName": "Baml",
"description": "BAML is a DSL for AI applications.",
"version": "0.43.0",
"version": "0.44.0",
"publisher": "Boundary",
"repository": "https://github.com/BoundaryML/baml",
"homepage": "https://www.boundaryml.com",
Expand Down

0 comments on commit 3f34e55

Please sign in to comment.