magnitude-core
Version:
Magnitude e2e testing agent
101 lines (97 loc) • 5.09 kB
JavaScript
/*************************************************************************************************
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
*************************************************************************************************/
import { toBamlError } from "@boundaryml/baml";
import { HttpRequest, HttpStreamRequest } from "./sync_request";
import { LlmResponseParser, LlmStreamParser } from "./parser";
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 class BamlSyncClient {
runtime;
ctxManager;
httpRequest;
httpStreamRequest;
llmResponseParser;
llmStreamParser;
bamlOptions;
constructor(runtime, ctxManager, bamlOptions) {
this.runtime = runtime;
this.ctxManager = ctxManager;
this.httpRequest = new HttpRequest(runtime, ctxManager);
this.httpStreamRequest = new HttpStreamRequest(runtime, ctxManager);
this.llmResponseParser = new LlmResponseParser(runtime, ctxManager);
this.llmStreamParser = new LlmStreamParser(runtime, ctxManager);
this.bamlOptions = bamlOptions || {};
}
withOptions(bamlOptions) {
return new BamlSyncClient(this.runtime, this.ctxManager, bamlOptions);
}
/*
* @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");
}
get request() {
return this.httpRequest;
}
get streamRequest() {
return this.httpStreamRequest;
}
get parse() {
return this.llmResponseParser;
}
get parseStream() {
return this.llmStreamParser;
}
CreatePartialRecipe(memory, task, taskData, includeClaudeSpoof, __baml_options__) {
try {
const options = { ...this.bamlOptions, ...(__baml_options__ || {}) };
const collector = options.collector ? (Array.isArray(options.collector) ? options.collector : [options.collector]) : [];
const rawEnv = __baml_options__?.env ? { ...process.env, ...__baml_options__.env } : { ...process.env };
const env = Object.fromEntries(Object.entries(rawEnv).filter(([_, value]) => value !== undefined));
const raw = this.runtime.callFunctionSync("CreatePartialRecipe", {
"memory": memory, "task": task, "taskData": taskData, "includeClaudeSpoof": includeClaudeSpoof
}, this.ctxManager.cloneContext(), options.tb?.__tb(), options.clientRegistry, collector, env);
return raw.parsed(false);
}
catch (error) {
throw toBamlError(error);
}
}
ExtractData(instructions, screenshot, domContent, includeClaudeSpoof, __baml_options__) {
try {
const options = { ...this.bamlOptions, ...(__baml_options__ || {}) };
const collector = options.collector ? (Array.isArray(options.collector) ? options.collector : [options.collector]) : [];
const rawEnv = __baml_options__?.env ? { ...process.env, ...__baml_options__.env } : { ...process.env };
const env = Object.fromEntries(Object.entries(rawEnv).filter(([_, value]) => value !== undefined));
const raw = this.runtime.callFunctionSync("ExtractData", {
"instructions": instructions, "screenshot": screenshot, "domContent": domContent, "includeClaudeSpoof": includeClaudeSpoof
}, this.ctxManager.cloneContext(), options.tb?.__tb(), options.clientRegistry, collector, env);
return raw.parsed(false);
}
catch (error) {
throw toBamlError(error);
}
}
QueryMemory(memory, query, includeClaudeSpoof, __baml_options__) {
try {
const options = { ...this.bamlOptions, ...(__baml_options__ || {}) };
const collector = options.collector ? (Array.isArray(options.collector) ? options.collector : [options.collector]) : [];
const rawEnv = __baml_options__?.env ? { ...process.env, ...__baml_options__.env } : { ...process.env };
const env = Object.fromEntries(Object.entries(rawEnv).filter(([_, value]) => value !== undefined));
const raw = this.runtime.callFunctionSync("QueryMemory", {
"memory": memory, "query": query, "includeClaudeSpoof": includeClaudeSpoof
}, this.ctxManager.cloneContext(), options.tb?.__tb(), options.clientRegistry, collector, env);
return raw.parsed(false);
}
catch (error) {
throw toBamlError(error);
}
}
}
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);