utilitas 1995.2.44 → 1995.2.46

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/lib/alan.mjs CHANGED
@@ -181,9 +181,10 @@ const init = async (options) => {
181
181
  if (options?.apiKey) {
182
182
  const OpenAI = await need('openai');
183
183
  // const { getEncoding } = await need('js-tiktoken');
184
- const openai = new OpenAI(options);
184
+ const openai = new OpenAI({ ...options, baseURL: undefined });
185
185
  clients[provider] = {
186
186
  client: openai, clientBeta: openai.beta,
187
+ chatGptClient: options?.baseURL ? new OpenAI(options) : openai,
187
188
  // tokeniser: getEncoding(options?.tokenModel || 'cl100k_base'),
188
189
  // countTokens: text => tokenSafe(
189
190
  // clients[provider].tokeniser.encode(text).length
@@ -284,10 +285,10 @@ const packGptResp = (resp, options) => {
284
285
  };
285
286
 
286
287
  const promptChatGPT = async (content, options) => {
287
- const { client } = await getOpenAIClient(options);
288
+ const { chatGptClient } = await getOpenAIClient(options);
288
289
  // https://github.com/openai/openai-node?tab=readme-ov-file#streaming-responses
289
290
  // https://github.com/openai/openai-node?tab=readme-ov-file#streaming-responses-1
290
- let [resp, result, chunk] = [await client.chat.completions.create({
291
+ let [resp, result, chunk] = [await chatGptClient.chat.completions.create({
291
292
  ...messages([...options?.messages || [], buildGptMessage(content)]),
292
293
  model: options?.model || DEFAULT_MODELS[CHATGPT],
293
294
  stream: !!options?.stream,
@@ -757,7 +758,7 @@ const talk = async (input, options) => {
757
758
  const engine = unifyEngine({ engine: CHATGPT, ...options });
758
759
  assert(chatConfig.engines[engine], NOT_INIT);
759
760
  const model = options?.model || chatConfig.engines[engine].model;
760
- const MODEL = MODELS[model];
761
+ const _MODEL = MODELS[model];
761
762
  const sessionId = options?.sessionId || newSessionId();
762
763
  const session = await getSession(sessionId, { engine, ...options });
763
764
  let [resp, sys, messages, msgBuilder] = [null, [], [], null];
@@ -791,7 +792,7 @@ const talk = async (input, options) => {
791
792
  }
792
793
  while (countTokens([
793
794
  ...sys, ...messages, buildVertexMessage(input, { role: user })
794
- ]) >= MODEL.maxInputTokens) {
795
+ ]) >= _MODEL.maxInputTokens) {
795
796
  if (messages.length) {
796
797
  session.messages.shift();
797
798
  msgBuilder && msgBuilder();
package/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1995.2.44",
4
+ "version": "1995.2.46",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1995.2.44",
4
+ "version": "1995.2.46",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",