utilitas 1995.2.45 → 1995.2.47
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/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/alan.mjs +9 -2
- package/lib/manifest.mjs +1 -1
- package/package.json +1 -1
package/lib/alan.mjs
CHANGED
|
@@ -182,8 +182,15 @@ const init = async (options) => {
|
|
|
182
182
|
const OpenAI = await need('openai');
|
|
183
183
|
// const { getEncoding } = await need('js-tiktoken');
|
|
184
184
|
const openai = new OpenAI(options);
|
|
185
|
+
const chatGpt = options?.chatGptEndpoint || options?.chatGptApiKey
|
|
186
|
+
? new OpenAI({
|
|
187
|
+
...options,
|
|
188
|
+
baseURL: options?.chatGptEndpoint || options?.baseURL,
|
|
189
|
+
apiKey: options?.chatGptApiKey || options?.apiKey,
|
|
190
|
+
}) : openai;
|
|
185
191
|
clients[provider] = {
|
|
186
192
|
client: openai, clientBeta: openai.beta,
|
|
193
|
+
chatGptClient: chatGpt,
|
|
187
194
|
// tokeniser: getEncoding(options?.tokenModel || 'cl100k_base'),
|
|
188
195
|
// countTokens: text => tokenSafe(
|
|
189
196
|
// clients[provider].tokeniser.encode(text).length
|
|
@@ -284,10 +291,10 @@ const packGptResp = (resp, options) => {
|
|
|
284
291
|
};
|
|
285
292
|
|
|
286
293
|
const promptChatGPT = async (content, options) => {
|
|
287
|
-
const {
|
|
294
|
+
const { chatGptClient } = await getOpenAIClient(options);
|
|
288
295
|
// https://github.com/openai/openai-node?tab=readme-ov-file#streaming-responses
|
|
289
296
|
// https://github.com/openai/openai-node?tab=readme-ov-file#streaming-responses-1
|
|
290
|
-
let [resp, result, chunk] = [await
|
|
297
|
+
let [resp, result, chunk] = [await chatGptClient.chat.completions.create({
|
|
291
298
|
...messages([...options?.messages || [], buildGptMessage(content)]),
|
|
292
299
|
model: options?.model || DEFAULT_MODELS[CHATGPT],
|
|
293
300
|
stream: !!options?.stream,
|
package/lib/manifest.mjs
CHANGED