190proof 1.0.48 → 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 +106 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -7
- 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(
|
|
@@ -31749,6 +31754,100 @@ 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
|
+
}
|
|
31752
31851
|
function truncatePayload(payload) {
|
|
31753
31852
|
return JSON.stringify(
|
|
31754
31853
|
{
|