Skip to content

Commit

Permalink
update id generation, add todo, add test files
Browse files Browse the repository at this point in the history
  • Loading branch information
Parker-Stafford committed Oct 7, 2024
1 parent fabb2e3 commit 76f3646
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
6 changes: 5 additions & 1 deletion app/src/pages/playground/SpanPlaygroundPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ export function SpanPlaygroundPage() {

const playgroundInstance = transformSpanAttributesToPlaygroundInstance(span);

return <Playground instances={[playgroundInstance]} />;
return (
<Playground
instances={playgroundInstance != null ? [playgroundInstance] : undefined}
/>
);
}
Empty file.
Empty file.
13 changes: 6 additions & 7 deletions app/src/pages/playground/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
INITIAL_PLAYGROUND_INSTANCE_ID,
PlaygroundInstance,
} from "@phoenix/store";
import { generateInstanceId, PlaygroundInstance } from "@phoenix/store";

Check failure on line 1 in app/src/pages/playground/utils.ts

View workflow job for this annotation

GitHub Actions / CI Typescript

Run autofix to sort these imports!
import { spanPlaygroundPageLoaderQuery$data } from "./__generated__/spanPlaygroundPageLoaderQuery.graphql";
import { safelyParseJSON } from "@phoenix/utils/jsonUtils";
import { llmAttributesSchema } from "./schemas";
Expand All @@ -13,7 +10,7 @@ type PlaygroundSpan = Extract<

export function transformSpanAttributesToPlaygroundInstance(
span: PlaygroundSpan
): PlaygroundInstance {
): PlaygroundInstance | null {
const { json: parsedAttributes, parseError } = safelyParseJSON(
span.attributes
);
Expand All @@ -22,10 +19,12 @@ export function transformSpanAttributesToPlaygroundInstance(
}
const { data, success } = llmAttributesSchema.safeParse(parsedAttributes);
if (!success) {
throw new Error("Invalid data");
return null;
}
// TODO(parker): add support for tools, variables, and input / output variants
// https://github.com/Arize-ai/phoenix/issues/4886
return {
id: INITIAL_PLAYGROUND_INSTANCE_ID,
id: generateInstanceId(),
activeRunId: null,
isRunning: false,
input: {
Expand Down
16 changes: 7 additions & 9 deletions app/src/store/playgroundStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { devtools } from "zustand/middleware";

export type GenAIOperationType = "chat" | "text_completion";

export const INITIAL_PLAYGROUND_INSTANCE_ID = 0;
let playgroundInstanceIdIndex = INITIAL_PLAYGROUND_INSTANCE_ID;
let playgroundInstanceIdIndex = 0;
let playgroundRunIdIndex = 0;

export const generateInstanceId = () => playgroundInstanceIdIndex++;

/**
* The input mode for the playground
* @example "manual" or "dataset"
Expand Down Expand Up @@ -183,16 +184,13 @@ const DEFAULT_TEXT_COMPLETION_TEMPLATE: PlaygroundTextCompletionTemplate = {
export const createPlaygroundStore = (
initialProps?: Partial<PlaygroundProps>
) => {
if (initialProps?.instances != null && initialProps.instances.length > 0) {
playgroundInstanceIdIndex += initialProps.instances.length;
}
const playgroundStore: StateCreator<PlaygroundState> = (set, get) => ({
operationType: "chat",
inputMode: "manual",
setInputMode: (inputMode: PlaygroundInputMode) => set({ inputMode }),
instances: [
{
id: playgroundInstanceIdIndex++,
id: generateInstanceId(),
template: DEFAULT_CHAT_COMPLETION_TEMPLATE,
tools: {},
input: { variables: {} },
Expand All @@ -207,7 +205,7 @@ export const createPlaygroundStore = (
set({
instances: [
{
id: playgroundInstanceIdIndex++,
id: generateInstanceId(),
template: DEFAULT_CHAT_COMPLETION_TEMPLATE,
tools: {},
input: { variables: {} },
Expand All @@ -221,7 +219,7 @@ export const createPlaygroundStore = (
set({
instances: [
{
id: playgroundInstanceIdIndex++,
id: generateInstanceId(),
template: DEFAULT_TEXT_COMPLETION_TEMPLATE,
tools: {},
input: { variables: {} },
Expand All @@ -245,7 +243,7 @@ export const createPlaygroundStore = (
instance,
{
...instance,
id: playgroundInstanceIdIndex++,
id: generateInstanceId(),
activeRunId: null,
},
],
Expand Down

0 comments on commit 76f3646

Please sign in to comment.