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