Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeldking committed Oct 9, 2024
1 parent 79276cf commit c8f2d11
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
38 changes: 28 additions & 10 deletions app/src/pages/playground/__tests__/playgroundUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { _resetInstanceId } from "@phoenix/store";
import { _resetInstanceId, _resetMessageId } from "@phoenix/store";

import {
getChatRole,
Expand All @@ -20,7 +20,12 @@ const expectedPlaygroundInstance = {
template: {
__type: "chat",
messages: spanAttributesWithInputMessages.llm.input_messages.map(
({ message }) => message
({ message }, index) => {
return {
id: index,
...message,
};
}
),
},
output: spanAttributesWithInputMessages.llm.output_messages,
Expand All @@ -30,6 +35,7 @@ const expectedPlaygroundInstance = {
describe("transformSpanAttributesToPlaygroundInstance", () => {
beforeEach(() => {
_resetInstanceId();
_resetMessageId();
});
it("should throw if the attributes are not parsable", () => {
const span = {
Expand All @@ -55,11 +61,21 @@ describe("transformSpanAttributesToPlaygroundInstance", () => {
attributes: JSON.stringify(spanAttributesWithInputMessages),
};

expect(transformSpanAttributesToPlaygroundInstance(span)).toEqual(
expectedPlaygroundInstance
);
const instance = transformSpanAttributesToPlaygroundInstance(span);
expect(instance?.template.__type).toEqual("chat");
if (instance?.template.__type !== "chat") {
throw new Error("Invalid template type constructed");
}
expect(instance?.template.messages).toHaveLength(2);
instance?.template.messages.forEach((message, index) => {
expect(message.role).toEqual(
expectedPlaygroundInstance.template.messages[index].role
);
expect(message.content).toEqual(
expectedPlaygroundInstance.template.messages[index].content
);
});
});

it("should return a PlaygroundInstance if the attributes contain llm.input_messages, even if output_messages are not present", () => {
const span = {
...basePlaygroundSpan,
Expand All @@ -71,10 +87,12 @@ describe("transformSpanAttributesToPlaygroundInstance", () => {
},
}),
};
expect(transformSpanAttributesToPlaygroundInstance(span)).toEqual({
...expectedPlaygroundInstance,
output: undefined,
});
const instance = transformSpanAttributesToPlaygroundInstance(span);
expect(instance?.template.__type).toEqual("chat");
if (instance?.template.__type !== "chat") {
throw new Error("Invalid template type constructed");
}
expect(Array.isArray(instance?.template.messages)).toBeTruthy();
});
});

Expand Down
11 changes: 10 additions & 1 deletion app/src/store/playgroundStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type GenAIOperationType = "chat" | "text_completion";

let playgroundInstanceIdIndex = 0;
let playgroundRunIdIndex = 0;
let playgroundMessageIdIndex = 100;
let playgroundMessageIdIndex = 0;

/**
* Generates a new playground instance ID
Expand All @@ -26,6 +26,15 @@ export const _resetInstanceId = () => {
playgroundInstanceIdIndex = 0;
};

/**
* Resets the playground message ID to 0
*
* NB: This is only used for testing purposes
*/
export const _resetMessageId = () => {
playgroundInstanceIdIndex = 0;
};

/**
* The input mode for the playground
* @example "manual" or "dataset"
Expand Down

0 comments on commit c8f2d11

Please sign in to comment.