-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Expand file tree
/
Copy pathelizaClassicJsonPlugin.ts
More file actions
70 lines (65 loc) · 2.28 KB
/
elizaClassicJsonPlugin.ts
File metadata and controls
70 lines (65 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import type { GenerateTextParams, IAgentRuntime, Plugin } from "@elizaos/core";
import { ModelType } from "@elizaos/core";
const elizaKeywords = [
{ pattern: /\bmother\b/i, response: "Tell me more about your family." },
{
pattern: /\bfather\b/i,
response: "How does that make you feel about your father?",
},
{ pattern: /\bfeel\b/i, response: "Do you often feel this way?" },
{ pattern: /\bthink\b/i, response: "Why do you think that?" },
{ pattern: /\bwant\b/i, response: "What would it mean if you got that?" },
{
pattern: /\bsad\b/i,
response: "I'm sorry to hear you're feeling sad. Can you tell me more?",
},
{
pattern: /\bhappy\b/i,
response: "That's wonderful! What's making you happy?",
},
{ pattern: /\byes\b/i, response: "You seem certain. Why is that?" },
{ pattern: /\bno\b/i, response: "Why not?" },
{
pattern: /\bwhy\b/i,
response: "That's a good question. What do you think?",
},
{ pattern: /\bhow\b/i, response: "What approach would you suggest?" },
{
pattern: /\bwhat\b/i,
response: "Let me think about that. What does it mean to you?",
},
{ pattern: /\bcan\b/i, response: "What makes you ask about that?" },
{ pattern: /\byou\b/i, response: "We were talking about you, not me." },
{ pattern: /\bI am\b/i, response: "How long have you been like that?" },
{ pattern: /\bI\b/i, response: "Tell me more about yourself." },
{ pattern: /.*/, response: "Please go on." },
];
function extractUserMessage(prompt: string): string {
const match = prompt.match(/(?:User|Human|You):\s*(.+?)(?:\n|$)/i);
return match ? match[1].trim() : prompt.trim();
}
function generateElizaResponse(input: string): string {
for (const keyword of elizaKeywords) {
if (keyword.pattern.test(input)) {
return keyword.response;
}
}
return "Please go on.";
}
async function handle(
_runtime: IAgentRuntime,
params: GenerateTextParams,
): Promise<string> {
const input = extractUserMessage(params.prompt ?? "");
return generateElizaResponse(input);
}
export const elizaClassicJsonPlugin: Plugin = {
name: "eliza-classic-json",
description:
"Provides classic ELIZA responses when no hosted model is configured",
priority: 200,
models: {
[ModelType.TEXT_LARGE]: handle,
[ModelType.TEXT_SMALL]: handle,
},
};