Skip to content

Commit d67486f

Browse files
docs Implementation session fixed.
1 parent 6e97340 commit d67486f

File tree

2 files changed

+0
-406
lines changed

2 files changed

+0
-406
lines changed

docs/configs.md

Lines changed: 0 additions & 229 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,6 @@ Sets a prompt for the selected session history.
5656

5757
---
5858

59-
#### Implementation
60-
61-
```js
62-
setPrompt(promptData, tokenAmount, id) {
63-
const selectedId = this.getId(id);
64-
if (this.history[selectedId]) {
65-
if (typeof promptData === 'string') {
66-
const hash = objHash(promptData);
67-
this.history[selectedId].prompt = promptData;
68-
this.history[selectedId].hash.prompt = hash;
69-
}
70-
71-
if (typeof tokenAmount === 'number') this.history[selectedId].tokens.prompt = tokenAmount;
72-
this.emit('setPrompt', promptData, selectedId);
73-
return;
74-
}
75-
throw new Error('Invalid history id data!');
76-
}
77-
```
78-
79-
---
80-
8159
#### Example Usage
8260

8361
```js
@@ -126,24 +104,6 @@ Retrieves the prompt of the selected session history.
126104

127105
---
128106

129-
#### Implementation
130-
131-
```js
132-
getPrompt(id) {
133-
const selectedId = this.getId(id);
134-
if (
135-
this.history[selectedId] &&
136-
typeof this.history[selectedId].prompt === 'string' &&
137-
this.history[selectedId].prompt.length > 0
138-
) {
139-
return this.history[selectedId].prompt;
140-
}
141-
return null;
142-
}
143-
```
144-
145-
---
146-
147107
#### Example Usage
148108

149109
```js
@@ -198,29 +158,6 @@ Sets the first dialogue for the selected session history.
198158

199159
---
200160

201-
#### Implementation
202-
203-
```js
204-
setFirstDialogue(dialogue, tokenAmount, id) {
205-
const selectedId = this.getId(id);
206-
if (this.history[selectedId]) {
207-
if (typeof dialogue === 'string') {
208-
const hash = objHash(dialogue);
209-
this.history[selectedId].firstDialogue = dialogue;
210-
this.history[selectedId].hash.firstDialogue = hash;
211-
}
212-
213-
if (typeof tokenAmount === 'number')
214-
this.history[selectedId].tokens.firstDialogue = tokenAmount;
215-
this.emit('setFirstDialogue', dialogue, selectedId);
216-
return;
217-
}
218-
throw new Error('Invalid history id data!');
219-
}
220-
```
221-
222-
---
223-
224161
#### Example Usage
225162

226163
```js
@@ -267,24 +204,6 @@ Retrieves the first dialogue from the selected session history.
267204

268205
---
269206

270-
#### Implementation
271-
272-
```js
273-
getFirstDialogue(id) {
274-
const selectedId = this.getId(id);
275-
if (
276-
this.history[selectedId] &&
277-
typeof this.history[selectedId].firstDialogue === 'string' &&
278-
this.history[selectedId].firstDialogue.length > 0
279-
) {
280-
return this.history[selectedId].firstDialogue;
281-
}
282-
return null;
283-
}
284-
```
285-
286-
---
287-
288207
#### Example Usage
289208

290209
```js
@@ -354,31 +273,6 @@ This would set the file data for the session with ID `'session123'`, using the M
354273

355274
#### Implementation
356275

357-
```js
358-
setFileData(mime, data, isBase64 = false, tokenAmount = undefined, id = undefined) {
359-
const selectedId = this.getId(id);
360-
if (this.history[selectedId]) {
361-
let hash;
362-
if (typeof data === 'string' && typeof mime === 'string') {
363-
this.history[selectedId].file = {
364-
mime,
365-
data,
366-
base64: !isBase64 ? Base64.encode(data) : data,
367-
};
368-
hash = objHash(this.history[selectedId].file);
369-
this.history[selectedId].hash.file = hash;
370-
}
371-
372-
if (typeof tokenAmount === 'number') this.history[selectedId].tokens.file = tokenAmount;
373-
this.emit('setFileData', this.history[selectedId].file, hash, selectedId);
374-
return;
375-
}
376-
throw new Error('Invalid history id data!');
377-
}
378-
```
379-
380-
---
381-
382276
This method allows you to store file data (either as raw text or base64-encoded) along with an optional MIME type and token count in a selected session history. It also calculates a hash for the file data and emits an event with the new file data.
383277

384278
---
@@ -426,22 +320,6 @@ This would remove the file data from the session with ID `'session123'`.
426320

427321
#### Implementation
428322

429-
```js
430-
removeFileData(id) {
431-
const selectedId = this.getId(id);
432-
if (this.history[selectedId]) {
433-
delete this.history[selectedId].file;
434-
delete this.history[selectedId].hash.file;
435-
delete this.history[selectedId].tokens.file;
436-
this.emit('setFileData', null, null, selectedId);
437-
return;
438-
}
439-
throw new Error('Invalid history id data!');
440-
}
441-
```
442-
443-
---
444-
445323
This method allows you to remove any stored file data from a specific session's history, including the file content, its hash, and associated token data. It also emits an event to indicate that the file data has been removed.
446324

