Skip to content

Commit 19ad491

Browse files
committed
Address feedback
1 parent a3ee76f commit 19ad491

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/chat-workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class ChatWorkspace {
6767
completion: ChatCompletionRequest,
6868
): Promise<ReadableStream<Uint8Array>> {
6969
if (!completion.stream) {
70-
throw new Error("The SDK only support streaming");
70+
throw new Error("The SDK only supports streaming");
7171
}
7272
return await this.#httpRequest.postStream({
7373
path: `chats/${this.#workspace}/chat/completions`,

tests/chat-workspaces.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const WORKSPACE_SETTINGS = {
2222
apiVersion: "some-api-version",
2323
deploymentId: "some-deployment-id",
2424
baseUrl: "https://baseurl.com",
25-
apiKey: "sk-abc...",
25+
apiKey: "sk-test-placeholder-api-key",
2626
prompts: {
2727
system:
2828
"You are a helpful assistant that answers questions based on the provided context.",
@@ -83,13 +83,22 @@ test("it can create a chat completion (streaming)", async () => {
8383
const decoder = new TextDecoder();
8484
try {
8585
let receivedData = "";
86-
while (true) {
86+
let chunkCount = 0;
87+
const maxChunks = 1000; // Safety limit to prevent infinite loops
88+
89+
while (chunkCount < maxChunks) {
8790
const { done, value } = await reader.read();
8891
if (done) break;
8992

9093
const chunk = decoder.decode(value);
9194
receivedData += chunk;
95+
chunkCount++;
96+
}
97+
98+
if (chunkCount >= maxChunks) {
99+
throw new Error(`Test exceeded maximum chunk limit of ${maxChunks}`);
92100
}
101+
93102
expect(receivedData.length).toBeGreaterThan(0);
94103
} finally {
95104
reader.releaseLock();

0 commit comments

Comments
 (0)