orchestrated 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +87 -39
  2. package/index.js.map +9 -7
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -13911,6 +13911,44 @@ var init_zod = __esm(() => {
13911
13911
  zod_default = exports_external;
13912
13912
  });
13913
13913
 
13914
+ // src/batch/bedrock-openai-client.ts
13915
+ var exports_bedrock_openai_client = {};
13916
+ __export(exports_bedrock_openai_client, {
13917
+ BedrockOpenAI: () => BedrockOpenAI
13918
+ });
13919
+ import OpenAI from "openai";
13920
+ function trimToolCallNames(response) {
13921
+ if (!response || typeof response !== "object")
13922
+ return response;
13923
+ const resp = response;
13924
+ if (!Array.isArray(resp.choices))
13925
+ return response;
13926
+ for (const choice of resp.choices) {
13927
+ const toolCalls = choice?.message?.tool_calls;
13928
+ if (!Array.isArray(toolCalls))
13929
+ continue;
13930
+ for (const toolCall of toolCalls) {
13931
+ if (toolCall?.function?.name && typeof toolCall.function.name === "string") {
13932
+ toolCall.function.name = toolCall.function.name.trim();
13933
+ }
13934
+ }
13935
+ }
13936
+ return response;
13937
+ }
13938
+ var BedrockOpenAI;
13939
+ var init_bedrock_openai_client = __esm(() => {
13940
+ BedrockOpenAI = class BedrockOpenAI extends OpenAI {
13941
+ constructor(options) {
13942
+ super(options);
13943
+ const originalCreate = this.chat.completions.create.bind(this.chat.completions);
13944
+ this.chat.completions.create = async (...args) => {
13945
+ const result = await originalCreate(...args);
13946
+ return trimToolCallNames(result);
13947
+ };
13948
+ }
13949
+ };
13950
+ });
13951
+
13914
13952
  // node_modules/.pnpm/yaml@2.8.2/node_modules/yaml/dist/nodes/identity.js