447325
---
@@ -505,23 +383,6 @@ This would retrieve and display the MIME type and base64-encoded content of the
505383

506384
#### Implementation
507385

508-
```js
509-
getFileData(id) {
510-
const selectedId = this.getId(id);
511-
if (
512-
this.history[selectedId] &&
513-
this.history[selectedId].file &&
514-
typeof this.history[selectedId].file.data === 'string' &&
515-
typeof this.history[selectedId].file.mime === 'string'
516-
) {
517-
return this.history[selectedId].file;
518-
}
519-
return null;
520-
}
521-
```
522-
523-
---
524-
525386
This method provides access to the file data stored in the selected session's history, including the MIME type and the base64-encoded content of the file. If no valid file data exists, it returns `null`.
526387

527388
---
@@ -586,27 +447,6 @@ This would set the system instruction `'Ensure system stability'` for the sessio
586447

587448
#### Implementation
588449

589-
```js
590-
setSystemInstruction(data, tokenAmount, id) {
591-
const selectedId = this.getId(id);
592-
if (this.history[selectedId]) {
593-
if (typeof data === 'string') {
594-
const hash = objHash(data);
595-
this.history[selectedId].systemInstruction = data;
596-
this.history[selectedId].hash.systemInstruction = hash;
597-
}
598-
599-
if (typeof tokenAmount === 'number')
600-
this.history[selectedId].tokens.systemInstruction = tokenAmount;
601-
this.emit('setSystemInstruction', data, selectedId);
602-
return;
603-
}
604-
throw new Error('Invalid history id data!');
605-
}
606-
```
607-
608-
---
609-
610450
This method allows you to set a system instruction for a given session, optionally associating token data with it. The session is identified by its history ID, and it throws an error if the provided session ID or data is invalid.
611451

612452
---
@@ -659,21 +499,6 @@ This would attempt to retrieve the system instruction for the session with ID `'
659499

660500
#### Implementation
661501

662-
```js
663-
getSystemInstruction(id) {
664-
const selectedId = this.getId(id);
665-
if (
666-
this.history[selectedId] &&
667-
typeof this.history[selectedId].systemInstruction === 'string'
668-
) {
669-
return this.history[selectedId].systemInstruction;
670-
}
671-
return null;
672-
}
673-
```
674-
675-
---
676-
677502
This method allows you to retrieve the system instruction for a specified session. If no instruction is found or the session ID is invalid, it will return `null`.
678503

679504
---
@@ -726,17 +551,6 @@ This would attempt to retrieve the token count for the `prompt` category in the
726551

727552
#### Implementation
728553

729-
```js
730-
getTokens(where, id) {
731-
const selectedId = this.getId(id);
732-
if (this.history[selectedId] && typeof this.history[selectedId].tokens[where] === 'number')
733-
return this.history[selectedId].tokens[where];
734-
return null;
735-
}
736-
```
737-
738-
---
739-
740554
This method allows you to retrieve the token count for a specific category (such as `prompt`, `file`, or `systemInstruction`) for the selected session. If the token count is not available or the session ID is invalid, it returns `null`.
741555

742556
---
@@ -789,17 +603,6 @@ This would attempt to retrieve the hash value for the `prompt` item in the sessi
789603

790604
#### Implementation
791605

792-
```js
793-
getHash(where, id) {
794-
const selectedId = this.getId(id);
795-
if (this.history[selectedId] && typeof this.history[selectedId].hash[where] === 'string')
796-
return this.history[selectedId].hash[where];
797-
return null;
798-
}
799-
```
800-
801-
---
802-
803606
This method allows you to retrieve the hash value for a specific item (such as `prompt`, `file`, or `systemInstruction`) in the selected session. If the hash is not available or the session ID is invalid, it returns `null`.
804607

805608
---
@@ -856,24 +659,6 @@ This would start a new data session with the ID `'session123'`, select it as the
856659

857660
#### Implementation
858661

859-
```js
860-
startDataId(id, selected = false) {
861-
this.history[id] = {
862-
data: [],
863-
ids: [],
864-
tokens: { data: [] },
865-
hash: { data: [] },
866-
systemInstruction: null,
867-
model: null,
868-
};
869-
if (selected) this.selectDataId(id);
870-
this.emit('startDataId', this.history[id], id, selected ? true : false);
871-
return this.history[id];
872-
}
873-
```
874-
875-
---
876-
877662
This method is responsible for initializing a new session with a specific session ID and optional selection flag. It ensures that each session has default, empty structures ready to hold data and other session-specific information. The event `startDataId` is emitted when the session is created.
878663

879664
---
@@ -926,18 +711,4 @@ In this example, the session with ID `'session123'` will be stopped and removed
926711

927712
#### Implementation
928713

929-
```js
930-
stopDataId(id) {
931-
if (this.history[id]) {
932-
delete this.history[id];
933-
if (this.getId() === id) this.selectDataId(null);
934-
this.emit('stopDataId', id);
935-
return true;
936-
}
937-
return false;
938-
}
939-
```
940-
941-
---
942-
943714
This method is used to stop and remove a data session by its ID, ensuring that the session history is properly updated. If the stopped session is the active one, it clears the active session as well.

0 commit comments

Comments
 (0)