-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
915 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,7 +60,7 @@ internal-baml-core = { path = "baml-lib/baml-core" } | |
internal-baml-jinja = { path = "baml-lib/jinja" } | ||
|
||
[workspace.package] | ||
version = "0.47.0" | ||
version = "0.48.0" | ||
authors = ["Boundary <[email protected]>"] | ||
|
||
description = "BAML Toolchain" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[project] | ||
name = "baml-py" | ||
version = "0.47.0" | ||
version = "0.48.0" | ||
description = "BAML python bindings (pyproject.toml)" | ||
readme = "README.md" | ||
authors = [["Boundary", "[email protected]"]] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
Gem::Specification.new do |spec| | ||
spec.name = "baml" | ||
spec.version = "0.47.0" | ||
spec.version = "0.48.0" | ||
spec.authors = ["BoundaryML"] | ||
spec.email = ["[email protected]"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { BamlSpan, RuntimeContextManager, BamlRuntime, BamlLogEvent } from './native'; | ||
export declare class BamlCtxManager { | ||
private rt; | ||
private ctx; | ||
constructor(rt: BamlRuntime); | ||
upsertTags(tags: Record<string, string>): void; | ||
cloneContext(): RuntimeContextManager; | ||
startTrace(name: string, args: Record<string, any>): [RuntimeContextManager, BamlSpan]; | ||
endTrace(span: BamlSpan, response: any): void; | ||
flush(): void; | ||
onLogEvent(callback: (event: BamlLogEvent) => void): void; | ||
traceFnSync<ReturnType, F extends (...args: any[]) => ReturnType>(name: string, func: F): F; | ||
traceFnAsync<ReturnType, F extends (...args: any[]) => Promise<ReturnType>>(name: string, func: F): F; | ||
} | ||
//# sourceMappingURL=async_context_vars.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BamlCtxManager = void 0; | ||
const native_1 = require("./native"); | ||
const async_hooks_1 = require("async_hooks"); | ||
class BamlCtxManager { | ||
rt; | ||
ctx; | ||
constructor(rt) { | ||
this.rt = rt; | ||
this.ctx = new async_hooks_1.AsyncLocalStorage(); | ||
this.ctx.enterWith(rt.createContextManager()); | ||
process.on('exit', () => { | ||
this.rt.flush(); | ||
}); | ||
} | ||
upsertTags(tags) { | ||
const manager = this.ctx.getStore(); | ||
manager.upsertTags(tags); | ||
} | ||
cloneContext() { | ||
let store = this.ctx.getStore(); | ||
if (store === undefined) { | ||
store = this.rt.createContextManager(); | ||
this.ctx.enterWith(store); | ||
} | ||
return store.deepClone(); | ||
} | ||
startTrace(name, args) { | ||
const mng = this.cloneContext(); | ||
return [mng, native_1.BamlSpan.new(this.rt, name, args, mng)]; | ||
} | ||
endTrace(span, response) { | ||
const manager = this.ctx.getStore(); | ||
if (!manager) { | ||
console.error('Context lost before span could be finished\n'); | ||
return; | ||
} | ||
try { | ||
span.finish(response, manager); | ||
} | ||
catch (e) { | ||
console.error('BAML internal error', e); | ||
} | ||
} | ||
flush() { | ||
this.rt.flush(); | ||
} | ||
onLogEvent(callback) { | ||
this.rt.setLogEventCallback((error, param) => { | ||
if (!error) { | ||
callback(param); | ||
} | ||
}); | ||
} | ||
traceFnSync(name, func) { | ||
return ((...args) => { | ||
const params = args.reduce((acc, arg, i) => ({ | ||
...acc, | ||
[`arg${i}`]: arg, // generic way to label args | ||
}), {}); | ||
const [mng, span] = this.startTrace(name, params); | ||
this.ctx.run(mng, () => { | ||
try { | ||
const response = func(...args); | ||
this.endTrace(span, response); | ||
return response; | ||
} | ||
catch (e) { | ||
this.endTrace(span, e); | ||
throw e; | ||
} | ||
}); | ||
}); | ||
} | ||
traceFnAsync(name, func) { | ||
const funcName = name; | ||
return (async (...args) => { | ||
const params = args.reduce((acc, arg, i) => ({ | ||
...acc, | ||
[`arg${i}`]: arg, // generic way to label args | ||
}), {}); | ||
const [mng, span] = this.startTrace(name, params); | ||
await this.ctx.run(mng, async () => { | ||
try { | ||
const response = await func(...args); | ||
this.endTrace(span, response); | ||
return response; | ||
} | ||
catch (e) { | ||
this.endTrace(span, e); | ||
throw e; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
exports.BamlCtxManager = BamlCtxManager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { BamlRuntime, FunctionResult, FunctionResultStream, BamlImage as Image, BamlAudio as Audio, invoke_runtime_cli, } from './native'; | ||
export { BamlStream } from './stream'; | ||
export { BamlCtxManager } from './async_context_vars'; | ||
//# sourceMappingURL=index.d.ts.map |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BamlCtxManager = exports.BamlStream = exports.invoke_runtime_cli = exports.Audio = exports.Image = exports.FunctionResultStream = exports.FunctionResult = exports.BamlRuntime = void 0; | ||
var native_1 = require("./native"); | ||
Object.defineProperty(exports, "BamlRuntime", { enumerable: true, get: function () { return native_1.BamlRuntime; } }); | ||
Object.defineProperty(exports, "FunctionResult", { enumerable: true, get: function () { return native_1.FunctionResult; } }); | ||
Object.defineProperty(exports, "FunctionResultStream", { enumerable: true, get: function () { return native_1.FunctionResultStream; } }); | ||
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return native_1.BamlImage; } }); | ||
Object.defineProperty(exports, "Audio", { enumerable: true, get: function () { return native_1.BamlAudio; } }); | ||
Object.defineProperty(exports, "invoke_runtime_cli", { enumerable: true, get: function () { return native_1.invoke_runtime_cli; } }); | ||
var stream_1 = require("./stream"); | ||
Object.defineProperty(exports, "BamlStream", { enumerable: true, get: function () { return stream_1.BamlStream; } }); | ||
var async_context_vars_1 = require("./async_context_vars"); | ||
Object.defineProperty(exports, "BamlCtxManager", { enumerable: true, get: function () { return async_context_vars_1.BamlCtxManager; } }); |
Oops, something went wrong.