@graf-research/llm-runner 0.0.20 → 0.0.21
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.
|
@@ -6,10 +6,10 @@ export declare namespace GenericLLM {
|
|
|
6
6
|
stream(onMessage: OnMessage): Promise<void>;
|
|
7
7
|
}
|
|
8
8
|
abstract class ChatSessionManager<SessionModel, ChatModel> {
|
|
9
|
-
abstract newSession():
|
|
10
|
-
abstract getChatSession(id_session: string):
|
|
11
|
-
abstract saveMessage(messages: string[], role: string, id_session: string):
|
|
12
|
-
abstract retrieveHistory(id_session: string):
|
|
9
|
+
abstract newSession(): SessionModel;
|
|
10
|
+
abstract getChatSession(id_session: string): SessionModel;
|
|
11
|
+
abstract saveMessage(messages: string[], role: string, id_session: string): void;
|
|
12
|
+
abstract retrieveHistory(id_session: string): ChatModel[];
|
|
13
13
|
}
|
|
14
14
|
abstract class GenericLLM {
|
|
15
15
|
abstract stream(messages: string[], id_session: string): Promise<StreamResponse>;
|
|
@@ -13,11 +13,11 @@ export declare namespace LLMRunner {
|
|
|
13
13
|
*/
|
|
14
14
|
class SessionManager implements GenericLLM.ChatSessionManager<ChatSession, Message> {
|
|
15
15
|
list_session: ChatSession[];
|
|
16
|
-
newSession():
|
|
17
|
-
getSession(id_session: string):
|
|
18
|
-
getChatSession(id_session: string):
|
|
19
|
-
saveMessage(messages: string[], role: string, id_session: string):
|
|
20
|
-
retrieveHistory(id_session: string):
|
|
16
|
+
newSession(): ChatSession;
|
|
17
|
+
getSession(id_session: string): ChatSession | undefined;
|
|
18
|
+
getChatSession(id_session: string): ChatSession;
|
|
19
|
+
saveMessage(messages: string[], role: string, id_session: string): void;
|
|
20
|
+
retrieveHistory(id_session: string): Message[];
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Abstract Base LLM Class
|
package/dist/base/llm-runner.js
CHANGED
|
@@ -30,43 +30,33 @@ var LLMRunner;
|
|
|
30
30
|
this.list_session = [];
|
|
31
31
|
}
|
|
32
32
|
newSession() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return session;
|
|
40
|
-
});
|
|
33
|
+
const session = {
|
|
34
|
+
id: (0, uuid_1.v4)(),
|
|
35
|
+
list_message: []
|
|
36
|
+
};
|
|
37
|
+
this.list_session.push(session);
|
|
38
|
+
return session;
|
|
41
39
|
}
|
|
42
40
|
getSession(id_session) {
|
|
43
|
-
return
|
|
44
|
-
return this.list_session.find(s => s.id == id_session);
|
|
45
|
-
});
|
|
41
|
+
return this.list_session.find(s => s.id == id_session);
|
|
46
42
|
}
|
|
47
43
|
getChatSession(id_session) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return cs;
|
|
54
|
-
});
|
|
44
|
+
const cs = this.list_session.find(s => s.id == id_session);
|
|
45
|
+
if (!cs) {
|
|
46
|
+
throw new Error('Session not found.');
|
|
47
|
+
}
|
|
48
|
+
return cs;
|
|
55
49
|
}
|
|
56
50
|
saveMessage(messages, role, id_session) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})));
|
|
63
|
-
});
|
|
51
|
+
const cs = this.getChatSession(id_session);
|
|
52
|
+
cs.list_message.push(...messages.map(content => ({
|
|
53
|
+
role,
|
|
54
|
+
content
|
|
55
|
+
})));
|
|
64
56
|
}
|
|
65
57
|
retrieveHistory(id_session) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return cs.list_message;
|
|
69
|
-
});
|
|
58
|
+
const cs = this.getChatSession(id_session);
|
|
59
|
+
return cs.list_message;
|
|
70
60
|
}
|
|
71
61
|
}
|
|
72
62
|
LLMRunner.SessionManager = SessionManager;
|