chat-agent-toolkit 1.2.105 → 1.2.107
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.
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { LanguageModel } from 'ai';
|
|
2
|
+
import { ChatTurnMessage } from './meta-search-types';
|
|
3
|
+
type TitleGeneratorInput = {
|
|
4
|
+
chat_history: ChatTurnMessage[];
|
|
5
|
+
};
|
|
6
|
+
declare const generateTitle: (input: TitleGeneratorInput, llm: LanguageModel) => Promise<string>;
|
|
7
|
+
export default generateTitle;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chat-agent-toolkit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.107",
|
|
4
4
|
"description": "Multi-provider AI agent toolkit: generate language responses, search the web, extract content, and manage memory across 10+ LLM providers.",
|
|
5
5
|
"author": "vtempest <grokthiscontact@gmail.com>",
|
|
6
6
|
"license": "rights.institute/PROSPER",
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module research/chains/titleGeneratorAgent
|
|
3
|
+
* @description Generates a short, human-friendly title summarising a chat
|
|
4
|
+
* conversation using the Vercel AI SDK. Used to give conversations with
|
|
5
|
+
* multiple turns a meaningful title instead of the truncated first message.
|
|
6
|
+
*/
|
|
7
|
+
import { generateText, type LanguageModel } from "ai";
|
|
8
|
+
import { formatChatHistoryAsString } from "../../utils";
|
|
9
|
+
import type { ChatTurnMessage } from "./meta-search-types";
|
|
10
|
+
|
|
11
|
+
const titleGeneratorPrompt = `
|
|
12
|
+
You are a title generator for an AI powered search engine. You will be given a conversation between a user and an AI. Generate a concise, descriptive title that captures the overall topic of the whole conversation.
|
|
13
|
+
|
|
14
|
+
Rules for the title:
|
|
15
|
+
- Maximum 6 words, ideally 3-5.
|
|
16
|
+
- No surrounding quotes, no trailing punctuation.
|
|
17
|
+
- Use title case.
|
|
18
|
+
- Describe the subject matter, not the fact that it is a conversation (e.g. "Quantum Computing Basics", not "A Chat About Quantum Computing").
|
|
19
|
+
|
|
20
|
+
Return only the title between the XML tags <title> and </title>. For example:
|
|
21
|
+
|
|
22
|
+
<title>SpaceX Starship Launch Timeline</title>
|
|
23
|
+
|
|
24
|
+
Conversation:
|
|
25
|
+
{chat_history}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
type TitleGeneratorInput = {
|
|
29
|
+
chat_history: ChatTurnMessage[];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Extracts the title from the model output, tolerating responses that omit
|
|
34
|
+
* the XML tags. Falls back to the trimmed raw text, stripped of surrounding
|
|
35
|
+
* quotes and truncated to a sane length.
|
|
36
|
+
*/
|
|
37
|
+
const parseTitle = (text: string): string => {
|
|
38
|
+
const match = text.match(/<title>([\s\S]*?)<\/title>/i);
|
|
39
|
+
const raw = (match ? match[1] : text).trim();
|
|
40
|
+
return raw.replace(/^["'\s]+|["'\s]+$/g, "").slice(0, 80);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const generateTitle = async (
|
|
44
|
+
input: TitleGeneratorInput,
|
|
45
|
+
llm: LanguageModel,
|
|
46
|
+
): Promise<string> => {
|
|
47
|
+
const prompt = titleGeneratorPrompt.replace(
|
|
48
|
+
"{chat_history}",
|
|
49
|
+
formatChatHistoryAsString(input.chat_history),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const { text } = await generateText({
|
|
53
|
+
model: llm,
|
|
54
|
+
temperature: 0,
|
|
55
|
+
prompt,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return parseTitle(text);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default generateTitle;
|