jan/web/utils/Stack.ts
NamH 6ee5d16e5c
fix: duplicate role inside messages cause some model to refuse to answer (#3006)
* fix: duplicate role inside messages cause some model to refuse to answer

Signed-off-by: James <namnh0122@gmail.com>

* update

* Bump cortex to 0.4.12

* some model require not empty message

update

---------

Signed-off-by: James <namnh0122@gmail.com>
Co-authored-by: Van Pham <64197333+Van-QA@users.noreply.github.com>
2024-06-10 16:19:31 +07:00

32 lines
488 B
TypeScript

export class Stack<T> {
private array: T[] = []
pop(): T | undefined {
if (this.isEmpty()) throw new Error()
return this.array.pop()
}
push(data: T): void {
this.array.push(data)
}
peek(): T {
if (this.isEmpty()) throw new Error()
return this.array[this.array.length - 1]
}
isEmpty(): boolean {
return this.array.length === 0
}
size(): number {
return this.array.length
}
reverseOutput(): T[] {
return [...this.array]
}
}