@saltcorn/large-language-model 0.3.5 → 0.3.7

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.
Files changed (2) hide show
  1. package/generate.js +7 -3
  2. package/package.json +1 -1
package/generate.js CHANGED
@@ -109,7 +109,7 @@ const getCompletionOpenAICompatible = async (
109
109
  if (bearer) headers.Authorization = "Bearer " + bearer;
110
110
  const body = {
111
111
  //prompt: "How are you?",
112
- model,
112
+ model: rest.model || model,
113
113
  messages: [
114
114
  {
115
115
  role: "system",
@@ -121,6 +121,7 @@ const getCompletionOpenAICompatible = async (
121
121
  temperature: temperature || 0.7,
122
122
  ...rest,
123
123
  };
124
+ if (debugResult) console.log("OpenAI request", JSON.stringify(body, null, 2));
124
125
  const rawResponse = await fetch(chatCompleteEndpoint, {
125
126
  method: "POST",
126
127
  headers,
@@ -129,6 +130,7 @@ const getCompletionOpenAICompatible = async (
129
130
  const results = await rawResponse.json();
130
131
  if (debugResult)
131
132
  console.log("OpenAI response", JSON.stringify(results, null, 2));
133
+ if (results.error) throw new Error(`OpenAI error: ${results.error.message}`);
132
134
 
133
135
  return (
134
136
  results?.choices?.[0]?.message?.content ||
@@ -139,7 +141,7 @@ const getCompletionOpenAICompatible = async (
139
141
  };
140
142
 
141
143
  const getEmbeddingOpenAICompatible = async (config, { prompt, model }) => {
142
- const { embeddingsEndpoint, bearer, embed_model } = config;
144
+ const { embeddingsEndpoint, bearer, debugResult, embed_model } = config;
143
145
  const headers = {
144
146
  "Content-Type": "application/json",
145
147
  Accept: "application/json",
@@ -157,7 +159,9 @@ const getEmbeddingOpenAICompatible = async (config, { prompt, model }) => {
157
159
  body: JSON.stringify(body),
158
160
  });
159
161
  const results = await rawResponse.json();
160
-
162
+ if (debugResult)
163
+ console.log("OpenAI response", JSON.stringify(results, null, 2));
164
+ if (results.error) throw new Error(`OpenAI error: ${results.error.message}`);
161
165
  return results?.data?.[0]?.embedding;
162
166
  };
163
167
  module.exports = { getCompletion, getEmbedding };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {