mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-16 16:30:15 +01:00
* 🧹 chore: Update logger imports to use @librechat/data-schemas across multiple files and remove unused sleep function from queue.js (#9930) * chore: Replace local isEnabled utility with @librechat/api import across multiple files, update test files * chore: Replace local logger import with @librechat/data-schemas logger in countTokens.js and fork.js * chore: Update logs volume path in docker-compose.yml to correct directory * chore: import order of isEnabled in static.js
42 lines
1.5 KiB
JavaScript
42 lines
1.5 KiB
JavaScript
const { z } = require('zod');
|
|
const { logger } = require('@librechat/data-schemas');
|
|
const { langPrompt, createTitlePrompt, escapeBraces, getSnippet } = require('../prompts');
|
|
const { createStructuredOutputChainFromZod } = require('langchain/chains/openai_functions');
|
|
|
|
const langSchema = z.object({
|
|
language: z.string().describe('The language of the input text (full noun, no abbreviations).'),
|
|
});
|
|
|
|
const createLanguageChain = (config) =>
|
|
createStructuredOutputChainFromZod(langSchema, {
|
|
prompt: langPrompt,
|
|
...config,
|
|
// verbose: true,
|
|
});
|
|
|
|
const titleSchema = z.object({
|
|
title: z.string().describe('The conversation title in title-case, in the given language.'),
|
|
});
|
|
const createTitleChain = ({ convo, ...config }) => {
|
|
const titlePrompt = createTitlePrompt({ convo });
|
|
return createStructuredOutputChainFromZod(titleSchema, {
|
|
prompt: titlePrompt,
|
|
...config,
|
|
// verbose: true,
|
|
});
|
|
};
|
|
|
|
const runTitleChain = async ({ llm, text, convo, signal, callbacks }) => {
|
|
let snippet = text;
|
|
try {
|
|
snippet = getSnippet(text);
|
|
} catch (e) {
|
|
logger.error('[runTitleChain] Error getting snippet of text for titleChain', e);
|
|
}
|
|
const languageChain = createLanguageChain({ llm, callbacks });
|
|
const titleChain = createTitleChain({ llm, callbacks, convo: escapeBraces(convo) });
|
|
const { language } = (await languageChain.call({ inputText: snippet, signal })).output;
|
|
return (await titleChain.call({ language, signal })).output.title;
|
|
};
|
|
|
|
module.exports = runTitleChain;
|