13915
13953
  var require_identity = __commonJS((exports) => {
13916
13954
  var ALIAS = Symbol.for("yaml.alias");
@@ -151103,6 +151141,7 @@ function createBedrockConverseClient(region, modelId) {
151103
151141
  finishReason = "content_filter";
151104
151142
  break;
151105
151143
  }
151144
+ console.dir(response, { depth: null });
151106
151145
  const messageContent = response.output?.message?.content?.map((c) => c.text).join("") ?? "";
151107
151146
  return {
151108
151147
  id: `chatcmpl-bedrock-${Date.now()}`,
@@ -176308,7 +176347,7 @@ var init_esm = __esm(() => {
176308
176347
  });
176309
176348
 
176310
176349
  // node_modules/.pnpm/autoevals@0.0.131_encoding@0.1.13_ws@8.18.3/node_modules/autoevals/jsdist/index.mjs
176311
- import { AzureOpenAI, OpenAI as OpenAI3 } from "openai";
176350
+ import { AzureOpenAI, OpenAI as OpenAI4 } from "openai";
176312
176351
  function extractOpenAIArgs(args) {
176313
176352
  return args.client ? { client: args.client } : {
176314
176353
  openAiApiKey: args.openAiApiKey,
@@ -176698,7 +176737,7 @@ var import_js_levenshtein, import_compute_cosine_similarity, import_ajv, PROXY_U
176698
176737
  dangerouslyAllowBrowser: openAiDangerouslyAllowBrowser
176699
176738
  });
176700
176739
  }
176701
- return new OpenAI3({
176740
+ return new OpenAI4({
176702
176741
  apiKey: openAiApiKey || process.env.OPENAI_API_KEY || process.env.BRAINTRUST_API_KEY,
176703
176742
  organization: openAiOrganizationId,
176704
176743
  baseURL: openAiBaseUrl || process.env.OPENAI_BASE_URL || PROXY_URL,
@@ -206304,11 +206343,33 @@ init_zod();
206304
206343
  import { createHash as createHash2 } from "node:crypto";
206305
206344
 
206306
206345
  // src/batch/manager.ts
206346
+ init_bedrock_openai_client();
206307
206347
  import { createHash } from "node:crypto";
206308
206348
  import * as fs from "node:fs";
206309
206349
  import * as os from "node:os";
206310
206350
  import * as path from "node:path";
206311
- import OpenAI from "openai";
206351
+ import OpenAI2 from "openai";
206352
+
206353
+ // src/utils/index.ts
206354
+ var iso = {
206355
+ writeln: (text) => console.log(text)
206356
+ };
206357
+ var colors = {
206358
+ reset: "\x1B[0m",
206359
+ blue: "\x1B[34m",
206360
+ brightBlue: "\x1B[94m",
206361
+ white: "\x1B[97m",
206362
+ gray: "\x1B[90m",
206363
+ yellow: "\x1B[33m"
206364
+ };
206365
+ var warning = (text) => `Warning: ${text}`;
206366
+ function logError(e, verbose) {
206367
+ if (!verbose) {
206368
+ console.error(`${e}`);
206369
+ } else {
206370
+ console.error(e);
206371
+ }
206372
+ }
206312
206373
 
206313
206374
  // src/batch/bedrock-converse.ts
206314
206375
  function openaiToConverseRecord(requestId, body) {
@@ -206415,27 +206476,6 @@ function converseOutputToBatchResult(record2) {
206415
206476
  };
206416
206477
  }
206417
206478
 
206418
- // src/utils/index.ts
206419
- var iso = {
206420
- writeln: (text) => console.log(text)
206421
- };
206422
- var colors = {
206423
- reset: "\x1B[0m",
206424
- blue: "\x1B[34m",
206425
- brightBlue: "\x1B[94m",
206426
- white: "\x1B[97m",
206427
- gray: "\x1B[90m",
206428
- yellow: "\x1B[33m"
206429
- };
206430
- var warning = (text) => `Warning: ${text}`;
206431
- function logError(e, verbose) {
206432
- if (!verbose) {
206433
- console.error(`${e}`);
206434
- } else {
206435
- console.error(e);
206436
- }
206437
- }
206438
-
206439
206479
  // src/batch/manager.ts
206440
206480
  class S3FileManager {
206441
206481
  bucket;
@@ -206548,8 +206588,8 @@ class BatchClient {
206548
206588
  }
206549
206589
  this.bedrockConfig = opts.bedrock;
206550
206590
  this.s3FileManager = new S3FileManager(opts.bedrock.s3Bucket, opts.bedrock.region);
206551
- this.client = new OpenAI({
206552
- baseURL: `https://bedrock-runtime.${opts.bedrock.region}.amazonaws.com/openai/v1`,
206591
+ this.client = new BedrockOpenAI({
206592
+ baseURL: `https://bedrock-mantle.${opts.bedrock.region}.api.aws/v1`,
206553
206593
  apiKey: opts.bedrock.apiKey,
206554
206594
  defaultHeaders: {
206555
206595
  "X-Amzn-Bedrock-RoleArn": opts.bedrock.serviceRoleArn,
@@ -206565,11 +206605,11 @@ class BatchClient {
206565
206605
  this.s3FileManager = new S3FileManager(opts.bedrockNative.s3Bucket, opts.bedrockNative.region);
206566
206606
  this.client = null;
206567
206607
  } else {
206568
- this.client = new OpenAI(opts.clientOptions ?? {});
206608
+ this.client = new OpenAI2(opts.clientOptions ?? {});
206569
206609
  }
206570
206610
  } else {
206571
206611
  this.mode = "OPENAI";
206572
- this.client = new OpenAI(options);
206612
+ this.client = new OpenAI2(options);
206573
206613
  }
206574
206614
  this.tempDir = path.join(os.tmpdir(), "batches");
206575
206615
  if (!fs.existsSync(this.tempDir)) {
@@ -206930,7 +206970,7 @@ function createChatCompletionRequest(custom_id, body) {
206930
206970
  };
206931
206971
  }
206932
206972
  // src/batch/client.ts
206933
- import OpenAI2 from "openai";
206973
+ import OpenAI3 from "openai";
206934
206974
 
206935
206975
  class BatchingError extends Error {
206936
206976
  request;
@@ -206943,7 +206983,7 @@ function isBatchingError(error48) {
206943
206983
  return error48 instanceof BatchingError;
206944
206984
  }
206945
206985
 
206946
- class EvalClient extends OpenAI2 {
206986
+ class EvalClient extends OpenAI3 {
206947
206987
  batchClient;
206948
206988
  constructor({ batchClient, ...config2 }) {
206949
206989
  super(config2);
@@ -206960,6 +207000,10 @@ class EvalClient extends OpenAI2 {
206960
207000
  };
206961
207001
  }
206962
207002
  }
207003
+
207004
+ // src/batch/index.ts
207005
+ init_bedrock_openai_client();
207006
+
206963
207007
  // src/registry/index.ts
206964
207008
  function getRegistry() {
206965
207009
  if (!globalThis.__ORCHESTRATED_EVAL_REGISTRY__) {
@@ -207795,9 +207839,9 @@ function getEvaluationOptions(name, options, state) {
207795
207839
  s3Bucket: state.bedrockS3Bucket
207796
207840
  }
207797
207841
  });
207798
- const OpenAI4 = __require("openai").default;
207799
- openaiClient = new OpenAI4({
207800
- baseURL: `https://bedrock-runtime.${state.bedrockRegion}.amazonaws.com/openai/v1`,
207842
+ const { BedrockOpenAI: BedrockOpenAI2 } = (init_bedrock_openai_client(), __toCommonJS(exports_bedrock_openai_client));
207843
+ openaiClient = new BedrockOpenAI2({
207844
+ baseURL: `https://bedrock-mantle.${state.bedrockRegion}.api.aws/v1`,
207801
207845
  apiKey: state.bedrockApiKey,
207802
207846
  defaultHeaders: {
207803
207847
  "X-Amzn-Bedrock-RoleArn": state.bedrockServiceRoleArn,
@@ -207818,7 +207862,9 @@ function getEvaluationOptions(name, options, state) {
207818
207862
  s3Bucket: state.bedrockS3Bucket
207819
207863
  }
207820
207864
  });
207821
- const { createBedrockConverseClient: createBedrockConverseClient2 } = __toCommonJS(exports_bedrock_converse_client);
207865
+ const {
207866
+ createBedrockConverseClient: createBedrockConverseClient2
207867
+ } = __toCommonJS(exports_bedrock_converse_client);
207822
207868
  openaiClient = createBedrockConverseClient2(state.bedrockRegion, state.bedrockModelId);
207823
207869
  } else {
207824
207870
  batchClient = new BatchClient;
@@ -207828,8 +207874,8 @@ function getEvaluationOptions(name, options, state) {
207828
207874
  batchClient
207829
207875
  });
207830
207876
  } else {
207831
- const OpenAI4 = __require("openai").default;
207832
- openaiClient = merged.openaiClient || new OpenAI4;
207877
+ const OpenAI5 = __require("openai").default;
207878
+ openaiClient = merged.openaiClient || new OpenAI5;
207833
207879
  }
207834
207880
  const onResult = merged.onResult;
207835
207881
  return {
@@ -207874,9 +207920,11 @@ async function evaluateDataCase(dataCase, evaluator, _ctx, options) {
207874
207920
  expected: dataCase.expected,
207875
207921
  tags: dataCase.tags,
207876
207922
  id: caseId,
207877
- client: client2,
207878
- model: options.execute === "sync" && (options.batchProcessor === "BEDROCK_OPENAI" || options.batchProcessor === "BEDROCK") ? _ctx.state.bedrockModelId : undefined
207923
+ client: client2
207879
207924
  };
207925
+ if (options.execute === "sync" && (options.batchProcessor === "BEDROCK_OPENAI" || options.batchProcessor === "BEDROCK")) {
207926
+ scorerArgs.model = _ctx.state.bedrockModelId;
207927
+ }
207880
207928
  const fieldsToExclude = new Set(["state", "ctx", "tags", "id", "client"]);
207881
207929
  const argsForStorage = Object.fromEntries(Object.entries(scorerArgs).filter(([key]) => !fieldsToExclude.has(key)));
207882
207930
  const { scorerFailAsZero, verbose } = options;
@@ -208632,4 +208680,4 @@ export {
208632
208680
  Behavioral
208633
208681
  };
208634
208682
 
208635
- //# debugId=4034857F5C6A089964756E2164756E21
208683
+ //# debugId=AD205A8029985CD264756E2164756E21