190proof 1.0.47 → 1.0.49
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.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +132 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +132 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -12,7 +12,9 @@ declare enum GPTModel {
|
|
|
12
12
|
GPT4_0125_PREVIEW = "gpt-4-0125-preview",
|
|
13
13
|
GPT4_0409 = "gpt-4-turbo-2024-04-09",
|
|
14
14
|
GPT4O = "gpt-4o",
|
|
15
|
-
GPT4O_MINI = "gpt-4o-mini"
|
|
15
|
+
GPT4O_MINI = "gpt-4o-mini",
|
|
16
|
+
O1_PREVIEW = "o1-preview",
|
|
17
|
+
O1_MINI = "o1-mini"
|
|
16
18
|
}
|
|
17
19
|
declare enum GroqModel {
|
|
18
20
|
LLAMA_3_70B_8192 = "llama3-70b-8192"
|
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,9 @@ declare enum GPTModel {
|
|
|
12
12
|
GPT4_0125_PREVIEW = "gpt-4-0125-preview",
|
|
13
13
|
GPT4_0409 = "gpt-4-turbo-2024-04-09",
|
|
14
14
|
GPT4O = "gpt-4o",
|
|
15
|
-
GPT4O_MINI = "gpt-4o-mini"
|
|
15
|
+
GPT4O_MINI = "gpt-4o-mini",
|
|
16
|
+
O1_PREVIEW = "o1-preview",
|
|
17
|
+
O1_MINI = "o1-mini"
|
|
16
18
|
}
|
|
17
19
|
declare enum GroqModel {
|
|
18
20
|
LLAMA_3_70B_8192 = "llama3-70b-8192"
|
package/dist/index.js
CHANGED
|
@@ -27038,6 +27038,8 @@ var GPTModel = /* @__PURE__ */ ((GPTModel2) => {
|
|
|
27038
27038
|
GPTModel2["GPT4_0409"] = "gpt-4-turbo-2024-04-09";
|
|
27039
27039
|
GPTModel2["GPT4O"] = "gpt-4o";
|
|
27040
27040
|
GPTModel2["GPT4O_MINI"] = "gpt-4o-mini";
|
|
27041
|
+
GPTModel2["O1_PREVIEW"] = "o1-preview";
|
|
27042
|
+
GPTModel2["O1_MINI"] = "o1-mini";
|
|
27041
27043
|
return GPTModel2;
|
|
27042
27044
|
})(GPTModel || {});
|
|
27043
27045
|
var GroqModel = /* @__PURE__ */ ((GroqModel2) => {
|
|
@@ -31487,13 +31489,16 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
|
|
|
31487
31489
|
for (let i5 = 0; i5 <= retries; i5++) {
|
|
31488
31490
|
try {
|
|
31489
31491
|
const timerId = `timer:${identifier}:${Date.now()}:callOpenAi:${openAiConfig == null ? void 0 : openAiConfig.service}-${openAiPayload.model}-${openAiConfig == null ? void 0 : openAiConfig.orgId}`;
|
|
31490
|
-
|
|
31491
|
-
identifier,
|
|
31492
|
-
|
|
31493
|
-
|
|
31494
|
-
|
|
31495
|
-
|
|
31496
|
-
|
|
31492
|
+
if (openAiPayload.model === "o1-mini" /* O1_MINI */ || openAiPayload.model === "o1-preview" /* O1_PREVIEW */) {
|
|
31493
|
+
return await callOpenAI(identifier, openAiPayload, openAiConfig);
|
|
31494
|
+
} else {
|
|
31495
|
+
return await callOpenAIStream(
|
|
31496
|
+
identifier,
|
|
31497
|
+
openAiPayload,
|
|
31498
|
+
openAiConfig,
|
|
31499
|
+
chunkTimeoutMs
|
|
31500
|
+
);
|
|
31501
|
+
}
|
|
31497
31502
|
} catch (error) {
|
|
31498
31503
|
console.error(error);
|
|
31499
31504
|
console.error(
|
|
@@ -31515,7 +31520,7 @@ async function callOpenAiWithRetries(identifier, openAiPayload, openAiConfig, re
|
|
|
31515
31520
|
if (errorCode === "content_policy_violation") {
|
|
31516
31521
|
console.log(
|
|
31517
31522
|
identifier,
|
|
31518
|
-
`
|
|
31523
|
+
`Removing images due to content policy violation error`
|
|
31519
31524
|
);
|
|
31520
31525
|
openAiPayload.messages.forEach((message) => {
|
|
31521
31526
|
if (Array.isArray(message.content)) {
|
|
@@ -31642,9 +31647,9 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31642
31647
|
let functionCallArgs = "";
|
|
31643
31648
|
const reader = response.body.getReader();
|
|
31644
31649
|
let partialChunk = "";
|
|
31645
|
-
let abortTimeout;
|
|
31650
|
+
let abortTimeout = null;
|
|
31646
31651
|
const startAbortTimeout = () => {
|
|
31647
|
-
clearTimeout(abortTimeout);
|
|
31652
|
+
abortTimeout && clearTimeout(abortTimeout);
|
|
31648
31653
|
return setTimeout(() => {
|
|
31649
31654
|
console.log(
|
|
31650
31655
|
identifier,
|
|
@@ -31717,7 +31722,7 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31717
31722
|
);
|
|
31718
31723
|
const error = new Error("Stream error: OpenAI error");
|
|
31719
31724
|
error.data = json.error;
|
|
31720
|
-
error.requestBody = openAiPayload;
|
|
31725
|
+
error.requestBody = truncatePayload(openAiPayload);
|
|
31721
31726
|
throw error;
|
|
31722
31727
|
}
|
|
31723
31728
|
if (chunkIndex !== 0)
|
|
@@ -31749,6 +31754,122 @@ async function callOpenAIStream(identifier, openAiPayload, openAiConfig, chunkTi
|
|
|
31749
31754
|
throw new Error("Stream error: no response body");
|
|
31750
31755
|
}
|
|
31751
31756
|
}
|
|
31757
|
+
async function callOpenAI(identifier, openAiPayload, openAiConfig) {
|
|
31758
|
+
const functionNames = openAiPayload.tools ? new Set(openAiPayload.tools.map((fn) => fn.function.name)) : null;
|
|
31759
|
+
if (!openAiConfig) {
|
|
31760
|
+
openAiConfig = {
|
|
31761
|
+
service: "openai",
|
|
31762
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
31763
|
+
baseUrl: ""
|
|
31764
|
+
};
|
|
31765
|
+
}
|
|
31766
|
+
let response;
|
|
31767
|
+
if (openAiConfig.service === "azure") {
|
|
31768
|
+
console.log(identifier, "Using Azure OpenAI service", openAiPayload.model);
|
|
31769
|
+
const model = openAiPayload.model;
|
|
31770
|
+
if (!openAiConfig.modelConfigMap) {
|
|
31771
|
+
throw new Error(
|
|
31772
|
+
"OpenAI config modelConfigMap is required when using Azure OpenAI service."
|
|
31773
|
+
);
|
|
31774
|
+
}
|
|
31775
|
+
const azureConfig = openAiConfig.modelConfigMap[model];
|
|
31776
|
+
let endpoint;
|
|
31777
|
+
if (azureConfig.endpoint) {
|
|
31778
|
+
endpoint = `${azureConfig.endpoint}/openai/deployments/${azureConfig.deployment}/chat/completions?api-version=${azureConfig.apiVersion}`;
|
|
31779
|
+
} else {
|
|
31780
|
+
throw new Error("Azure OpenAI endpoint is required in modelConfigMap.");
|
|
31781
|
+
}
|
|
31782
|
+
console.log(identifier, "Using endpoint", endpoint);
|
|
31783
|
+
try {
|
|
31784
|
+
const stringifiedPayload = JSON.stringify({
|
|
31785
|
+
...openAiPayload,
|
|
31786
|
+
stream: false
|
|
31787
|
+
});
|
|
31788
|
+
const parsedPayload = JSON.parse(stringifiedPayload);
|
|
31789
|
+
} catch (error) {
|
|
31790
|
+
console.error(
|
|
31791
|
+
identifier,
|
|
31792
|
+
"OpenAI JSON parsing error:",
|
|
31793
|
+
JSON.stringify(error)
|
|
31794
|
+
);
|
|
31795
|
+
throw error;
|
|
31796
|
+
}
|
|
31797
|
+
response = await fetch(endpoint, {
|
|
31798
|
+
method: "POST",
|
|
31799
|
+
headers: {
|
|
31800
|
+
"Content-Type": "application/json",
|
|
31801
|
+
"api-key": azureConfig.apiKey
|
|
31802
|
+
},
|
|
31803
|
+
body: JSON.stringify({
|
|
31804
|
+
...openAiPayload,
|
|
31805
|
+
stream: false
|
|
31806
|
+
})
|
|
31807
|
+
});
|
|
31808
|
+
} else {
|
|
31809
|
+
console.log(identifier, "Using OpenAI service", openAiPayload.model);
|
|
31810
|
+
const endpoint = `https://api.openai.com/v1/chat/completions`;
|
|
31811
|
+
if (openAiConfig.orgId) {
|
|
31812
|
+
console.log(identifier, "Using orgId", openAiConfig.orgId);
|
|
31813
|
+
}
|
|
31814
|
+
response = await fetch(endpoint, {
|
|
31815
|
+
method: "POST",
|
|
31816
|
+
headers: {
|
|
31817
|
+
"Content-Type": "application/json",
|
|
31818
|
+
Authorization: `Bearer ${openAiConfig.apiKey}`,
|
|
31819
|
+
...openAiConfig.orgId ? { "OpenAI-Organization": openAiConfig.orgId } : {}
|
|
31820
|
+
},
|
|
31821
|
+
body: JSON.stringify({
|
|
31822
|
+
...openAiPayload,
|
|
31823
|
+
stream: false
|
|
31824
|
+
})
|
|
31825
|
+
});
|
|
31826
|
+
}
|
|
31827
|
+
if (!response.ok) {
|
|
31828
|
+
const errorData = await response.json();
|
|
31829
|
+
console.error(identifier, "OpenAI API error:", JSON.stringify(errorData));
|
|
31830
|
+
throw new Error(`OpenAI API Error: ${errorData.error.message}`);
|
|
31831
|
+
}
|
|
31832
|
+
const data = await response.json();
|
|
31833
|
+
if (!data.choices || !data.choices.length) {
|
|
31834
|
+
if (data.error) {
|
|
31835
|
+
console.error(identifier, "OpenAI error:", JSON.stringify(data.error));
|
|
31836
|
+
throw new Error("OpenAI error: " + data.error.message);
|
|
31837
|
+
}
|
|
31838
|
+
throw new Error("OpenAI error: No choices returned.");
|
|
31839
|
+
}
|
|
31840
|
+
const choice = data.choices[0];
|
|
31841
|
+
const functionCall = choice.function_call ? {
|
|
31842
|
+
name: choice.function_call.name,
|
|
31843
|
+
arguments: JSON.parse(choice.function_call.arguments)
|
|
31844
|
+
} : null;
|
|
31845
|
+
return {
|
|
31846
|
+
role: "assistant",
|
|
31847
|
+
content: choice.message.content || null,
|
|
31848
|
+
function_call: functionCall
|
|
31849
|
+
};
|
|
31850
|
+
}
|
|
31851
|
+
function truncatePayload(payload) {
|
|
31852
|
+
return JSON.stringify(
|
|
31853
|
+
{
|
|
31854
|
+
...payload,
|
|
31855
|
+
messages: payload.messages.map((message) => {
|
|
31856
|
+
if (typeof message.content === "string") {
|
|
31857
|
+
message.content = message.content.slice(0, 100);
|
|
31858
|
+
} else if (Array.isArray(message.content)) {
|
|
31859
|
+
message.content = message.content.map((block) => {
|
|
31860
|
+
if (block.type === "image_url") {
|
|
31861
|
+
block.image_url.url = block.image_url.url.slice(0, 100);
|
|
31862
|
+
}
|
|
31863
|
+
return block;
|
|
31864
|
+
});
|
|
31865
|
+
}
|
|
31866
|
+
return message;
|
|
31867
|
+
})
|
|
31868
|
+
},
|
|
31869
|
+
null,
|
|
31870
|
+
2
|
|
31871
|
+
);
|
|
31872
|
+
}
|
|
31752
31873
|
async function callAnthropicWithRetries(identifier, AiPayload, AiConfig, attempts = 5) {
|
|
31753
31874
|
var _a3, _b, _c, _d;
|
|
31754
31875
|
console.log(identifier, "Calling Anthropic API with retries");
|