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 +31 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -31505,6 +31505,10 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
|
|
|
31505
31505
|
openAiPayload.model = "gpt-4-turbo-2024-04-09" /* GPT4_0409 */;
|
|
31506
31506
|
openAiPayload.temperature = 0.8;
|
|
31507
31507
|
if (errorCode === "content_policy_violation") {
|
|
31508
|
+
console.log(
|
|
31509
|
+
identifier,
|
|
31510
|
+
`Switching to OpenAI service due to content policy violation error`
|
|
31511
|
+
);
|
|
31508
31512
|
openAiPayload.messages.forEach((message) => {
|
|
31509
31513
|
if (Array.isArray(message.content)) {
|
|
31510
31514
|
message.content = message.content.filter(
|
|
@@ -31522,11 +31526,19 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
|
|
|
31522
31526
|
}
|
|
31523
31527
|
if (i5 === 3) {
|
|
31524
31528
|
if ((openAiConfig == null ? void 0 : openAiConfig.service) === "azure") {
|
|
31529
|
+
console.log(
|
|
31530
|
+
identifier,
|
|
31531
|
+
`Switching to OpenAI service due to Azure service error`
|
|
31532
|
+
);
|
|
31525
31533
|
openAiConfig.service = "openai";
|
|
31526
31534
|
}
|
|
31527
31535
|
}
|
|
31528
31536
|
if (i5 === 4) {
|
|
31529
31537
|
if (openAiPayload.tools) {
|
|
31538
|
+
console.log(
|
|
31539
|
+
identifier,
|
|
31540
|
+
`Switching to no tool choice due to persistent error`
|
|
31541
|
+
);
|
|
31530
31542
|
openAiPayload.tool_choice = "none";
|
|
31531
31543
|
}
|
|
31532
31544
|
}
|
|
@@ -31568,6 +31580,19 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31568
31580
|
}
|
|
31569
31581
|
const azureConfig = openAiConfig.modelConfigMap[model];
|
|
31570
31582
|
const endpoint = `${openAiConfig.baseUrl}/azure-openai/${azureConfig.resource}/${azureConfig.deployment}/chat/completions?api-version=${azureConfig.apiVersion}`;
|
|
31583
|
+
try {
|
|
31584
|
+
const stringifiedPayload = JSON.stringify({
|
|
31585
|
+
...openAiPayload,
|
|
31586
|
+
stream: true
|
|
31587
|
+
});
|
|
31588
|
+
const parsedPayload = JSON.parse(stringifiedPayload);
|
|
31589
|
+
} catch (error) {
|
|
31590
|
+
console.error(
|
|
31591
|
+
identifier,
|
|
31592
|
+
"Stream error: Azure OpenAI JSON parsing error:",
|
|
31593
|
+
JSON.stringify(error)
|
|
31594
|
+
);
|
|
31595
|
+
}
|
|
31571
31596
|
response = await fetch(endpoint, {
|
|
31572
31597
|
method: "POST",
|
|
31573
31598
|
headers: {
|
|
@@ -31629,9 +31654,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31629
31654
|
console.log(
|
|
31630
31655
|
identifier,
|
|
31631
31656
|
`Stream error: ended after ${chunkIndex + 1} chunks via reader done flag.`,
|
|
31632
|
-
|
|
31633
|
-
functionCallName,
|
|
31634
|
-
functionCallArgs
|
|
31657
|
+
rawStreamedBody
|
|
31635
31658
|
);
|
|
31636
31659
|
throw new Error("Stream error: ended prematurely");
|
|
31637
31660
|
}
|
|
@@ -31680,7 +31703,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31680
31703
|
console.error(
|
|
31681
31704
|
identifier,
|
|
31682
31705
|
"Stream error: OpenAI error:",
|
|
31683
|
-
json.error
|
|
31706
|
+
json.error && JSON.stringify(json.error)
|
|
31684
31707
|
);
|
|
31685
31708
|
const error = new Error("Stream error: OpenAI error");
|
|
31686
31709
|
error.data = json.error;
|
|
@@ -31695,11 +31718,11 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31695
31718
|
);
|
|
31696
31719
|
continue;
|
|
31697
31720
|
}
|
|
31698
|
-
const
|
|
31699
|
-
if (
|
|
31700
|
-
const toolCallIndex =
|
|
31721
|
+
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];
|
|
31722
|
+
if (dToolCall) {
|
|
31723
|
+
const toolCallIndex = dToolCall.index || 0;
|
|
31701
31724
|
if (toolCallIndex === 0) {
|
|
31702
|
-
const dFn =
|
|
31725
|
+
const dFn = dToolCall.function || {};
|
|
31703
31726
|
if (dFn.name)
|
|
31704
31727
|
functionCallName += dFn.name;
|
|
31705
31728
|
if (dFn.arguments)
|