190proof 1.0.47 → 1.0.48
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 +26 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31515,7 +31515,7 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
|
|
|
31515
31515
|
if (errorCode === "content_policy_violation") {
|
|
31516
31516
|
console.log(
|
|
31517
31517
|
identifier,
|
|
31518
|
-
`
|
|
31518
|
+
`Removing images due to content policy violation error`
|
|
31519
31519
|
);
|
|
31520
31520
|
openAiPayload.messages.forEach((message) => {
|
|
31521
31521
|
if (Array.isArray(message.content)) {
|
|
@@ -31642,9 +31642,9 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31642
31642
|
let functionCallArgs = "";
|
|
31643
31643
|
const reader = response.body.getReader();
|
|
31644
31644
|
let partialChunk = "";
|
|
31645
|
-
let abortTimeout;
|
|
31645
|
+
let abortTimeout = null;
|
|
31646
31646
|
const startAbortTimeout = () => {
|
|
31647
|
-
clearTimeout(abortTimeout);
|
|
31647
|
+
abortTimeout && clearTimeout(abortTimeout);
|
|
31648
31648
|
return setTimeout(() => {
|
|
31649
31649
|
console.log(
|
|
31650
31650
|
identifier,
|
|
@@ -31717,7 +31717,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31717
31717
|
);
|
|
31718
31718
|
const error = new Error("Stream error: OpenAI error");
|
|
31719
31719
|
error.data = json.error;
|
|
31720
|
-
error.requestBody = openAiPayload;
|
|
31720
|
+
error.requestBody = truncatePayload(openAiPayload);
|
|
31721
31721
|
throw error;
|
|
31722
31722
|
}
|
|
31723
31723
|
if (chunkIndex !== 0)
|
|
@@ -31749,6 +31749,28 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31749
31749
|
throw new Error("Stream error: no response body");
|
|
31750
31750
|
}
|
|
31751
31751
|
}
|
|
31752
|
+
function truncatePayload(payload) {
|
|
31753
|
+
return JSON.stringify(
|
|
31754
|
+
{
|
|
31755
|
+
...payload,
|
|
31756
|
+
messages: payload.messages.map((message) => {
|
|
31757
|
+
if (typeof message.content === "string") {
|
|
31758
|
+
message.content = message.content.slice(0, 100);
|
|
31759
|
+
} else if (Array.isArray(message.content)) {
|
|
31760
|
+
message.content = message.content.map((block) => {
|
|
31761
|
+
if (block.type === "image_url") {
|
|
31762
|
+
block.image_url.url = block.image_url.url.slice(0, 100);
|
|
31763
|
+
}
|
|
31764
|
+
return block;
|
|
31765
|
+
});
|
|
31766
|
+
}
|
|
31767
|
+
return message;
|
|
31768
|
+
})
|
|
31769
|
+
},
|
|
31770
|
+
null,
|
|
31771
|
+
2
|
|
31772
|
+
);
|
|
31773
|
+
}
|
|
31752
31774
|
async function callAnthropicWithRetries(identifier, AiPayload, AiConfig, attempts = 5) {
|
|
31753
31775
|
var _a3, _b, _c, _d;
|
|
31754
31776
|
console.log(identifier, "Calling Anthropic API with retries");
|