Skip to content

Commit

Permalink
[js] Fix: Making ResponseCreateParams optional params optional. (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
glecaros authored Dec 17, 2024
1 parent 5e9fff2 commit b7ac1f9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
10 changes: 5 additions & 5 deletions javascript/standalone/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion javascript/standalone/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rt-client",
"version": "0.5.1",
"version": "0.5.2",
"scripts": {
"test": "vitest",
"build": "rollup -c",
Expand Down
2 changes: 1 addition & 1 deletion javascript/standalone/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import nodeResolve from "@rollup/plugin-node-resolve";
import alias from "@rollup/plugin-alias";
import replace from "@rollup/plugin-replace";

import pkg from "./package.json" assert { type: "json" };
import pkg from "./package.json" with { type: "json" };

export default [
{
Expand Down
4 changes: 2 additions & 2 deletions javascript/standalone/src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ export interface ItemDeleteMessage extends ClientMessageBase {
}

export interface ResponseCreateParams {
commit: boolean;
cancel_previous: boolean;
commit?: boolean;
cancel_previous?: boolean;
append_input_items?: Item[];
input_items?: Item[];
instructions?: string;
Expand Down
33 changes: 20 additions & 13 deletions javascript/standalone/test/client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ describe.each([
});
const response = await client.generateResponse();
expect(response).toBeDefined();
expect(response.id).toBeDefined();
expect(response.id!.length).toBeGreaterThan(0);
for await (const item of response) {
expect(response!.id).toBeDefined();
expect(response!.id!.length).toBeGreaterThan(0);
for await (const item of response!) {
expect(item).toBeDefined();
expect(item.responseId).toBe(response.id);
expect(item.responseId).toBe(response!.id);
expect(item.previousItemId).toBe(sentItem.id);
}
});
Expand All @@ -254,14 +254,15 @@ describe.each([
],
});
const response = await client.generateResponse();
await response.cancel();
expect(response).toBeDefined();
await response!.cancel();

let itemCount = 0;
for await (const _item of response) {
for await (const _item of response!) {
itemCount++;
}
expect(itemCount).toBe(0);
expect(["cancelled", "completed"].includes(response.status));
expect(["cancelled", "completed"].includes(response!.status));
});

it("items should properly be emitted for text in text out", async () => {
Expand All @@ -277,8 +278,9 @@ describe.each([
],
});
const response = await client.generateResponse();
expect(response).toBeDefined();

for await (const item of response) {
for await (const item of response!) {
expect(item.type).toBe("message");
assert(item.type === "message");
for await (const part of item) {
Expand Down Expand Up @@ -309,8 +311,9 @@ describe.each([
],
});
const response = await client.generateResponse();
expect(response).toBeDefined();

for await (const item of response) {
for await (const item of response!) {
expect(item.type).toBe("message");
assert(item.type === "message");
for await (const part of item) {
Expand Down Expand Up @@ -366,8 +369,9 @@ describe.each([
],
});
const response = await client.generateResponse();
expect(response).toBeDefined();

for await (const item of response) {
for await (const item of response!) {
expect(item.type).toBe("function_call");
assert(item.type === "function_call");
expect(item.functionName).toBe("get_weather_by_location");
Expand Down Expand Up @@ -398,8 +402,9 @@ describe.each([
],
});
const response = await client.generateResponse();
expect(response).toBeDefined();

for await (const item of response) {
for await (const item of response!) {
expect(item.type).toBe("function_call");
assert(item.type === "function_call");
expect(item.functionName).toBe("get_weather_by_location");
Expand Down Expand Up @@ -430,8 +435,9 @@ describe.each([
],
});
const response = await client.generateResponse();
expect(response).toBeDefined();

for await (const item of response) {
for await (const item of response!) {
expect(item.type).toBe("function_call");
assert(item.type === "function_call");
expect(item.functionName).toBe("get_weather_by_location");
Expand Down Expand Up @@ -462,8 +468,9 @@ describe.each([
],
});
const response = await client.generateResponse();
expect(response).toBeDefined();

for await (const item of response) {
for await (const item of response!) {
expect(item.type).toBe("function_call");
assert(item.type === "function_call");
expect(item.functionName).toBe("get_weather_by_location");
Expand Down

0 comments on commit b7ac1f9

Please sign in to comment.