@saltcorn/large-language-model 0.3.4 → 0.3.6
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/generate.js +8 -4
- package/package.json +1 -1
package/generate.js
CHANGED
|
@@ -100,7 +100,7 @@ const getCompletion = async (config, opts) => {
|
|
|
100
100
|
|
|
101
101
|
const getCompletionOpenAICompatible = async (
|
|
102
102
|
{ chatCompleteEndpoint, bearer, model },
|
|
103
|
-
{ systemPrompt, prompt, temperature, chat = [], ...rest }
|
|
103
|
+
{ systemPrompt, prompt, temperature, debugResult, chat = [], ...rest }
|
|
104
104
|
) => {
|
|
105
105
|
const headers = {
|
|
106
106
|
"Content-Type": "application/json",
|
|
@@ -127,7 +127,9 @@ const getCompletionOpenAICompatible = async (
|
|
|
127
127
|
body: JSON.stringify(body),
|
|
128
128
|
});
|
|
129
129
|
const results = await rawResponse.json();
|
|
130
|
-
|
|
130
|
+
if (debugResult)
|
|
131
|
+
console.log("OpenAI response", JSON.stringify(results, null, 2));
|
|
132
|
+
if (results.error) throw new Error(`OpenAI error: ${results.error.message}`);
|
|
131
133
|
|
|
132
134
|
return (
|
|
133
135
|
results?.choices?.[0]?.message?.content ||
|
|
@@ -138,7 +140,7 @@ const getCompletionOpenAICompatible = async (
|
|
|
138
140
|
};
|
|
139
141
|
|
|
140
142
|
const getEmbeddingOpenAICompatible = async (config, { prompt, model }) => {
|
|
141
|
-
const { embeddingsEndpoint, bearer, embed_model } = config;
|
|
143
|
+
const { embeddingsEndpoint, bearer, debugResult, embed_model } = config;
|
|
142
144
|
const headers = {
|
|
143
145
|
"Content-Type": "application/json",
|
|
144
146
|
Accept: "application/json",
|
|
@@ -156,7 +158,9 @@ const getEmbeddingOpenAICompatible = async (config, { prompt, model }) => {
|
|
|
156
158
|
body: JSON.stringify(body),
|
|
157
159
|
});
|
|
158
160
|
const results = await rawResponse.json();
|
|
159
|
-
|
|
161
|
+
if (debugResult)
|
|
162
|
+
console.log("OpenAI response", JSON.stringify(results, null, 2));
|
|
163
|
+
if (results.error) throw new Error(`OpenAI error: ${results.error.message}`);
|
|
160
164
|
return results?.data?.[0]?.embedding;
|
|
161
165
|
};
|
|
162
166
|
module.exports = { getCompletion, getEmbedding };
|