190proof 1.0.36 → 1.0.38

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.
package/dist/index.js CHANGED
@@ -31511,6 +31511,10 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
31511
31511
  openAiPayload.model = "gpt-4-turbo-2024-04-09" /* GPT4_0409 */;
31512
31512
  openAiPayload.temperature = 0.8;
31513
31513
  if (errorCode === "content_policy_violation") {
31514
+ console.log(
31515
+ identifier,
31516
+ `Switching to OpenAI service due to content policy violation error`
31517
+ );
31514
31518
  openAiPayload.messages.forEach((message) => {
31515
31519
  if (Array.isArray(message.content)) {
31516
31520
  message.content = message.content.filter(
@@ -31528,11 +31532,19 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
31528
31532
  }
31529
31533
  if (i5 === 3) {
31530
31534
  if ((openAiConfig == null ? void 0 : openAiConfig.service) === "azure") {
31535
+ console.log(
31536
+ identifier,
31537
+ `Switching to OpenAI service due to Azure service error`
31538
+ );
31531
31539
  openAiConfig.service = "openai";
31532
31540
  }
31533
31541
  }
31534
31542
  if (i5 === 4) {
31535
31543
  if (openAiPayload.tools) {
31544
+ console.log(
31545
+ identifier,
31546
+ `Switching to no tool choice due to persistent error`
31547
+ );
31536
31548
  openAiPayload.tool_choice = "none";
31537
31549
  }
31538
31550
  }
@@ -31574,6 +31586,19 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
31574
31586
  }
31575
31587
  const azureConfig = openAiConfig.modelConfigMap[model];
31576
31588
  const endpoint = `${openAiConfig.baseUrl}/azure-openai/${azureConfig.resource}/${azureConfig.deployment}/chat/completions?api-version=${azureConfig.apiVersion}`;
31589
+ try {
31590
+ const stringifiedPayload = JSON.stringify({
31591
+ ...openAiPayload,
31592
+ stream: true
31593
+ });
31594
+ const parsedPayload = JSON.parse(stringifiedPayload);
31595
+ } catch (error) {
31596
+ console.error(
31597
+ identifier,
31598
+ "Stream error: Azure OpenAI JSON parsing error:",
31599
+ JSON.stringify(error)
31600
+ );
31601
+ }
31577
31602
  response = await fetch(endpoint, {
31578
31603
  method: "POST",
31579
31604
  headers: {
@@ -31635,9 +31660,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
31635
31660
  console.log(
31636
31661
  identifier,
31637
31662
  `Stream error: ended after ${chunkIndex + 1} chunks via reader done flag.`,
31638
- paragraph,
31639
- functionCallName,
31640
- functionCallArgs
31663
+ rawStreamedBody
31641
31664
  );
31642
31665
  throw new Error("Stream error: ended prematurely");
31643
31666
  }
@@ -31686,7 +31709,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
31686
31709
  console.error(
31687
31710
  identifier,
31688
31711
  "Stream error: OpenAI error:",
31689
- json.error
31712
+ json.error && JSON.stringify(json.error)
31690
31713
  );
31691
31714
  const error = new Error("Stream error: OpenAI error");
31692
31715
  error.data = json.error;
@@ -31701,11 +31724,11 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
31701
31724
  );
31702
31725
  continue;
31703
31726
  }
31704
- const toolCall = (_d = (_c = (_b = (_a3 = json.choices) == null ? void 0 : _a3[0]) == null ? void 0 : _b.delta) == null ? void 0 : _c.tool_calls) == null ? void 0 : _d[0];
31705
- if (toolCall) {
31706
- const toolCallIndex = toolCall.index || 0;
31727
+ const dToolCall = (_d = (_c = (_b = (_a3 = json.choices) == null ? void 0 : _a3[0]) == null ? void 0 : _b.delta) == null ? void 0 : _c.tool_calls) == null ? void 0 : _d[0];
31728
+ if (dToolCall) {
31729
+ const toolCallIndex = dToolCall.index || 0;
31707
31730
  if (toolCallIndex === 0) {
31708
- const dFn = toolCall.function || {};
31731
+ const dFn = dToolCall.function || {};
31709
31732
  if (dFn.name)
31710
31733
  functionCallName += dFn.name;
31711
31734
  if (dFn.arguments)