@saltcorn/large-language-model 0.4.9 → 0.5.1

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 +15 -3
  2. package/package.json +1 -1
package/generate.js CHANGED
@@ -23,6 +23,7 @@ const getEmbedding = async (config, opts) => {
23
23
  {
24
24
  embeddingsEndpoint: opts?.endpoint || config.embed_endpoint,
25
25
  bearer: opts?.bearer || opts?.api_key || config.api_key,
26
+ apiKey: opts?.api_key || config.api_key,
26
27
  embed_model:
27
28
  opts?.embed_model ||
28
29
  opts?.model ||
@@ -77,6 +78,7 @@ const getCompletion = async (config, opts) => {
77
78
  {
78
79
  chatCompleteEndpoint: opts?.endpoint || config.endpoint,
79
80
  bearer: opts?.bearer || opts?.api_key || config.bearer,
81
+ apiKey: opts?.api_key || config.api_key,
80
82
  model: opts?.model || config.model,
81
83
  },
82
84
  opts
@@ -117,7 +119,7 @@ const getCompletion = async (config, opts) => {
117
119
  };
118
120
 
119
121
  const getCompletionOpenAICompatible = async (
120
- { chatCompleteEndpoint, bearer, model },
122
+ { chatCompleteEndpoint, bearer, apiKey, model },
121
123
  { systemPrompt, prompt, temperature, debugResult, chat = [], ...rest }
122
124
  ) => {
123
125
  const headers = {
@@ -125,6 +127,7 @@ const getCompletionOpenAICompatible = async (
125
127
  Accept: "application/json",
126
128
  };
127
129
  if (bearer) headers.Authorization = "Bearer " + bearer;
130
+ if (apiKey) headers["api-key"] = apiKey;
128
131
  const body = {
129
132
  //prompt: "How are you?",
130
133
  model: rest.model || model,
@@ -139,7 +142,15 @@ const getCompletionOpenAICompatible = async (
139
142
  temperature: temperature || 0.7,
140
143
  ...rest,
141
144
  };
142
- if (debugResult) console.log("OpenAI request", JSON.stringify(body, null, 2));
145
+ if (debugResult)
146
+ console.log(
147
+ "OpenAI request",
148
+ JSON.stringify(body, null, 2),
149
+ "to",
150
+ chatCompleteEndpoint,
151
+ "headers",
152
+ JSON.stringify(headers)
153
+ );
143
154
  const rawResponse = await fetch(chatCompleteEndpoint, {
144
155
  method: "POST",
145
156
  headers,
@@ -162,12 +173,13 @@ const getEmbeddingOpenAICompatible = async (
162
173
  config,
163
174
  { prompt, model, debugResult }
164
175
  ) => {
165
- const { embeddingsEndpoint, bearer, embed_model } = config;
176
+ const { embeddingsEndpoint, bearer, apiKey, embed_model } = config;
166
177
  const headers = {
167
178
  "Content-Type": "application/json",
168
179
  Accept: "application/json",
169
180
  };
170
181
  if (bearer) headers.Authorization = "Bearer " + bearer;
182
+ if (apiKey) headers["api-key"] = apiKey;
171
183
  const body = {
172
184
  //prompt: "How are you?",
173
185
  model: model || embed_model || "text-embedding-3-small",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saltcorn/large-language-model",
3
- "version": "0.4.9",
3
+ "version": "0.5.1",
4
4
  "description": "Large language models and functionality for Saltcorn",
5
5
  "main": "index.js",
6
6
  "dependencies": {