* docs: add docs and schema for "OS" provider (#1536) * ignore .env * ✨ use and cache imports for autocomplete (#1456) * ✨ use and cache imports for autocomplete * fix tsc * add voyage rerank-1 * import Handlebars * feat: open pane on install (#1564) * feat: open pane on activation * comment out testing code * chore: add telemetry for pageviews (#1576) * feat: update onboarding w/ embeddings model (#1570) * chore(gui): remove unused pages * feat: add embeddings step * feat: update styles * feat: copy button updates * fix: correct pull command for embed model * fix: remove commented code * fix: remove commented code * feat: simplify copy btn props * chore: rename onboarding selection event * feat: add provider config * fix: undo msg name * remove dead code * fix: invalid mode check * fix: remove testing logic * fix: fullscreen gui retains context when hidden, fixed fullscreen focusing (#1582) * small UI tweaks * media query * feat: add best experience onboarding * small fixes * feat: add free trial card to onboarding (#1600) * feat: add free trial card to onboarding * add import * chore: add telemetry for full screen toggle (#1618) * rerank-lite-1 * remove doccs * basic tests for VS Code extension * improved testing of VS Code extension * manually implement stop tokens for hf inference api * chore: onboarding metrics (#1626) * fix: pageview tracking * feat: add onboarding telemetry * create single `onboardingStatus` type * improved var naming * remove console logs * fix windows performance issue * rename vscodeExtension.ts * migration of onboarding variables --------- Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com> Co-authored-by: Jonah Wagner <jonahwagner231@gmail.com>
160 lines
4.2 KiB
TypeScript
160 lines
4.2 KiB
TypeScript
import { stopAtStopTokens } from "../../autocomplete/charStream";
|
|
|
|
describe("stopAtStopTokens", () => {
|
|
async function* createMockStream(chunks: string[]): AsyncGenerator<string> {
|
|
for (const chunk of chunks) {
|
|
yield chunk;
|
|
}
|
|
}
|
|
|
|
it("should yield characters until a stop token is encountered", async () => {
|
|
const mockStream = createMockStream(["Hello", " world", "! Stop", "here"]);
|
|
const stopTokens = ["Stop"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("Hello world! ");
|
|
});
|
|
|
|
it("should handle multiple stop tokens", async () => {
|
|
const mockStream = createMockStream([
|
|
"This",
|
|
" is a ",
|
|
"test. END",
|
|
" of stream",
|
|
]);
|
|
const stopTokens = ["END", "STOP", "HALT"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("This is a test. ");
|
|
});
|
|
|
|
it("should handle stop tokens split across chunks", async () => {
|
|
const mockStream = createMockStream([
|
|
"Hello",
|
|
" wo",
|
|
"r",
|
|
"ld! ST",
|
|
"OP now",
|
|
]);
|
|
const stopTokens = ["STOP"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("Hello world! ");
|
|
});
|
|
|
|
it("should yield all characters if no stop token is encountered", async () => {
|
|
const mockStream = createMockStream([
|
|
"This",
|
|
" is ",
|
|
"a complete",
|
|
" stream",
|
|
]);
|
|
const stopTokens = ["END"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("This is a complete stream");
|
|
});
|
|
|
|
it("should handle empty chunks", async () => {
|
|
const mockStream = createMockStream(["Hello", "", " world", "", "! STOP"]);
|
|
const stopTokens = ["STOP"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("Hello world! ");
|
|
});
|
|
|
|
it("should handle stop token at the beginning of the stream", async () => {
|
|
const mockStream = createMockStream(["STOP", "Hello world"]);
|
|
const stopTokens = ["STOP"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("");
|
|
});
|
|
|
|
it("should handle stop token at the end of the stream", async () => {
|
|
const mockStream = createMockStream(["Hello world", "STOP"]);
|
|
const stopTokens = ["STOP"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("Hello world");
|
|
});
|
|
|
|
it("should handle multiple stop tokens of different lengths", async () => {
|
|
const mockStream = createMockStream([
|
|
"This is a ",
|
|
"test with ",
|
|
"multiple STOP",
|
|
" tokens END",
|
|
]);
|
|
const stopTokens = ["STOP", "END", "HALT"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("This is a test with multiple ");
|
|
});
|
|
|
|
it("should handle an empty stream", async () => {
|
|
const mockStream = createMockStream([]);
|
|
const stopTokens = ["STOP"];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("");
|
|
});
|
|
|
|
it("should handle an empty stop tokens array", async () => {
|
|
const mockStream = createMockStream(["Hello", " world!"]);
|
|
const stopTokens: string[] = [];
|
|
const result = stopAtStopTokens(mockStream, stopTokens);
|
|
|
|
const output = [];
|
|
for await (const char of result) {
|
|
output.push(char);
|
|
}
|
|
|
|
expect(output.join("")).toBe("Hello world!");
|
|
});
|
|
});
|